use of com.ibm.j9ddr.StructureReader.FieldDescriptor in project openj9 by eclipse.
the class BytecodeGenerator method getClassBytes.
public static byte[] getClassBytes(StructureDescriptor structure, String fullClassName) throws ClassNotFoundException {
// The className we are trying to load is FooOffsets.
// The structure name stored in the reader is Foo
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
FieldVisitor fv;
int bitFieldBitCount = 0;
// Class definition
cw.visit(V1_5, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, fullClassName, null, "java/lang/Object", null);
// Constants
// SIZEOF
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, "SIZEOF", "J", null, Long.valueOf(structure.getSizeOf()));
// Declared Constants
for (ConstantDescriptor constantDescriptor : structure.getConstants()) {
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, constantDescriptor.getName(), "J", null, Long.valueOf(constantDescriptor.getValue()));
fv.visitEnd();
}
// Offset Fields
for (FieldDescriptor field : structure.getFields()) {
String fieldName = field.getName();
String type = field.getType();
// make sure match a bit-field, not a C++ namespace
int colonIndex = type.replace("::", "__").indexOf(':');
if (colonIndex != -1) {
// Bitfield
String getter = fieldName;
int bitSize = Integer.parseInt(type.substring(colonIndex + 1).trim());
if (bitSize > (StructureReader.BIT_FIELD_CELL_SIZE - (bitFieldBitCount % StructureReader.BIT_FIELD_CELL_SIZE))) {
throw new InternalError(String.format("Bitfield %s->%s must not span cells", structure.getName(), type));
}
// s field
String name = String.format("_%s_s_", getter);
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, name, "I", null, Integer.valueOf(bitFieldBitCount));
fv.visitEnd();
// b field
name = String.format("_%s_b_", getter);
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, name, "I", null, new Integer(bitSize));
fv.visitEnd();
bitFieldBitCount += bitSize;
} else {
// Regular field
String name = String.format("_%sOffset_", fieldName);
// Offset fields
fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, name, "I", null, Integer.valueOf(field.getOffset()));
fv.visitEnd();
}
}
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
cw.visitEnd();
return cw.toByteArray();
}
use of com.ibm.j9ddr.StructureReader.FieldDescriptor in project openj9 by eclipse.
the class DDRSymbolFinder method getVoidPointerFieldsFromStructure.
private static List<String> getVoidPointerFieldsFromStructure(StructureReader reader, String structureName) throws MemoryFault {
List<String> functionPointers = new LinkedList<String>();
for (FieldDescriptor f : reader.getFields(structureName)) {
String name = f.getDeclaredName();
String type = f.getDeclaredType();
if ("void *".equals(type)) {
functionPointers.add(name);
}
}
return functionPointers;
}
use of com.ibm.j9ddr.StructureReader.FieldDescriptor in project openj9 by eclipse.
the class Declaration method writeOut.
public void writeOut(String typeName, String fieldPrefix, PrintWriter out, PrintWriter ssout) {
if (name == null || name.length() == 0) {
return;
}
// Treat bitfields differently
String typeString = getTypeString();
String declaredName = fieldPrefix + name;
// superset is in java format so replace . with $
String fieldname = (fieldPrefix + name).replace(".", "$");
FieldDescriptor field = new FieldDescriptor(0, typeString, typeString, fieldname, declaredName);
field.cleanUpTypes();
field.applyAliases(aliasmap);
if (typeString.contains(":") && !typeString.contains("::")) {
out.println("\tJ9DDRBitFieldTableEntry(\"" + fieldPrefix + name + "\"," + typeString + ")");
ssout.println(field.deflate());
} else {
if (type instanceof UserDefinedType && type.isAnonymous()) {
((UserDefinedType) type).writeFieldEntries(typeName, fieldPrefix + name + ".", out, ssout);
} else {
out.println("\tJ9DDRFieldTableEntry(" + typeName + "," + fieldPrefix + name + "," + typeString + ")");
if (!field.getDeclaredName().startsWith("_j9padding")) {
if (name.equals("utf8.data")) {
System.out.println("Def");
}
// don't include padding fields
ssout.println(field.deflate());
}
}
}
}
use of com.ibm.j9ddr.StructureReader.FieldDescriptor in project openj9 by eclipse.
the class CommandUtils method followPointerFromStructure.
public static long followPointerFromStructure(Context context, String structureName, long structureAddress, String fieldName) throws MemoryFault, DDRInteractiveCommandException {
if (structureAddress == 0) {
throw new DDRInteractiveCommandException(new NullPointerException("Null " + structureName + " found."));
}
StructureDescriptor desc = StructureCommandUtil.getStructureDescriptor(structureName, context);
for (FieldDescriptor f : desc.getFields()) {
if (f.getDeclaredName().equals(fieldName)) {
long offset = f.getOffset();
long pointerAddress = structureAddress + offset;
long pointer = context.process.getPointerAt(pointerAddress);
return pointer;
}
}
return 0;
}
use of com.ibm.j9ddr.StructureReader.FieldDescriptor in project openj9 by eclipse.
the class DDRSymbolFinder method followPointerFromStructure.
private static long followPointerFromStructure(String structureName, long structureAddress, String fieldName, StructureReader reader, IProcess process) throws MemoryFault, NullPointerException {
if (structureAddress == 0) {
throw new NullPointerException("Null " + structureName + " found.");
}
for (FieldDescriptor f : reader.getFields(structureName)) {
if (f.getDeclaredName().equals(fieldName)) {
long offset = f.getOffset();
long pointerAddress = structureAddress + offset;
long pointer = process.getPointerAt(pointerAddress);
return pointer;
}
}
return 0;
}
Aggregations