diff --git a/libraryInterface/Common/src/sun/misc/Unsafe.java b/libraryInterface/Common/src/sun/misc/Unsafe.java index ff6697af7d..56eb28271e 100644 --- a/libraryInterface/Common/src/sun/misc/Unsafe.java +++ b/libraryInterface/Common/src/sun/misc/Unsafe.java @@ -19,6 +19,7 @@ import org.jikesrvm.classloader.RVMClassLoader; import org.jikesrvm.classloader.RVMField; import org.jikesrvm.classloader.RVMType; +import org.jikesrvm.objectmodel.ObjectModel; import org.jikesrvm.runtime.Magic; import org.jikesrvm.runtime.RuntimeEntrypoints; import org.jikesrvm.scheduler.Synchronization; @@ -62,6 +63,8 @@ public static Unsafe getUnsafe() { @Inline public long allocateMemory(long bytes) { + // TODO sysMalloc needs to be changed to Extent because the C + // prototype uses size_t Address result = SysCall.sysCall.sysMalloc((int)bytes); if (result.isZero()) { throw new OutOfMemoryError("Unable to satisfy malloc of " + bytes); @@ -90,7 +93,18 @@ public int pageSize() { */ @Inline public void ensureClassInitialized(Class c){ - // TODO implement + RVMType type = JikesRVMSupport.getTypeForClass(c); + if (!type.isInitialized()) { + if (type.isClassType()) { + RuntimeEntrypoints.initializeClassForDynamicLink(type.asClass()); + } else { + // TODO these 3 methods appear a few times in the code base together. + // Consider refactoring this + type.resolve(); + type.instantiate(); + type.initialize(); + } + } } @Inline @@ -125,8 +139,7 @@ public long objectFieldOffset(Field field) { @Inline public int arrayBaseOffset(Class arrayClass) { - // TODO should we get this via ObjectModel? - return 0; + return ObjectModel.getArrayBaseOffset().toInt(); } @Inline @@ -155,7 +168,7 @@ public void setMemory(long address, long bytes, byte value) { @Inline public void copyMemory(long srcAddress, long destAddress, long bytes) { - Memory.memcopy(Address.fromLong(destAddress), Address.fromLong(srcAddress), (int)bytes); + Memory.memcopy(Address.fromLong(destAddress), Address.fromLong(srcAddress), Offset.fromLong(bytes).toWord().toExtent()); } @Inline diff --git a/rvm/src/org/jikesrvm/objectmodel/ObjectModel.java b/rvm/src/org/jikesrvm/objectmodel/ObjectModel.java index a99047c68e..877a04959a 100644 --- a/rvm/src/org/jikesrvm/objectmodel/ObjectModel.java +++ b/rvm/src/org/jikesrvm/objectmodel/ObjectModel.java @@ -180,6 +180,16 @@ public static Offset getArrayLengthOffset() { return ARRAY_LENGTH_OFFSET; } + /** + * NB: this method exists only for documentation purposes. + * + * @return the offset of the first array element from the array's address + * (in bytes). Always {@code 0} in the current object model. + */ + public static Offset getArrayBaseOffset() { + return Offset.zero(); + } + public static TIB getTIB(ObjectReference ptr) { return getTIB(ptr.toObject()); }