Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDR: Fix printing of class static field values #4366

Merged
merged 4 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2018 IBM Corp. and others
* Copyright (c) 1991, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -62,18 +62,17 @@
/**
* Class that calculates offsets into an Object of fields.
* Based on:
* resolvefield.c 1.48
* description.c 1.25
* resolvefield.cpp
* description.c
*/

public class J9ObjectFieldOffsetIterator_V1 extends J9ObjectFieldOffsetIterator {

private J9JavaVMPointer vm;
private J9ROMClassPointer romClass;
private J9ClassPointer superClazz;
private Iterator romFieldsShapeIterator;
private J9ClassPointer instanceClass;

private U32 doubleSeen = new U32(0);
private U32 doubleStaticsSeen = new U32(0);
private UDATA firstDoubleOffset = new UDATA(0);
Expand All @@ -93,7 +92,7 @@ public class J9ObjectFieldOffsetIterator_V1 extends J9ObjectFieldOffsetIterator
private UDATA lockOffset = new UDATA(0);

private boolean isHidden;

@SuppressWarnings("unused")
private UDATA finalizeLinkOffset = new UDATA(0);
private int hiddenInstanceFieldWalkIndex = -1;
Expand All @@ -112,12 +111,12 @@ protected J9ObjectFieldOffsetIterator_V1(J9JavaVMPointer vm, J9ROMClassPointer r
this.walkFlags = flags;
// Can't call init or set romClass in the constructor because they can throw a CorruptDataException
}

private void init() throws CorruptDataException {
calculateInstanceSize(romClass, superClazz); //initInstanceSize(romClass, superClazz);
romFieldsShapeIterator = new J9ROMFieldShapeIterator(romClass.romFields(), romClass.romFieldCount());
}

private void nextField() throws CorruptDataException {
boolean walkHiddenFields = false;
isHidden = false;
Expand All @@ -133,7 +132,7 @@ private void nextField() throws CorruptDataException {
walkHiddenFields = true;
/* Start the walk over the hidden fields array in reverse order. */
hiddenInstanceFieldWalkIndex = hiddenInstanceFieldList.size();
}
}
} else {
walkHiddenFields = true;
}
Expand Down Expand Up @@ -197,7 +196,7 @@ private void fieldOffsetsFindNext() throws CorruptDataException {
if (walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE)) {
if (modifiers.anyBitsIn(J9FieldFlagObject)) {
if (walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_BACKFILL_OBJECT_FIELD)) {
// Assert_VM_true(state->backfillOffsetToUse >= 0);
// Assert_VM_true(state->backfillOffsetToUse >= 0);
offset = new UDATA(backfillOffsetToUse);
walkFlags = walkFlags.bitAnd(new U32(new UDATA(J9VM_FIELD_OFFSET_WALK_BACKFILL_OBJECT_FIELD).bitNot()));
} else {
Expand All @@ -212,7 +211,7 @@ private void fieldOffsetsFindNext() throws CorruptDataException {
doubleSeen = doubleSeen.add(1);
} else {
if (walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_BACKFILL_SINGLE_FIELD)) {
// Assert_VM_true(state->backfillOffsetToUse >= 0);
// Assert_VM_true(state->backfillOffsetToUse >= 0);
offset = new UDATA(backfillOffsetToUse);
walkFlags = walkFlags.bitAnd(new U32(new UDATA(J9VM_FIELD_OFFSET_WALK_BACKFILL_SINGLE_FIELD).bitNot()));
} else {
Expand Down Expand Up @@ -249,7 +248,7 @@ private void calculateInstanceSize(J9ROMClassPointer romClass, J9ClassPointer su
if (!walkFlags.anyBitsIn(J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE | J9VM_FIELD_OFFSET_WALK_CALCULATE_INSTANCE_SIZE)) {
return;
}
ObjectFieldInfo fieldInfo = new ObjectFieldInfo(romClass);
ObjectFieldInfo fieldInfo = new ObjectFieldInfo(romClass);

/*
* Step 1: Calculate the size of the superclass and backfill offset.
Expand Down Expand Up @@ -280,7 +279,7 @@ private void calculateInstanceSize(J9ROMClassPointer romClass, J9ClassPointer su
* superClazz is java.lang.Object: subtract off non-inherited monitor field.
* Note that java.lang.Object's backfill slot can be only at the end.
*/
/* this may have been rounded to 8 bytes so also get rid of the padding */
/* this may have been rounded to 8 bytes so also get rid of the padding */
if (fieldInfo.isSuperclassBackfillSlotAvailable()) { /* j.l.Object was not end aligned */
newSuperSize -= BACKFILL_SIZE;
fieldInfo.setSuperclassBackfillOffset(NO_BACKFILL_AVAILABLE);
Expand All @@ -301,9 +300,9 @@ private void calculateInstanceSize(J9ROMClassPointer romClass, J9ClassPointer su
} else {
/*
* Superclass is not finalizable.
* We add the field if the class marked as needing finalization. In addition when HCR is enabled we also add the field if the
* We add the field if the class marked as needing finalization. In addition when HCR is enabled we also add the field if the
* the class is not the class for java.lang.Object (superclass name in java.lang.object isnull) and the class has a finalize
* method regardless of whether this method is empty or not. We need to do this because when HCR is enabled it is possible
* method regardless of whether this method is empty or not. We need to do this because when HCR is enabled it is possible
* that the method will be re-transformed such that there finalization is needed and in that case
* we need the field to be in the shape of the existing objects
*/
Expand Down Expand Up @@ -342,14 +341,14 @@ private void calculateInstanceSize(J9ROMClassPointer romClass, J9ClassPointer su
}

/*
* Calculate offsets (from the object header) for hidden fields. Hidden fields follow immediately the instance fields of the same type.
* Calculate offsets (from the object header) for hidden fields. Hidden fields follow immediately the instance fields of the same type.
* Give instance fields priority for backfill slots.
* Note that the hidden fields remember their offsets, so this need be done once only.
*/
if (!hiddenInstanceFieldList.isEmpty()) {
UDATA hiddenSingleOffset = firstSingleOffset.add(J9Object.SIZEOF + (fieldInfo.getNonBackfilledInstanceSingleCount() * U32.SIZEOF));
UDATA hiddenDoubleOffset = firstDoubleOffset.add(J9Object.SIZEOF + (fieldInfo.getInstanceDoubleCount() * U64.SIZEOF));
UDATA hiddenObjectOffset = firstObjectOffset.add(J9Object.SIZEOF + (fieldInfo.getNonBackfilledInstanceObjectCount() * fj9object_t_SizeOf));
UDATA hiddenObjectOffset = firstObjectOffset.add(J9Object.SIZEOF + (fieldInfo.getNonBackfilledInstanceObjectCount() * fj9object_t_SizeOf));
boolean useBackfillForObject = false;
boolean useBackfillForSingle = false;

Expand Down Expand Up @@ -391,7 +390,7 @@ private void calculateInstanceSize(J9ROMClassPointer romClass, J9ClassPointer su
}
backfillOffsetToUse = new IDATA(fieldInfo.getMyBackfillOffset()); /* backfill offset for this class's fields */
}

static PrintStream err = System.err;

/**
Expand All @@ -401,45 +400,43 @@ private void calculateInstanceSize(J9ROMClassPointer romClass, J9ClassPointer su
* @param romClass
* @param ramSuperClass
* @param instanceClass
* @return NO_LOCKWORD_NEEDED if no lockword, lockword offset if it inherits a lockword,
* @return NO_LOCKWORD_NEEDED if no lockword, lockword offset if it inherits a lockword,
* LOCKWORD_NEEDED if lockword needed and superclass does not have a lockword
* @throws CorruptDataException
*/
private UDATA checkLockwordNeeded(J9ROMClassPointer romClass, J9ClassPointer ramSuperClass,J9ClassPointer instanceClass) throws CorruptDataException {
if (!J9BuildFlags.thr_lockNursery) {
return NO_LOCKWORD_NEEDED;
}

J9ClassPointer ramClassForRomClass = instanceClass;
while (!ramClassForRomClass.isNull() &&(!romClass.equals(ramClassForRomClass.romClass()))) {
while (!ramClassForRomClass.isNull() && (!romClass.equals(ramClassForRomClass.romClass()))) {
ramClassForRomClass = J9ClassHelper.superclass(ramClassForRomClass);
}
// if the class does not have a lock offset then one was not needed
if (ramClassForRomClass.lockOffset().eq(NO_LOCKWORD_NEEDED)){
// if the class does not have a lock offset then one was not needed
if (ramClassForRomClass.lockOffset().eq(NO_LOCKWORD_NEEDED)) {
return NO_LOCKWORD_NEEDED;
}


// if class inherited its lockword from its parent then we return the offset
if ((ramSuperClass != null)&&(! ramSuperClass.isNull())&&(ramClassForRomClass.lockOffset().eq(ramSuperClass.lockOffset()))){
// if class inherited its lockword from its parent then we return the offset
if ((ramSuperClass != null) && (!ramSuperClass.isNull()) && ramClassForRomClass.lockOffset().eq(ramSuperClass.lockOffset())) {
return ramSuperClass.lockOffset();
}
}

// class has lockword and did not get it from its parent so a lockword was needed
return LOCKWORD_NEEDED;
}

public boolean hasNext() {

if (next != null) {
return true;
}

next = getNext();

return next != null;
//

//
// if (romFieldsShapeIterator.hasNext()) {
// return true;
// }
Expand All @@ -449,18 +446,18 @@ public boolean hasNext() {
// return false;
}

private J9ObjectFieldOffset getNext()
private J9ObjectFieldOffset getNext()
{
if (romFieldsShapeIterator == null) {
try {
init();
} catch (CorruptDataException e) {
// Tell anyone listening there was corrupt data.
raiseCorruptDataEvent("CorruptDataException in com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffsetIterator_V1.init()", e, false);
raiseCorruptDataEvent("CorruptDataException in com.ibm.j9ddr.vm29.j9.J9ObjectFieldOffsetIterator_V1.init()", e, false);
return null;
}
}

try {
nextField();
if (field == null) {
Expand All @@ -481,9 +478,9 @@ private J9ObjectFieldOffset getNext()

public J9ObjectFieldOffset next() {
if (!hasNext()) {
throw new NoSuchElementException();
throw new NoSuchElementException();
}

J9ObjectFieldOffset toReturn = next;
next = null;
return toReturn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2018 IBM Corp. and others
* Copyright (c) 2001, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand All @@ -25,6 +25,7 @@

import com.ibm.j9ddr.CorruptDataException;
import com.ibm.j9ddr.vm29.j9.ObjectModel;
import com.ibm.j9ddr.vm29.pointer.I16Pointer;
import com.ibm.j9ddr.vm29.pointer.I32Pointer;
import com.ibm.j9ddr.vm29.pointer.I64Pointer;
import com.ibm.j9ddr.vm29.pointer.ObjectReferencePointer;
Expand Down Expand Up @@ -212,7 +213,7 @@ public static void getByteData(J9IndexableObjectPointer objPointer, final byte[]
throw new ArrayIndexOutOfBoundsException("Supplied destination array too small. Requires: " + destStart + length + ", was " + dst.length);
}
for (int i = 0; i < length; i++) {
dst[destStart + i] = (byte)U8Pointer.cast(ObjectModel.getElementAddress(objPointer, start + i, 1)).at(0).intValue();
dst[destStart + i] = U8Pointer.cast(ObjectModel.getElementAddress(objPointer, start + i, 1)).at(0).byteValue();
}
}

Expand Down Expand Up @@ -274,7 +275,7 @@ public static void getShortData(J9IndexableObjectPointer objPointer, final short
throw new ArrayIndexOutOfBoundsException("Supplied destination array too small. Requires: " + destStart + length + ", was " + dst.length);
}
for (int i = 0; i < length; i++) {
dst[destStart + i] = (short)U16Pointer.cast(ObjectModel.getElementAddress(objPointer, start + i, 2)).at(0).intValue();
dst[destStart + i] = I16Pointer.cast(ObjectModel.getElementAddress(objPointer, start + i, 2)).at(0).shortValue();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1991, 2018 IBM Corp. and others
* Copyright (c) 1991, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -35,7 +35,7 @@ public static U32 CCITEMLEN(ShcItemHdrPointer ptr) throws CorruptDataException {

// #define CCITEM(ih) (((U_8*)(ih)) - (CCITEMLEN(ih) - sizeof(ShcItemHdr)))
public static U8Pointer CCITEM(ShcItemHdrPointer ptr) throws CorruptDataException {
return U8Pointer.cast(ptr).sub(CCITEMLEN(ptr).sub((int)ShcItemHdr.SIZEOF));
return U8Pointer.cast(ptr).sub(CCITEMLEN(ptr).sub(ShcItemHdr.SIZEOF));
}

// #define CCITEMNEXT(ih) ((ShcItemHdr*)(CCITEM(ih) - sizeof(ShcItemHdr)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2018 IBM Corp. and others
* Copyright (c) 2001, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -51,28 +51,25 @@
import com.ibm.j9ddr.vm29.structure.J9ROMFieldOffsetWalkState;
import com.ibm.j9ddr.vm29.types.U32;

public class J9StaticsCommand extends Command
{
public J9StaticsCommand()
{
public class J9StaticsCommand extends Command {

public J9StaticsCommand() {
addCommand("j9statics", "<ramclass>", "Display static fields of a ram class");
}

long staticFieldAddress(J9VMThreadPointer vmStruct, J9ROMClassPointer romClass, String fieldName, String signature, long options)
{
long staticFieldAddress(J9VMThreadPointer vmStruct, J9ROMClassPointer romClass, String fieldName, String signature, long options) {
return 0;
}

public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException
{
public void run(String command, String[] args, Context context, PrintStream out) throws DDRInteractiveCommandException {
try {
if (args.length != 1) {
CommandUtils.dbgPrint(out, "Usage: !j9statics <classAddress>\n");
return;
}

long address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);

J9ClassPointer ramClass = J9ClassPointer.cast(address);
J9ROMClassPointer romClass = ramClass.romClass();
J9UTF8Pointer className = romClass.className();
Expand All @@ -91,40 +88,44 @@ public void run(String command, String[] args, Context context, PrintStream out)
switch (sig.charAt(0)) {
case 'L':
case '[':
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticstringfieldshape %s) = !j9object %s\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticfieldshape %s) = !j9object %s\n",
fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
break;
case 'D':
DoublePointer doublePointer = DoublePointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticdoublefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), doublePointer.getHexValue(), new Double(doublePointer.doubleAt(0)).toString());
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticfieldshape %s) = %s (%s)\n",
fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), doublePointer.getHexValue(), Double.toString(doublePointer.doubleAt(0)));
break;
case 'F':
FloatPointer floatPointer = FloatPointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), floatPointer.getHexValue(), new Float(floatPointer.floatAt(0)).toString());
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticfieldshape %s) = %s (%s)\n",
fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), floatPointer.getHexValue(), Float.toString(floatPointer.floatAt(0)));
break;
case 'J':
I64Pointer longPointer = I64Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticdoublefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), longPointer.getHexValue(), longPointer.at(0).longValue());
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticfieldshape %s) = %s (%d)\n",
fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), longPointer.getHexValue(), longPointer.at(0).longValue());
break;
case 'B': // byte
case 'C': // char
case 'S': // short
case 'Z': // boolean
/*
* All fields are allocated a minimum of 32-bits. Thus, we must read 32-bits
* even for smaller primitive types to handle byte ordering properly.
* See J9ObjectStructureFormatter, which does likewise for instance fields.
*/
// fall through
case 'I':
I32Pointer intPointer = I32Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), intPointer.getHexValue(), intPointer.at(0).intValue());
break;
case 'B':
I8Pointer bytePointer = I8Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), bytePointer.getHexValue(), bytePointer.at(0).byteValue());
break;
case 'S':
I16Pointer shortPointer = I16Pointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%d)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), shortPointer.getHexValue(), shortPointer.at(0).shortValue());
break;
case 'Z':
BoolPointer booleanPointer = BoolPointer.cast(fieldAddress);
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s (%s)\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), booleanPointer.getHexValue(), booleanPointer.boolAt(0)? "true" : "false");
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticfieldshape %s) = %s (%d)\n",
fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), intPointer.getHexValue(), intPointer.at(0).intValue());
break;
default:
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticsinglefieldshape %s) = %s\n", fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
CommandUtils.dbgPrint(out, "\t%s %s %s (!j9romstaticfieldshape %s) = %s\n",
fieldAddress.getHexAddress(), name, sig, field.getHexAddress(), fieldAddress.at(0).getHexValue());
break;
}
}
}
} catch (CorruptDataException e) {
throw new DDRInteractiveCommandException(e);
Expand Down
Loading