use of com.ibm.j9ddr.vm29.pointer.Pointer in project openj9 by eclipse.
the class ClassWalker method addObjectsAsSlot.
/**
* It walks through each field in this structure that is represented by methodClass and
* registers each field as a slot into ClassWalkerCallBack
*
* It uses the StructureDescriptor of J9DDR to get the FieldDescriptor of a structure.
* The name, type and address are found in the FieldDescriptor. The name, type and address
* are guaranteed to match the current core file, since they are taken from it.
*
* @param methodClass pointer class that is generated for the VM structure
* @param renameFields list of names to rename the original field names in the structure
* @throws CorruptDataException
*/
protected void addObjectsAsSlot(StructurePointer methodClass, HashMap<String, String> renameFields) throws CorruptDataException {
/* Get the structure name by removing "Pointer" suffix from the DDR generated class name*/
String structureName = methodClass.getClass().getSimpleName().substring(0, methodClass.getClass().getSimpleName().indexOf("Pointer"));
/* Get structure descriptor by using structure name */
StructureDescriptor sd = StructureCommandUtil.getStructureDescriptor(structureName, getContext());
/* Structure descriptor can not be null in normal circumstances,
* because StructurePointer "methodClass" is generated for an existing structure in the VM,
* so it should exist. If not, throw an exception.
*/
if (sd == null) {
throw new CorruptDataException("Structure \"" + structureName + "\" can not be found.");
}
for (FieldDescriptor fd : sd.getFields()) {
/* Get the name of the field from field descriptor */
String outName = fd.getName();
/* Get SlotType by using field type name */
SlotType type = getTypeByFieldTypeName(fd.getType());
/* Get the address of the field by adding the offset to the methodClass'address */
AbstractPointer address = U8Pointer.cast(methodClass).addOffset(fd.getOffset());
/* Rename fields if any defined. */
if (null != renameFields) {
if (renameFields.containsKey(outName)) {
outName = renameFields.get(outName);
}
}
/*add the field into classWalkerCallback by its name, type, address and debug extension method name */
classWalkerCallback.addSlot(clazz, type, address, outName, getDebugExtForMethodName(outName));
}
}
use of com.ibm.j9ddr.vm29.pointer.Pointer in project openj9 by eclipse.
the class RamClassWalker method allSlotsInRAMSuperClassesDo.
private void allSlotsInRAMSuperClassesDo() throws CorruptDataException {
/* The classDepth represent the number of superclasses */
final long classDepth = J9ClassHelper.classDepth(ramClass).longValue();
/*
* The superclasses is an array, ramClass.superclasses() points to the
* head and we get the next superclasses by moving the pointer.
* superclasses.add(i) adds sizeof(UDATA) to the value of the
* superclass'pointer
*/
final PointerPointer superclasses = ramClass.superclasses();
for (int i = 0; i < classDepth; i++) {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, superclasses.add(i), "SuperClass address", "!j9class");
}
classWalkerCallback.addSection(clazz, superclasses, classDepth * PointerPointer.SIZEOF, "Superclasses", false);
}
use of com.ibm.j9ddr.vm29.pointer.Pointer in project openj9 by eclipse.
the class RuntimeTypeResolutionHelper method findRuntimeType.
// Design 42819
// Discover runtime type based on identifier field.
public static String findRuntimeType(String type, Pointer ptr, Context context) {
StructureDescriptor fieldOwner = null;
FieldDescriptor typeIdField = null;
String classType = null;
// not just as the top of the hierarchy, so we have to look at each level.
try {
if (ptr.notNull()) {
// Skip the "!"
classType = StructureCommandUtil.typeToCommand(type).substring(1);
do {
fieldOwner = StructureCommandUtil.getStructureDescriptor(classType, context);
if (null != fieldOwner) {
for (FieldDescriptor aField : fieldOwner.getFields()) {
if (aField.getDeclaredName().equals("_typeId")) {
typeIdField = aField;
break;
}
}
if (null == typeIdField) {
classType = fieldOwner.getSuperName();
}
}
} while ((null == typeIdField) && (null != classType) && (null != fieldOwner) && (classType.length() > 0));
}
if (null != typeIdField) {
VoidPointer untypedStrPtr = PointerPointer.cast(ptr).addOffset(typeIdField.getOffset()).at(0);
if (untypedStrPtr.notNull()) {
U8Pointer typeStrPtr = U8Pointer.cast(untypedStrPtr);
type = typeStrPtr.getCStringAtOffset(0).toLowerCase();
}
}
} catch (CorruptDataException e) {
// Do nothing.
}
return RuntimeTypeResolutionUtils.cleanTypeStr(type);
}
use of com.ibm.j9ddr.vm29.pointer.Pointer in project openj9 by eclipse.
the class VMConstantPoolCommand method run.
/**
* Run method for !vmconstantpool extension.
*
* @param command !vmconstantpool
* @param args args passed by !vmconstantpool extension.
* @param context Context
* @param out PrintStream
* @throws DDRInteractiveCommandException
*/
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
try {
J9JavaVMPointer javaVM;
javaVM = J9RASHelper.getVM(DataType.getJ9RASPointer());
if (args.length == 1) {
long vmaddress = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
if (vmaddress != javaVM.getAddress()) {
out.println(args[0] + " is not a valid j9javavm address. Run !findvm to find out the j9javavm address of the current context");
return;
}
} else if (args.length > 1) {
printUsage(out);
}
J9ConstantPoolPointer jclConstantPool = J9ConstantPoolPointer.cast(javaVM.jclConstantPoolEA());
J9ROMClassPointer romClass = jclConstantPool.ramClass().romClass();
int index;
U32Pointer cpShapeDescription;
int constPoolCount;
cpShapeDescription = romClass.cpShapeDescription();
long cpDescription = cpShapeDescription.at(0).longValue();
constPoolCount = romClass.romConstantPoolCount().intValue();
PointerPointer cpEntry = PointerPointer.cast(J9ROMClassHelper.constantPool(romClass));
long cpDescriptionIndex = 0;
for (index = 0; index < constPoolCount; index++) {
if (0 == cpDescriptionIndex) {
// Load a new description word
cpDescription = cpShapeDescription.at(0).longValue();
cpShapeDescription = cpShapeDescription.add(1);
cpDescriptionIndex = J9_CP_DESCRIPTIONS_PER_U32;
}
long shapeDesc = cpDescription & J9_CP_DESCRIPTION_MASK;
AbstractPointer ref = PointerPointer.NULL;
if (shapeDesc == J9CPTYPE_CLASS) {
ref = J9ROMClassRefPointer.cast(cpEntry);
} else if (shapeDesc == J9CPTYPE_STRING) {
ref = J9ROMStringRefPointer.cast(cpEntry);
} else if ((shapeDesc == J9CPTYPE_INT) || (shapeDesc == J9CPTYPE_FLOAT)) {
ref = J9ROMConstantPoolItemPointer.cast(cpEntry);
} else if (shapeDesc == J9CPTYPE_LONG) {
U64Pointer longPointer = U64Pointer.cast(cpEntry);
out.println("Long at " + longPointer.getHexAddress() + " {\n\t0x0: U64:" + longPointer.getHexValue() + "\n}");
} else if (shapeDesc == J9CPTYPE_DOUBLE) {
U64Pointer longPointer = U64Pointer.cast(cpEntry);
out.println("Double at " + longPointer.getHexAddress() + " {\n\t0x0: U64:" + longPointer.at(0).longValue() + "\n}");
} else if ((shapeDesc == J9CPTYPE_INSTANCE_METHOD) || (shapeDesc == J9CPTYPE_STATIC_METHOD) || (shapeDesc == J9CPTYPE_INTERFACE_METHOD) || (shapeDesc == J9CPTYPE_HANDLE_METHOD) || (shapeDesc == J9CPTYPE_FIELD)) {
long classRefCPIndex;
if (shapeDesc == J9CPTYPE_FIELD) {
ref = J9ROMFieldRefPointer.cast(cpEntry);
/* gets the classRefCPIndex to obtain a pointer to the j9romclassref */
classRefCPIndex = J9ROMFieldRefPointer.cast(ref).classRefCPIndex().longValue();
} else {
ref = J9ROMFieldRefPointer.cast(cpEntry);
classRefCPIndex = J9ROMMethodRefPointer.cast(ref).classRefCPIndex().longValue();
}
PointerPointer classRefCPEntry = PointerPointer.cast(J9ROMClassHelper.constantPool(romClass)).addOffset(J9ROMConstantPoolItem.SIZEOF * classRefCPIndex);
/* gets the DDR output of the item */
String outString = ref.formatFullInteractive();
String[] parts = outString.split(nl);
/* add a debug extension(!j9romclassref) on the second line of the output */
parts[1] += "(!j9romclassref " + classRefCPEntry.getHexAddress() + ")";
out.print(join(nl, parts));
} else if ((shapeDesc == J9CPTYPE_UNUSED) || (shapeDesc == J9CPTYPE_UNUSED8)) {
U64Pointer longPointer = U64Pointer.cast(cpEntry);
out.println("Unused at " + longPointer.getHexAddress() + " {\n\t0x0: U64:" + longPointer.at(0).longValue() + "\n}");
} else if (ref.notNull()) {
out.println(ref.formatFullInteractive());
}
cpEntry = cpEntry.addOffset(J9ROMConstantPoolItem.SIZEOF);
cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
cpDescriptionIndex -= 1;
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.vm29.pointer.Pointer in project openj9 by eclipse.
the class SetVMCommand method run.
/**
* Runs the !setvm command.
* 1. Checks whether correct number of args passed which is 1.
* 2. If condition 1 is successful, checks whether the passed arg is a valid integer, decimal or hexadecimal.
* 3. If condition 2 is successful, checks whether the address (only arg) is a valid J9JavaVM address.
* 4. If condition 3 is unsuccessful, checks whether the address is a valid J9VMThread address.
*
* If any of the condition 3 or 4 succeeds, then cachedVM is set to new address.
* Otherwise, it prints error msg.
*
* @param command DDR extension command which is setVM for this extension.
* @param args arguments passed with the command
* @param context current context that DDR is running on.
* @param out PrintStream to print the user messages.
* @return void
*/
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (1 != args.length) {
printHelp(out);
return;
}
long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
J9JavaVMPointer vmPtr = J9JavaVMPointer.cast(address);
if (testJavaVMPtr(vmPtr)) {
J9RASHelper.setCachedVM(vmPtr);
out.println("VM set to " + vmPtr.getHexAddress());
return;
} else {
/* hmm. It's not a J9JavaVM. Maybe it's a vmThread? */
/* try to read the VM slot */
J9VMThreadPointer threadPtr = J9VMThreadPointer.cast(address);
try {
vmPtr = threadPtr.javaVM();
if (testJavaVMPtr(vmPtr)) {
J9RASHelper.setCachedVM(vmPtr);
out.println("VM set to " + vmPtr.getHexAddress());
return;
}
} catch (CorruptDataException e) {
/* Do Nothing */
}
}
out.println("Error: Specified value (=" + address + ") is not a javaVM or vmThread pointer, VM not set");
}
Aggregations