use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class JavaLangClassLoaderHelper method getParent.
public static J9ObjectPointer getParent(J9ObjectPointer loader) throws CorruptDataException {
if (loader.isNull()) {
return J9ObjectPointer.NULL;
}
if (parentOffset == null) {
// Iterate through all the fields of Ljava/lang/ClassLoader; until you find "parent"
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
J9ClassPointer javaLangClassLoader = J9ClassLoaderHelper.findClass(vm.systemClassLoader(), "Ljava/lang/ClassLoader;");
Iterator<J9ObjectFieldOffset> fieldIterator = J9ClassHelper.getFieldOffsets(javaLangClassLoader);
while (fieldIterator.hasNext()) {
Object nextField = fieldIterator.next();
if (nextField instanceof J9ObjectFieldOffset) {
J9ObjectFieldOffset offset = (J9ObjectFieldOffset) nextField;
if ("parent".equals(offset.getName())) {
parentOffset = offset;
break;
}
}
}
}
if (parentOffset != null) {
return J9ObjectHelper.getObjectField(loader, parentOffset);
} else {
throw new CorruptDataException("Unable to find field offset for the 'parent' field");
}
}
use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class J9ObjectHelper method getFieldOffset.
private static J9ObjectFieldOffset getFieldOffset(J9ObjectPointer objPointer, String name, String signature) throws CorruptDataException {
J9ObjectFieldOffset result = J9ClassHelper.checkFieldOffsetCache(J9ObjectHelper.clazz(objPointer), name, signature);
if (result == null) {
result = readFieldOffset(objPointer, name, signature);
J9ClassHelper.setFieldOffsetCache(J9ObjectHelper.clazz(objPointer), result, name, signature);
}
return result;
}
use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class J9ObjectHelper method readFieldOffset.
// FIXME: Probably want to cache the entire class hierarchy the 1st time through for any field
private static J9ObjectFieldOffset readFieldOffset(J9ObjectPointer objPointer, String name, String signature) throws CorruptDataException {
J9ClassPointer currentClass = J9ObjectHelper.clazz(objPointer);
while (currentClass.notNull()) {
Iterator<J9ObjectFieldOffset> fields = J9ClassHelper.getFieldOffsets(currentClass);
while (fields.hasNext()) {
J9ObjectFieldOffset field = (J9ObjectFieldOffset) fields.next();
if (field.getName().equals(name) && field.getSignature().equals(signature)) {
return field;
}
}
currentClass = J9ClassHelper.superclass(currentClass);
}
throw new NoSuchElementException(String.format("No field named %s with signature %s in %s", name, signature, J9ObjectHelper.getClassName(objPointer)));
}
use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class J9ClassShapeCommand method run.
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
if (args.length != 1) {
CommandUtils.dbgPrint(out, "Usage: !j9classshape <classAddress>\n");
return;
}
try {
J9JavaVMPointer vm = J9RASHelper.getVM(DataType.getJ9RASPointer());
J9ClassPointer instanceClass = J9ClassPointer.NULL;
String classSelector = args[0];
if (classSelector.matches("\\p{Digit}.*")) {
/* addresses start with a decimal digit, possibly the '0' in "0x" */
instanceClass = J9ClassPointer.cast(CommandUtils.parsePointer(classSelector, J9BuildFlags.env_data64));
} else {
J9ClassPointer[] candidates = findClassByName(vm, classSelector);
if (candidates.length == 0) {
CommandUtils.dbgPrint(out, "No classes matching \"" + classSelector + "\" found\n");
return;
} else if (candidates.length > 1) {
CommandUtils.dbgPrint(out, "Multiple classes matching \"" + classSelector + "\" found\n");
return;
} else {
instanceClass = candidates[0];
String javaName = J9ClassHelper.getJavaName(instanceClass);
String hexString = instanceClass.getHexAddress();
CommandUtils.dbgPrint(out, String.format("!j9class %1$s\n", hexString));
}
}
J9ClassPointer previousSuperclass = J9ClassPointer.NULL;
String className = J9ClassHelper.getName(instanceClass);
J9VMThreadPointer mainThread = vm.mainThread();
boolean lockwordPrinted = true;
if (J9BuildFlags.thr_lockNursery) {
lockwordPrinted = false;
}
CommandUtils.dbgPrint(out, "Instance fields in %s:\n", className);
CommandUtils.dbgPrint(out, "\noffset name\tsignature\t(declaring class)\n");
if (mainThread.isNull()) {
/* we cannot print the instance fields without this */
return;
}
long depth = J9ClassHelper.classDepth(instanceClass).longValue();
for (long superclassIndex = 0; superclassIndex <= depth; superclassIndex++) {
J9ClassPointer superclass;
if (superclassIndex == depth) {
superclass = instanceClass;
} else {
superclass = J9ClassPointer.cast(instanceClass.superclasses().at(superclassIndex));
}
U32 flags = new U32(J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE | J9VM_FIELD_OFFSET_WALK_INCLUDE_HIDDEN);
Iterator<J9ObjectFieldOffset> iterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(superclass.romClass(), instanceClass, previousSuperclass, flags);
while (iterator.hasNext()) {
J9ObjectFieldOffset result = (J9ObjectFieldOffset) iterator.next();
boolean printField = true;
boolean isHiddenField = result.isHidden();
if (J9BuildFlags.thr_lockNursery) {
boolean isLockword = (isHiddenField && (result.getOffsetOrAddress().add(J9Object.SIZEOF).eq(superclass.lockOffset())));
if (isLockword) {
/*
* Print the lockword field if it is indeed the
* lockword for this instanceClass and we haven't
* printed it yet.
*/
printField = !lockwordPrinted && instanceClass.lockOffset().eq(superclass.lockOffset());
if (printField) {
lockwordPrinted = true;
}
}
}
if (printField) {
printShapeField(out, superclass, result.getField(), result.getOffsetOrAddress(), isHiddenField);
}
}
previousSuperclass = superclass;
}
CommandUtils.dbgPrint(out, "\nTotal instance size: %d\n", instanceClass.totalInstanceSize().longValue());
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
}
}
use of com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffset in project openj9 by eclipse.
the class CheckEngine method checkClassStatics.
private int checkClassStatics(J9ClassPointer clazz) {
int result = J9MODRON_GCCHK_RC_OK;
try {
boolean validationRequired = true;
if (J9ClassHelper.isSwappedOut(clazz)) {
/* if class has been hot swapped (J9AccClassHotSwappedOut bit is set) in Fast HCR,
* the ramStatics of the existing class may be reused. The J9ClassReusedStatics
* bit in J9Class->extendedClassFlags will be set if that's the case.
* In Extended HCR mode ramStatics might be not NULL and must be valid
* NOTE: If class is hot swapped and the value in ramStatics is NULL it is valid
* to have the correspondent ROM Class value in objectStaticCount field greater then 0
*/
if (J9ClassHelper.isArrayClass(clazz)) {
/* j9arrayclass should not be hot swapped */
result = J9MODRON_GCCHK_RC_CLASS_HOT_SWAPPED_FOR_ARRAY;
CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
_reporter.report(error);
return result;
}
if (J9ClassHelper.areExtensionsEnabled()) {
/* This is Extended HSR mode so hot swapped class might have NULL in ramStatics field */
if (clazz.ramStatics().isNull()) {
validationRequired = false;
}
}
try {
/* This case can also occur when running -Xint with extensions enabled */
if (J9ClassHelper.extendedClassFlags(clazz).allBitsIn(J9JavaClassFlags.J9ClassReusedStatics)) {
validationRequired = false;
}
} catch (NoSuchFieldError e) {
/* Flag must be missing from the core. */
}
}
if (validationRequired) {
// J9ClassLoaderPointer classLoader = clazz.classLoader();
J9ROMClassPointer romClazz = clazz.romClass();
UDATA numberOfReferences = new UDATA(0);
PointerPointer sectionStart = PointerPointer.NULL;
PointerPointer sectionEnd = PointerPointer.NULL;
/*
* Note: we have no special recognition for J9ArrayClass here
* J9ArrayClass does not have a ramStatics field but something else at this place
* so direct check (NULL != clazz->ramStatics) would not be correct,
* however romClazz->objectStaticCount must be 0 for this case
*/
if (!romClazz.objectStaticCount().eq(0)) {
sectionStart = PointerPointer.cast(clazz.ramStatics());
sectionEnd = sectionStart.add(romClazz.objectStaticCount());
}
/* Iterate all fields of ROM Class looking to statics fields pointed to java objects */
Iterator<J9ObjectFieldOffset> objectFieldOffsetIterator = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(clazz, J9ClassHelper.superclass(clazz), new U32(J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC | J9VM_FIELD_OFFSET_WALK_ONLY_OBJECT_SLOTS));
while (objectFieldOffsetIterator.hasNext()) {
J9ObjectFieldOffset fieldOffset = objectFieldOffsetIterator.next();
// J9ROMFieldShapePointer field = fieldOffset.getField();
numberOfReferences = numberOfReferences.add(1);
/* get address of next field */
PointerPointer address = sectionStart.addOffset(fieldOffset.getOffsetOrAddress());
/* an address must be in gc scan range */
if (!(address.gte(sectionStart) && address.lt(sectionEnd))) {
result = J9MODRON_GCCHK_RC_CLASS_STATICS_REFERENCE_IS_NOT_IN_SCANNING_RANGE;
CheckError error = new CheckError(clazz, address, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
_reporter.report(error);
}
/* check only if we have an object */
// TODO kmt : can't easily implement this part of the check
// J9Class* classToCast = vm->internalVMFunctions->internalFindClassUTF8(currentThread, toSearchString, toSearchLength, classLoader, J9_FINDCLASS_FLAG_EXISTING_ONLY);
// if ((NULL == classToCast) || (0 == instanceOfOrCheckCast(J9GC_J9OBJECT_CLAZZ(*address), classToCast))) {
// The issue is that we can't simply call "internalFindClassUTF8" in DDR.
// We could guess at the behaviour of the ClassLoader, but that makes
// distingushing a real problem from a weird ClassLoader delegation
// model difficult.
}
if (!numberOfReferences.eq(romClazz.objectStaticCount())) {
result = J9MODRON_GCCHK_RC_CLASS_STATICS_WRONG_NUMBER_OF_REFERENCES;
CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", result, _cycle.nextErrorCount());
_reporter.report(error);
}
}
} catch (CorruptDataException e) {
// TODO : cde should be part of the error
CheckError error = new CheckError(clazz, _cycle, _currentCheck, "Class ", J9MODRON_GCCHK_RC_CORRUPT_DATA_EXCEPTION, _cycle.nextErrorCount());
_reporter.report(error);
}
return result;
}
Aggregations