예제 #1
0
파일: memory.c 프로젝트: tobium/robovm
Array* rvmAllocateMemoryForArray(Env* env, Class* arrayClass, jint length) {
    jint elementSize = rvmGetArrayElementSize(env, arrayClass);
    if (elementSize == 0) {
        return NULL;
    }
    jlong size = (jlong) sizeof(Array) + (jlong) length * (jlong) elementSize;
    if (size > (jlong) (size_t) -1) {
        rvmThrowOutOfMemoryError(env);
        return NULL;
    }
    Array* m = NULL;
    if (CLASS_IS_PRIMITIVE(arrayClass->componentType)) {
        // Primitive array objects contain no pointers except for the Class
        // pointer and possibly a fat monitor. Those are allocated uncollectably
        // and will be reachable even if we alocate this atomically.
        m = (Array*) gcAllocateKind((size_t) size, atomicObjectGCKind);
    } else if (length < 30) {
        // TODO: Use GC bitmap descriptor for small Object arrays.
        m = (Array*) gcAllocateKind((size_t) size, objectGCKind);
    } else {
        // Large Object array. Conservatively scanned. Only the lock (if thin) 
        // and the length fields could become a problem if they look like 
        // pointers into the heap.
        m = (Array*) gcAllocateKind((size_t) size, largeArrayGCKind);
    }
    if (!m) {
        rvmThrowOutOfMemoryError(env);
        return NULL;
    }
    return m;
}
예제 #2
0
파일: memory.c 프로젝트: tobium/robovm
Object* rvmAllocateMemoryForObject(Env* env, Class* clazz) {
    Object* m = NULL;
    if (CLASS_IS_FINALIZABLE(clazz) || CLASS_IS_REFERENCE(clazz) 
        || (clazz->superclass && clazz->superclass == org_robovm_rt_bro_Struct)
        || (clazz->superclass && clazz->superclass == java_nio_MemoryBlock)
        || (clazz == java_nio_MemoryBlock)) {

        // These types of objects must be marked specially. We could probably
        // do this using GC bitmap descriptors instead. Also instances of
        // java.lang.Throwable must be marked specially but it has at least 1
        // reference field and will thus not be allocated atomically.

        m = (Object*) gcAllocateKind(clazz->instanceDataSize, objectGCKind);
    } else if (CLASS_IS_REF_FREE(clazz)) {
        // Objects with 0 instance reference fields contain no pointers except for the Class
        // pointer and possibly a fat monitor. Those are allocated uncollectably
        // and will be reachable even if we alocate this atomically.
        m = (Object*) gcAllocateKind(clazz->instanceDataSize, atomicObjectGCKind);
    } else {
        // TODO: Use GC bitmap descriptors for small Objects.
        m = (Object*) gcAllocateKind(clazz->instanceDataSize, objectGCKind);
    }
    if (!m) {
        if (clazz == java_lang_OutOfMemoryError) {
            // We can't even allocate an OutOfMemoryError object. Prevent
            // infinite recursion by returning the shared criticalOutOfMemoryError
            // object.
            return criticalOutOfMemoryError;
        }
        rvmThrowOutOfMemoryError(env);
        return NULL;
    }
    return m;
}
예제 #3
0
파일: memory.c 프로젝트: tobium/robovm
void* allocateMemoryOfKind(Env* env, size_t size, uint32_t kind) {
    void* m = gcAllocateKind(size, kind);
    if (!m) {
        rvmThrowOutOfMemoryError(env);
        return NULL;
    }
    return m;
}
예제 #4
0
파일: memory.c 프로젝트: tobium/robovm
Class* rvmAllocateMemoryForClass(Env* env, jint classDataSize) {
    Class* m = (Class*) gcAllocateKind(classDataSize, objectGCKind);
    if (!m) {
        rvmThrowOutOfMemoryError(env);
        return NULL;
    }
    return m;
}
예제 #5
0
Array* rvmAllocateMemoryForArray(Env* env, jint length, jint elementSize) {
    return gcAllocateKind(sizeof(Array) + length * elementSize, object_gc_kind);
}
예제 #6
0
Object* rvmAllocateMemoryForObject(Env* env, Class* clazz) {
    return gcAllocateKind(clazz->instanceDataSize, object_gc_kind);
}
예제 #7
0
Class* rvmAllocateMemoryForClass(Env* env, jint classDataSize) {
    return gcAllocateKind(classDataSize, object_gc_kind);
}