Index: vm/gc_gen/javasrc/org/apache/harmony/drlvm/gc_gen/GCHelper.java =================================================================== --- vm/gc_gen/javasrc/org/apache/harmony/drlvm/gc_gen/GCHelper.java (revision 489110) +++ vm/gc_gen/javasrc/org/apache/harmony/drlvm/gc_gen/GCHelper.java (working copy) @@ -22,6 +22,7 @@ import org.apache.harmony.drlvm.VMHelper; import org.vmmagic.unboxed.*; +import org.vmmagic.pragma.*; public class GCHelper { @@ -29,8 +30,7 @@ public static final int TLS_GC_OFFSET = TLSGCOffset(); - public static Address alloc(int objSize, int allocationHandle) { - + public static Address alloc(int objSize, int allocationHandle) throws InlinePragma { Address TLS_BASE = VMHelper.getTlsBaseAddress(); Address allocator_addr = TLS_BASE.plus(TLS_GC_OFFSET); @@ -49,6 +49,43 @@ return VMHelper.newResolvedUsingAllocHandleAndSize(objSize, allocationHandle); } + + private static final int ARRAY_LEN_OFFSET = 8; + private static final int GC_OBJECT_ALIGNMENT = 4; //TODO: EM64 or IPF could have 8! + + public static Address allocArray(int arrayLen, int elemSize, int allocationHandle) throws InlinePragma { + if (arrayLen >= 0) { + int firstElementOffset = ARRAY_LEN_OFFSET + (elemSize==8?8:4); + int size = firstElementOffset + elemSize*arrayLen; + size = (((size + (GC_OBJECT_ALIGNMENT - 1)) & (~(GC_OBJECT_ALIGNMENT - 1)))); + + Address arrayAddress = alloc(size, allocationHandle); //never null! + arrayAddress.store(arrayLen, Offset.fromInt(ARRAY_LEN_OFFSET)); + return arrayAddress; + } + return VMHelper.newVectorUsingAllocHandle(arrayLen, elemSize, allocationHandle); + } + + + /** NOS (nursery object space) is higher in address than other spaces. + The boundary currently is produced in GC initialization. It can + be a constant in future. + */ + public static final int NOS_BOUNDARY = 0x50000000; + + public static void write_barrier_slot_rem(Address p_objBase, Address p_objSlot, Address p_source) throws InlinePragma { + p_objSlot.store(p_source); + /* If the slot is in NOS or the target is not in NOS, we simply return*/ + if(p_objSlot.toInt() >= NOS_BOUNDARY || p_source.toInt() < NOS_BOUNDARY) { + return; + } + + /* Otherwise, we need remember it in native code. */ + VMHelper.writeBarrier(p_objBase, p_objSlot, p_source); + } + + + private static native int getNosBoundary(); private static native int TLSGCOffset(); } Index: vm/gc_gen/src/jni/helper.cpp =================================================================== --- vm/gc_gen/src/jni/helper.cpp (revision 489110) +++ vm/gc_gen/src/jni/helper.cpp (working copy) @@ -1,8 +1,8 @@ #include #include #include "../thread/gc_thread.h" +#include "../gen/gen.h" - #ifdef __cplusplus extern "C" { #endif @@ -17,6 +17,15 @@ return (jint)tls_gc_offset; } + + +JNIEXPORT jint JNICALL Java_org_apache_harmony_drlvm_gc_1gen_GCHelper_getNosBoundary(JNIEnv *e, jclass c) +{ + return (jint)NOS_BOUNDARY; +} + + + #ifdef __cplusplus } #endif