use of com.ibm.j9ddr.StructureReader.StructureDescriptor in project openj9 by eclipse.
the class BaseStructureCommand method recognises.
/* (non-Javadoc)
* @see com.ibm.j9ddr.tools.ddrinteractive.ICommand#recognises(java.lang.String)
*/
public final boolean recognises(String command, Context context) {
if (command.length() < 2) {
return false;
}
// Strip the !
command = command.substring(1);
StructureDescriptor desc = StructureCommandUtil.getStructureDescriptor(command, context);
return desc != null;
}
use of com.ibm.j9ddr.StructureReader.StructureDescriptor in project openj9 by eclipse.
the class J9DDRStructureStore method updateSuperset.
public void updateSuperset() throws IOException {
StructureReader reader = null;
if ((structureBytes.length > 2) && (structureBytes[0] == SUPERSET_ID[0]) && (structureBytes[1] == SUPERSET_ID[1])) {
// creating a reader using an input stream treats it as a superset input i.e. text
InputStream in = new ByteArrayInputStream(structureBytes);
reader = new StructureReader(in);
} else {
// using an image input stream to the reader indicates that is in binary blob format
ImageInputStream inputStream = new MemoryCacheImageInputStream(new ByteArrayInputStream(structureBytes));
reader = new StructureReader(inputStream);
}
for (StructureDescriptor structure : reader.getStructures()) {
String structureHeader = structure.deflate();
HashSet<String> structureContents = superset.get(structureHeader);
if (structureContents == null) {
structureContents = new HashSet<String>();
superset.put(structureHeader, structureContents);
}
for (FieldDescriptor field : structure.getFields()) {
addFieldToSuperset(structureContents, field);
}
for (ConstantDescriptor constant : structure.getConstants()) {
String constantHeader = constant.deflate();
structureContents.add(constantHeader);
}
}
writeSuperset();
}
use of com.ibm.j9ddr.StructureReader.StructureDescriptor 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.StructureReader.StructureDescriptor 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.StructureReader.StructureDescriptor in project openj9 by eclipse.
the class PrintBlob method main.
/**
* @param args
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Expected 1 argument. Got " + args.length);
System.exit(1);
}
File blobFile = new File(args[0]);
ImageInputStream iis = new FileImageInputStream(blobFile);
iis.setByteOrder(ByteOrder.LITTLE_ENDIAN);
StructureReader structReader = new StructureReader(iis);
List<StructureDescriptor> structures = new ArrayList<StructureDescriptor>(structReader.getStructures());
Collections.sort(structures, new Comparator<StructureDescriptor>() {
public int compare(StructureDescriptor o1, StructureDescriptor o2) {
return o1.getName().compareTo(o2.getName());
}
});
for (StructureDescriptor thisStruct : structures) {
String superClass = thisStruct.getSuperName();
if (superClass != null && superClass.length() > 0) {
System.out.println("Structure: " + thisStruct.getName() + " extends " + superClass);
} else {
System.out.println("Structure: " + thisStruct.getName());
}
// List<FieldDescriptor> fields = new ArrayList<FieldDescriptor>(thisStruct.getFields());
//
// Collections.sort(fields, new Comparator<FieldDescriptor>(){
//
// public int compare(FieldDescriptor o1, FieldDescriptor o2)
// {
// return o1.getName().compareTo(o2.getName());
// }});
//
// System.out.println("\tFields");
//
// for (FieldDescriptor thisField : fields) {
// System.out.println("\t\t" + thisField.getName() + " - " + thisField.getType());
// }
//
// List<ConstantDescriptor> constants = new ArrayList<ConstantDescriptor>(thisStruct.getConstants());
//
// Collections.sort(constants, new Comparator<ConstantDescriptor>(){
//
// public int compare(ConstantDescriptor o1, ConstantDescriptor o2)
// {
// return o1.getName().compareTo(o2.getName());
// }});
//
// System.out.println("\tConstants:");
// for (ConstantDescriptor thisConstant : constants) {
// System.out.println("\t\t" + thisConstant.getName());
// }
}
}
Aggregations