Navigation Menu

Skip to content

Commit

Permalink
RVM-1045 : Implement ensureClassInitialized and clean up a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-brangs committed Mar 2, 2016
1 parent 6a229c4 commit 12e7ce6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 17 additions & 4 deletions libraryInterface/Common/src/sun/misc/Unsafe.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions rvm/src/org/jikesrvm/objectmodel/ObjectModel.java
Expand Up @@ -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());
}
Expand Down

0 comments on commit 12e7ce6

Please sign in to comment.