use of com.ibm.j9ddr.vm29.j9.Pool in project openj9 by eclipse.
the class VMConstantPool method getFieldOffset.
/**
* Get a field offset from the constant pool.
* @param index A J9VmconstantpoolConstants index into the constant pool. Must be for a static or instance field reference.
* @return Either the offset to the object, or null if the field's class is not resolved in the constant pool.
* @throws CorruptDataException If the field cannot be found in the related class or the CP index is not a field reference.
*/
public static J9ObjectFieldOffset getFieldOffset(long index) throws CorruptDataException {
if (_constantPool.length <= index || 0 > index) {
throw new IndexOutOfBoundsException("Index outside of constant pool bounds");
}
int cpIndex = (int) index;
long shapeDesc = ConstantPoolHelpers.J9_CP_TYPE(_cpShapeDescription, cpIndex);
if (J9CPTYPE_FIELD != shapeDesc) {
throw new CorruptDataException("VMConstantPool[" + index + "] CP_TYPE is not J9CPTYPE_FIELD");
}
/* The offset of the field, to be returned */
J9ObjectFieldOffset offset = null;
if (null != _constantPool[cpIndex]) {
offset = (J9ObjectFieldOffset) _constantPool[cpIndex];
} else {
J9ROMFieldRefPointer romRef = J9ROMFieldRefPointer.cast(_romCPStart.add(cpIndex));
J9ClassPointer refClass = getClass(romRef.classRefCPIndex().longValue());
J9ClassPointer currentClass = refClass;
if (currentClass.notNull()) {
/* If the current class is J9ClassPointer.NULL, return null as the field offset */
/* Resolve the fieldname, starting from the current class,
* and working up the class hierarchy towards the super classes. This should
* properly handle shadowed fields.
*/
String fieldName = J9UTF8Helper.stringValue(romRef.nameAndSignature().name());
String signature = J9UTF8Helper.stringValue(romRef.nameAndSignature().signature());
while (currentClass.notNull() && (null == offset)) {
Iterator<J9ObjectFieldOffset> fields = J9ClassHelper.getFieldOffsets(currentClass);
while (fields.hasNext()) {
J9ObjectFieldOffset field = fields.next();
if (field.getName().equals(fieldName) && field.getSignature().equals(signature)) {
offset = field;
break;
}
}
currentClass = J9ClassHelper.superclass(currentClass);
}
if (null == offset) {
/* The field should exist in the class it points to, unless the constant pool is corrupt or wrong */
throw new CorruptDataException("VMConstantPool[" + index + "] field not found: " + J9ClassHelper.getName(refClass) + "." + fieldName + " " + signature);
} else {
_constantPool[cpIndex] = offset;
}
}
}
return offset;
}
use of com.ibm.j9ddr.vm29.j9.Pool in project openj9 by eclipse.
the class VMConstantPool method getClass.
/**
* Get a class from the constant pool.
* @param index A J9VmconstantpoolConstants index into the constant pool. Must be for a class reference.
* @return Either the loaded class, or if its not in the constant pool, J9ClassPointer.NULL.
* @throws CorruptDataException If the CPShape of the index is not a class.
*/
public static J9ClassPointer getClass(long index) throws CorruptDataException {
if (_constantPool.length <= index || 0 > index) {
throw new IndexOutOfBoundsException("Index outside of constant pool bounds");
}
int cpIndex = (int) index;
long shapeDesc = ConstantPoolHelpers.J9_CP_TYPE(_cpShapeDescription, cpIndex);
if (J9CPTYPE_CLASS != shapeDesc) {
throw new CorruptDataException("VMConstantPool[" + index + "] CP_TYPE is not J9CPTYPE_CLASS");
}
J9ClassPointer classPointer = null;
if (null != _constantPool[cpIndex]) {
classPointer = (J9ClassPointer) _constantPool[cpIndex];
} else {
J9RAMConstantPoolItemPointer ramEntry = _ramCPStart.add(index);
classPointer = J9RAMClassRefPointer.cast(ramEntry).value();
_constantPool[cpIndex] = classPointer;
}
return classPointer;
}
use of com.ibm.j9ddr.vm29.j9.Pool in project openj9 by eclipse.
the class Pool_29_V0 method poolPuddle_startDo.
private VoidPointer poolPuddle_startDo(J9PoolPuddlePointer currentPuddle, boolean followNextPointers) throws CorruptDataException {
UDATAPointer currAddr = null;
if (pool.isNull() || currentPuddle.isNull()) {
return null;
}
if (currentPuddle.usedElements().longValue() == 0) {
if ((currentPuddle.nextPuddle().notNull()) && followNextPointers) {
return poolPuddle_startDo(currentPuddle.nextPuddle(), followNextPointers);
} else {
return null;
}
}
while (isPuddleSlotFree(currentPuddle)) {
slot++;
}
currAddr = UDATAPointer.cast(currentPuddle.firstElementAddress().getAddress() + (elementSize * slot));
state.currentPuddle = currentPuddle;
state.lastSlot = slot;
state.leftToDo = currentPuddle.usedElements().intValue() - 1;
state.flags = 0;
if (followNextPointers) {
// TODO find out where this is set
state.flags |= POOLSTATE_FOLLOW_NEXT_POINTERS;
}
if (state.leftToDo == 0) {
if (followNextPointers) {
state.currentPuddle = state.currentPuddle.nextPuddle();
state.lastSlot = -1;
} else {
state.currentPuddle = null;
}
}
logger.fine(String.format("Next pool item 0x%016x", currAddr.getAddress()));
if (logger.isLoggable(Level.FINER)) {
logger.finer(state.toString());
}
return VoidPointer.cast(currAddr);
}
use of com.ibm.j9ddr.vm29.j9.Pool in project openj9 by eclipse.
the class J9JavaVMHelper method getSystemProperties.
public static Properties getSystemProperties(J9JavaVMPointer vm) throws CorruptDataException {
Properties result = new Properties();
Pool<J9VMSystemPropertyPointer> sysprops = Pool.fromJ9Pool(vm.systemProperties(), J9VMSystemPropertyPointer.class);
Iterator<J9VMSystemPropertyPointer> syspropsIterator = sysprops.iterator();
int count = 0;
while (syspropsIterator.hasNext()) {
J9VMSystemPropertyPointer prop = syspropsIterator.next();
// Iterator may return null if corrupt data was found.
if (prop != null) {
String name = null;
try {
name = prop.name().getCStringAtOffset(0);
} catch (CorruptDataException e) {
name = "Corrupt System Property[" + count + "]";
}
String value = null;
try {
value = prop.value().getCStringAtOffset(0);
} catch (CorruptDataException e) {
value = "Corrupt Value";
}
result.setProperty(name, value);
}
count++;
}
return result;
}
use of com.ibm.j9ddr.vm29.j9.Pool in project openj9 by eclipse.
the class RamClassWalker method allSlotsInConstantPoolDo.
private void allSlotsInConstantPoolDo() throws CorruptDataException {
final J9ROMClassPointer romClass = ramClass.romClass();
final int constPoolCount = romClass.ramConstantPoolCount().intValue();
final J9ConstantPoolPointer cpp = J9ConstantPoolPointer.cast(ramClass.ramConstantPool());
U32Pointer cpDescriptionSlots = romClass.cpShapeDescription();
PointerPointer cpEntry = PointerPointer.cast(ramClass.ramConstantPool());
long cpDescription = 0;
long cpEntryCount = ramClass.romClass().ramConstantPoolCount().longValue();
long cpDescriptionIndex = 0;
while (cpEntryCount > 0) {
if (0 == cpDescriptionIndex) {
// Load a new description word
cpDescription = cpDescriptionSlots.at(0).longValue();
cpDescriptionSlots = cpDescriptionSlots.add(1);
cpDescriptionIndex = J9_CP_DESCRIPTIONS_PER_U32;
}
/*
* A switch statement can't be used on long type, it might be
* erroneous to cast it to an int as it might change in the future.
*/
long slotType = cpDescription & J9_CP_DESCRIPTION_MASK;
if ((slotType == J9CPTYPE_STRING) || (slotType == J9CPTYPE_ANNOTATION_UTF8)) {
J9RAMStringRefPointer ref = J9RAMStringRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_RAM_UTF8, ref.stringObjectEA(), "stringObject");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.unusedEA(), "unused");
if (slotType == J9CPTYPE_STRING) {
classWalkerCallback.addSection(clazz, ref, J9RAMStringRef.SIZEOF, "J9CPTYPE_STRING", false);
} else {
classWalkerCallback.addSection(clazz, ref, J9RAMStringRef.SIZEOF, "J9CPTYPE_ANNOTATION_UTF8", false);
}
} else if (slotType == J9CPTYPE_METHOD_TYPE) {
J9RAMMethodTypeRefPointer ref = J9RAMMethodTypeRefPointer.cast(cpEntry);
J9ObjectPointer slot = ref.type();
if (slot.notNull()) {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.typeEA(), "type", "!j9object");
} else {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.typeEA(), "type");
}
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.slotCountEA(), "slotCount");
classWalkerCallback.addSection(clazz, ref, J9RAMMethodTypeRef.SIZEOF, "J9CPTYPE_METHOD_TYPE", false);
} else if (slotType == J9CPTYPE_METHODHANDLE) {
J9RAMMethodHandleRefPointer ref = J9RAMMethodHandleRefPointer.cast(cpEntry);
J9ObjectPointer slot = ref.methodHandle();
if (slot.notNull()) {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodHandleEA(), "methodHandle", "!j9object");
} else {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodHandleEA(), "methodHandle");
}
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.unusedEA(), "unused");
classWalkerCallback.addSection(clazz, ref, J9RAMMethodHandleRef.SIZEOF, "J9CPTYPE_METHODHANDLE", false);
} else if (slotType == J9CPTYPE_CLASS) {
J9RAMClassRefPointer ref = J9RAMClassRefPointer.cast(cpEntry);
if (ref.value().notNull()) {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.valueEA(), "value", "!j9class");
} else {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.valueEA(), "value");
}
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.modifiersEA(), "modifiers");
classWalkerCallback.addSection(clazz, ref, J9RAMClassRef.SIZEOF, "J9CPTYPE_CLASS", false);
} else if (slotType == J9CPTYPE_INT) {
J9RAMConstantRefPointer ref = J9RAMConstantRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.slot1EA(), "cpFieldInt");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.slot2EA(), "cpFieldIntUnused");
classWalkerCallback.addSection(clazz, ref, J9RAMConstantRef.SIZEOF, "J9CPTYPE_INT", false);
} else if (slotType == J9CPTYPE_FLOAT) {
J9RAMConstantRefPointer ref = J9RAMConstantRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.slot1EA(), "cpFieldFloat");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.slot2EA(), "cpFieldIntUnused");
classWalkerCallback.addSection(clazz, ref, J9RAMConstantRef.SIZEOF, "J9CPTYPE_FLOAT", false);
} else if (slotType == J9CPTYPE_LONG) {
J9RAMConstantRefPointer ref = J9RAMConstantRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_I64, I64Pointer.cast(cpEntry), "J9CPTYPE_LONG");
classWalkerCallback.addSection(clazz, ref, J9RAMConstantRef.SIZEOF, "J9CPTYPE_LONG", false);
} else if (slotType == J9CPTYPE_DOUBLE) {
J9RAMConstantRefPointer ref = J9RAMConstantRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_I64, I64Pointer.cast(cpEntry), "J9CPTYPE_DOUBLE");
classWalkerCallback.addSection(clazz, ref, I64.SIZEOF, "J9CPTYPE_DOUBLE", false);
} else if (slotType == J9CPTYPE_FIELD) {
J9RAMFieldRefPointer ref = J9RAMFieldRefPointer.cast(cpEntry);
J9RAMStaticFieldRefPointer staticRef = J9RAMStaticFieldRefPointer.cast(cpEntry);
/* if the field ref is resolved static, it has 'flagsAndClass', for other cases (unresolved and resolved instance) it has 'flags'. */
if ((staticRef.flagsAndClass().longValue() > 0) && (staticRef.valueOffset().longValue() != -1)) {
classWalkerCallback.addSlot(clazz, SlotType.J9_IDATA, staticRef.flagsAndClassEA(), "flagsAndClass");
} else {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.flagsEA(), "flags");
}
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.valueOffsetEA(), "valueOffset");
classWalkerCallback.addSection(clazz, ref, J9RAMFieldRef.SIZEOF, "J9CPTYPE_FIELD", false);
} else if (slotType == J9CPTYPE_INTERFACE_METHOD) {
J9RAMInterfaceMethodRefPointer ref = J9RAMInterfaceMethodRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.interfaceClassEA(), "interfaceClass", "!j9class");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodIndexAndArgCountEA(), "methodIndexAndArgCount");
classWalkerCallback.addSection(clazz, ref, J9RAMInterfaceMethodRef.SIZEOF, "J9CPTYPE_INTERFACE_METHOD", false);
} else if (slotType == J9CPTYPE_STATIC_METHOD) {
J9RAMStaticMethodRefPointer ref = J9RAMStaticMethodRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodEA(), "method", "!j9method");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodIndexAndArgCountEA(), "unused");
classWalkerCallback.addSection(clazz, ref, J9RAMStaticMethodRef.SIZEOF, "J9CPTYPE_STATIC_METHOD", false);
} else if ((slotType == J9CPTYPE_UNUSED) || (slotType == J9CPTYPE_UNUSED8)) {
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, cpEntry, "unused");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, cpEntry.add(1), "unused");
classWalkerCallback.addSection(clazz, cpEntry, 2 * UDATA.SIZEOF, "J9CPTYPE_UNUSED", false);
} else if (slotType == J9CPTYPE_INSTANCE_METHOD) {
J9RAMMethodRefPointer ref = J9RAMMethodRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodIndexAndArgCountEA(), "methodIndexAndArgCount");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodEA(), "method", "!j9method");
classWalkerCallback.addSection(clazz, ref, J9RAMMethodRef.SIZEOF, "J9CPTYPE_INSTANCE_METHOD", false);
} else if (slotType == J9CPTYPE_HANDLE_METHOD) {
J9RAMMethodRefPointer ref = J9RAMMethodRefPointer.cast(cpEntry);
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodIndexAndArgCountEA(), "methodTypeIndexAndArgCount");
classWalkerCallback.addSlot(clazz, SlotType.J9_UDATA, ref.methodEA(), "unused");
classWalkerCallback.addSection(clazz, ref, J9RAMMethodRef.SIZEOF, "J9CPTYPE_HANDLE_METHOD", false);
}
cpEntry = cpEntry.addOffset(J9RAMConstantPoolItem.SIZEOF);
cpEntryCount -= 1;
cpDescription >>= J9_CP_BITS_PER_DESCRIPTION;
cpDescriptionIndex -= 1;
}
// The spaces at the end of "Constant Pool" are important since the
// regions are sorted
// by address and size, but when they are equal they are sorted by
// longest name and "Constant Pool" has to come first
classWalkerCallback.addSection(clazz, cpp, constPoolCount * 2 * UDATA.SIZEOF, "Constant Pool ", false);
}
Aggregations