use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer in project openj9 by eclipse.
the class DTFJJavaObject method arraycopy.
public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
fetchDeferredData();
if (!objectIsArray) {
throw new IllegalArgumentException("Object is not an array");
}
J9IndexableObjectPointer array = J9IndexableObjectPointer.cast(object);
try {
validateArrayCopyParameters(array, srcStart, dst, dstStart, length);
// CMVC 171150 : use helper object to correctly get the class name
String className = J9IndexableObjectHelper.getClassName(array);
if ((null == className) || (className.length() < 2)) {
J9DDRCorruptData cd = new J9DDRCorruptData(DTFJContext.getProcess(), "The class name for this object could not be determined", object.getAddress());
throw new CorruptDataException(cd);
}
if (className.charAt(1) == 'L' || className.charAt(1) == '[') {
// JExtract/DTFJ can cope with dst of either Object[] or JavaObject[] - but we need to detect other things
if (!dst.getClass().equals(Object[].class) && !(dst instanceof JavaObject[])) {
throw new IllegalArgumentException("Type of dst object (" + dst.getClass().getName() + ") incompatible with Object array. Should be JavaObject[] or Object[]");
}
J9ObjectPointer[] intermediateArray = new J9ObjectPointer[length];
Object[] castedDst = (Object[]) dst;
if (dstStart + (long) length > castedDst.length) {
throw new ArrayIndexOutOfBoundsException("Supplied destination array too small. Requires: " + (dstStart + (long) length) + ", was " + castedDst.length);
}
J9IndexableObjectHelper.getData(array, intermediateArray, srcStart, length, 0);
for (int i = 0; i < length; i++) {
if (intermediateArray[i].isNull()) {
castedDst[dstStart + i] = null;
} else {
castedDst[dstStart + i] = new DTFJJavaObject(intermediateArray[i]);
}
}
} else {
// For primitives we can pass through the client object. The type verification will be done in J9IndexableObjectPointer
J9IndexableObjectHelper.getData(array, dst, srcStart, length, dstStart);
}
} catch (Throwable t) {
throw J9DDRDTFJUtils.handleAllButMemAccExAsCorruptDataException(DTFJContext.getProcess(), t, whitelist);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer in project openj9 by eclipse.
the class DTFJJavaFieldInstance method get.
public Object get(JavaObject object) throws CorruptDataException, MemoryAccessException {
if (null == object) {
throw new NullPointerException("JavaObject is null");
}
try {
switch(getSigFlag()) {
case BOOLEAN_SIGNATURE:
return Boolean.valueOf(getBoolean(object));
case BYTE_SIGNATURE:
return Byte.valueOf(getByte(object));
case CHAR_SIGNATURE:
return Character.valueOf(getChar(object));
case SHORT_SIGNATURE:
return Short.valueOf(getShort(object));
case INTEGER_SIGNATURE:
return Integer.valueOf(getInt(object));
case FLOAT_SIGNATURE:
return new Float(getFloat(object));
case LONG_SIGNATURE:
return Long.valueOf(getLong(object));
case DOUBLE_SIGNATURE:
return new Double(getDouble(object));
case ARRAY_PREFIX_SIGNATURE:
case OBJECT_PREFIX_SIGNATURE:
J9ROMFieldShapePointer fieldShape = fieldOffset.getField();
DTFJJavaObject jobj = validateJavaObject(object);
checkDataTypeConversion(jobj, FIELD_OBJECT | FIELD_ARRAY);
J9ObjectPointer data = J9ObjectHelper.getObjectField(jobj.getJ9ObjectPointer(), fieldOffset);
if (data.isNull()) {
return null;
} else {
return new DTFJJavaObject(null, data);
}
default:
throw new IllegalArgumentException("Cannot determine the correct data type");
}
} catch (Throwable t) {
// the whitelist will cause IllegalArgumentException to be re-thrown
throw J9DDRDTFJUtils.handleAllButMemAccExAsCorruptDataException(DTFJContext.getProcess(), t, whitelist);
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer 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.pointer.generated.J9ObjectPointer in project openj9 by eclipse.
the class LiveSetWalker method scanObject.
private static void scanObject(HashSet<J9ObjectPointer> visitedObjects, ObjectVisitor visitor, J9ObjectPointer object, VoidPointer address) {
if (visitedObjects.contains(object)) {
return;
}
if (!visitor.visit(object, address)) {
return;
}
visitedObjects.add(object);
try {
GCObjectIterator objectIterator = GCObjectIterator.fromJ9Object(object, true);
GCObjectIterator addressIterator = GCObjectIterator.fromJ9Object(object, true);
while (objectIterator.hasNext()) {
J9ObjectPointer slot = objectIterator.next();
VoidPointer addr = addressIterator.nextAddress();
if (slot.notNull()) {
scanObject(visitedObjects, visitor, slot, addr);
}
}
if (J9ObjectHelper.getClassName(object).equals("java/lang/Class")) {
J9ClassPointer clazz = ConstantPoolHelpers.J9VM_J9CLASS_FROM_HEAPCLASS(object);
// Iterate the Object slots
GCClassIterator classIterator = GCClassIterator.fromJ9Class(clazz);
GCClassIterator classAddressIterator = GCClassIterator.fromJ9Class(clazz);
while (classIterator.hasNext()) {
J9ObjectPointer slot = classIterator.next();
VoidPointer addr = classAddressIterator.nextAddress();
if (slot.notNull()) {
scanObject(visitedObjects, visitor, slot, addr);
}
}
// Iterate the Class slots
GCClassIteratorClassSlots classSlotIterator = GCClassIteratorClassSlots.fromJ9Class(clazz);
GCClassIteratorClassSlots classSlotAddressIterator = GCClassIteratorClassSlots.fromJ9Class(clazz);
while (classSlotIterator.hasNext()) {
J9ClassPointer slot = classSlotIterator.next();
VoidPointer addr = classSlotAddressIterator.nextAddress();
J9ObjectPointer classObject = ConstantPoolHelpers.J9VM_J9CLASS_TO_HEAPCLASS(slot);
if (classObject.notNull()) {
scanObject(visitedObjects, visitor, classObject, addr);
}
}
}
} catch (CorruptDataException e) {
EventManager.raiseCorruptDataEvent("Corruption found while walking the live set, object: " + object.getHexAddress(), e, false);
}
visitor.finishVisit(object, address);
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9ObjectPointer in project openj9 by eclipse.
the class LiveSetWalker method walkLiveSet.
/*
* Walks the LiveSet in preorder, returns a HashSet of all walked objects. The HashSet is generated as a byproduct of the walk.
*
* @return a HashSet containing all visited objects
*/
public static void walkLiveSet(ObjectVisitor visitor, RootSetType rootSetType) throws CorruptDataException {
/* TODO: lpnguyen, use something less stupid than a hashSet (markMap?) for this */
HashSet<J9ObjectPointer> visitedObjects = new HashSet<J9ObjectPointer>();
/* Not using a singleton because we want to allow users to catch corruptData events. Not worrying about the perf loss taken
* by doing this as walking the live set will probably take an order of magnitude longer anyway
*/
RootSet rootSet = RootSet.from(rootSetType, false);
GCIterator rootIterator = rootSet.gcIterator(rootSetType);
GCIterator rootAddressIterator = rootSet.gcIterator(rootSetType);
while (rootIterator.hasNext()) {
J9ObjectPointer nextObject = (J9ObjectPointer) rootIterator.next();
VoidPointer nextAddress = rootAddressIterator.nextAddress();
if (nextObject.notNull()) {
scanObject(visitedObjects, visitor, nextObject, nextAddress);
}
}
}
Aggregations