NativeDispatcher.c 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14

#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "jmm.h"
#include "com_alibaba_tenant_NativeDispatcher.h"

#define TENANT "Lcom/alibaba/tenant/TenantContainer;"
#define THREAD "Ljava/lang/Thread;"
#define ARRAY_LENGTH(a) (sizeof(a)/sizeof(a[0]))

static const JmmInterface* jmm_interface = NULL;

static JNINativeMethod methods[] = {
15 16 17 18 19
    {"attach",                              "(" TENANT ")V",                      (void *)&JVM_AttachToTenant},
    {"createTenantAllocationContext",       "(" TENANT "J)V",                     (void *)&JVM_CreateTenantAllocationContext},
    {"destroyTenantAllocationContext",      "(J)V",                               (void *)&JVM_DestroyTenantAllocationContext},
    {"getTenantOccupiedMemory",             "(J)J",                               (void *)&JVM_GetTenantOccupiedMemory},
    {"containerOf",                         "(Ljava/lang/Object;)"TENANT,         (void *)&JVM_TenantContainerOf },
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
};

JNIEXPORT void JNICALL
Java_com_alibaba_tenant_NativeDispatcher_registerNatives0(JNIEnv *env, jclass cls)
{
    (*env)->RegisterNatives(env, cls, methods, ARRAY_LENGTH(methods));
}

JNIEXPORT void JNICALL
Java_com_alibaba_tenant_NativeDispatcher_getThreadsAllocatedMemory(JNIEnv *env,
                                                                jobject obj,
                                                                jlongArray ids,
                                                                jlongArray sizeArray)
{
    if (NULL == jmm_interface) {
        jmm_interface = (JmmInterface*) JVM_GetManagement(JMM_VERSION_1_0);
    }

    jmm_interface->GetThreadAllocatedMemory(env, ids, sizeArray);
}