示例#1
0
void initialiseString() {
    FieldBlock *count = NULL, *value, *offset;

    string_class = findSystemClass0(SYMBOL(java_lang_String));
    registerStaticClassRef(&string_class);

    if(string_class != NULL) {
        count = findField(string_class, SYMBOL(count), SYMBOL(I));
        value = findField(string_class, SYMBOL(value), SYMBOL(array_C));
        offset = findField(string_class, SYMBOL(offset), SYMBOL(I));
    }

    /* findField doesn't throw an exception... */
    if((count == NULL) || (value == NULL) || (offset == NULL)) {
        jam_fprintf(stderr, "Error initialising VM (initialiseString)\n");
        exitVM(1);
    }

    count_offset = count->offset;
    value_offset = value->offset;
    offset_offset = offset->offset;

    /* Init hash table and create lock */
    initHashTable(hash_table, HASHTABSZE, TRUE);
}
示例#2
0
int classlibInitialiseNatives() {
    Class *field_accessor;
    FieldBlock *base_fb = NULL;
    char *dll_path = getBootDllPath();
    char *dll_name = getDllName("java");
    char path[strlen(dll_path) + strlen(dll_name) + 2];

    strcat(strcat(strcpy(path, dll_path), "/"), dll_name);
    sysFree(dll_name);

    if(!resolveDll(path, NULL)) {
        jam_fprintf(stderr, "Error initialising natives: couldn't open "
                            "libjava.so: use -verbose:jni for more "
                            "information\n");
        return FALSE;
    }

    field_accessor = findSystemClass0(SYMBOL(
                         sun_reflect_UnsafeStaticFieldAccessorImpl));

    if(field_accessor != NULL)
        base_fb = findField(field_accessor, SYMBOL(base),
                                            SYMBOL(sig_java_lang_Object));

    if(base_fb == NULL) {
        jam_fprintf(stderr, "Error initialising natives: %s "
                            "missing or malformed\n",
                            SYMBOL(sun_reflect_UnsafeStaticFieldAccessorImpl));
        return FALSE;
    }

    hideFieldFromGC(base_fb);

    return initialiseJVMInterface();
}
示例#3
0
int classlibInitialiseAccess() {
    magic_accessor = findSystemClass0(SYMBOL(sun_reflect_MagicAccessorImpl));
    if(magic_accessor == NULL)
        return FALSE;

    registerStaticClassRef(&magic_accessor);
    return TRUE;
}
示例#4
0
文件: jni.c 项目: Liam1206/jamvm
int classlibInitialiseJNI() {
    FieldBlock *buffCap_fb, *buffAddr_fb, *rawdata_fb;
    Class *buffer_class;

    /* Cache class and method/fields for JNI 1.4 NIO support */

    buffer_class = findSystemClass0(SYMBOL(java_nio_Buffer));
    buffImpl_class = findSystemClass0(
                         SYMBOL(java_nio_DirectByteBufferImpl_ReadWrite));
    rawdata_class = findSystemClass0(sizeof(uintptr_t) == 4
                                            ? SYMBOL(gnu_classpath_Pointer32)
                                            : SYMBOL(gnu_classpath_Pointer64));

    if(buffer_class == NULL || buffImpl_class == NULL || rawdata_class == NULL)
        return FALSE;

    buffImpl_init_mb = findMethod(buffImpl_class, SYMBOL(object_init),
                      SYMBOL(_java_lang_Object_gnu_classpath_Pointer_III__V));

    buffCap_fb = findField(buffer_class, SYMBOL(cap), SYMBOL(I));
    rawdata_fb = findField(rawdata_class, SYMBOL(data),
                           sizeof(uintptr_t) == 4 ? SYMBOL(I) : SYMBOL(J));
    buffAddr_fb = findField(buffer_class, SYMBOL(address),
                            SYMBOL(sig_gnu_classpath_Pointer));

    if(buffImpl_init_mb == NULL || buffCap_fb == NULL || rawdata_fb == NULL
                                || buffAddr_fb == NULL)
        return FALSE;

    registerStaticClassRef(&buffImpl_class);
    registerStaticClassRef(&rawdata_class);

    buffCap_offset = buffCap_fb->u.offset;
    buffAddr_offset = buffAddr_fb->u.offset;
    rawdata_offset = rawdata_fb->u.offset;

    return TRUE;
}
示例#5
0
文件: excep.c 项目: OPSF/uClinux
void initialiseException() {
    FieldBlock *bcktrce;
    int i;

    ste_class = findSystemClass0(SYMBOL(java_lang_StackTraceElement));
    ste_array_class = findArrayClass(SYMBOL(array_java_lang_StackTraceElement));
    vmthrow_class = findSystemClass0(SYMBOL(java_lang_VMThrowable));
    throw_class = findSystemClass0(SYMBOL(java_lang_Throwable));
    bcktrce = findField(vmthrow_class, SYMBOL(backtrace), SYMBOL(sig_java_lang_Object));
    vmthrow_init_mb = findMethod(ste_class, SYMBOL(object_init),
                         SYMBOL(_java_lang_String_I_java_lang_String_java_lang_String_Z__V));

    if((bcktrce == NULL) || (vmthrow_init_mb == NULL)) {
        jam_fprintf(stderr, "Error initialising VM (initialiseException)\n");
        exitVM(1);
    }

    CLASS_CB(vmthrow_class)->flags |= VMTHROWABLE;
    backtrace_offset = bcktrce->offset;

    registerStaticClassRef(&ste_class);
    registerStaticClassRef(&ste_array_class);
    registerStaticClassRef(&vmthrow_class);
    registerStaticClassRef(&throw_class);

    /* Load and register the exceptions used within the VM.
       These are preloaded to speed up access.  The VM will
       abort if any can't be loaded */

    for(i = 0; i < MAX_EXCEPTION_ENUM; i++) {
        exceptions[i] = findSystemClass0(symbol_values[exception_symbols[i]]);
        registerStaticClassRef(&exceptions[i]);
    }

    inited = TRUE;
}
示例#6
0
void initialiseThreadStage2(InitArgs *args) {
    Object *java_thread;
    Class *thrdGrp_class;
    MethodBlock *run, *remove_thread;
    FieldBlock *group, *priority, *root, *threadId;
    FieldBlock *vmThread = NULL, *thread = NULL;
    FieldBlock *vmData, *daemon, *name;

    /* Load thread class and register reference for compaction threading */
    thread_class = findSystemClass0(SYMBOL(java_lang_Thread));
    registerStaticClassRef(&thread_class);

    if(thread_class != NULL) {
        vmThread = findField(thread_class, SYMBOL(vmThread), SYMBOL(sig_java_lang_VMThread));
        daemon = findField(thread_class, SYMBOL(daemon), SYMBOL(Z));
        name = findField(thread_class, SYMBOL(name), SYMBOL(sig_java_lang_String));
        group = findField(thread_class, SYMBOL(group), SYMBOL(sig_java_lang_ThreadGroup));
        priority = findField(thread_class, SYMBOL(priority), SYMBOL(I));
        threadId = findField(thread_class, SYMBOL(threadId), SYMBOL(J));

        init_mb = findMethod(thread_class, SYMBOL(object_init),
                             SYMBOL(_java_lang_VMThread_java_lang_String_I_Z__V));
        run = findMethod(thread_class, SYMBOL(run), SYMBOL(___V));

        vmthread_class = findSystemClass0(SYMBOL(java_lang_VMThread));
        CLASS_CB(vmthread_class)->flags |= VMTHREAD;

        /* Register class reference for compaction threading */
        registerStaticClassRef(&vmthread_class);

        if(vmthread_class != NULL) {
            thread = findField(vmthread_class, SYMBOL(thread), SYMBOL(sig_java_lang_Thread));
            vmData = findField(vmthread_class, SYMBOL(vmData), SYMBOL(I));
        }
    }

    /* findField and findMethod do not throw an exception... */
    if((init_mb == NULL) || (vmData == NULL) || (run == NULL) || (daemon == NULL) ||
       (name == NULL) || (group == NULL) || (priority == NULL) || (vmThread == NULL) ||
       (thread == NULL) || (threadId == NULL))
        goto error;

    vmthread_offset = vmThread->offset;
    thread_offset = thread->offset;
    vmData_offset = vmData->offset;
    daemon_offset = daemon->offset;
    group_offset = group->offset;
    priority_offset = priority->offset;
    threadId_offset = threadId->offset;
    name_offset = name->offset;
    run_mtbl_idx = run->method_table_index;

    /* Initialise the Java-level thread objects for the main thread */
    java_thread = initJavaThread(&main_thread, FALSE, "main");

    /* Main thread is now sufficiently setup to be able to run the thread group
       initialiser.  This is essential to create the root thread group */
    thrdGrp_class = findSystemClass(SYMBOL(java_lang_ThreadGroup));

    root = findField(thrdGrp_class, SYMBOL(root), SYMBOL(sig_java_lang_ThreadGroup));

    addThread_mb = findMethod(thrdGrp_class, SYMBOL(addThread),
                                             SYMBOL(_java_lang_Thread_args__void));

    remove_thread = findMethod(thrdGrp_class, SYMBOL(removeThread),
                                              SYMBOL(_java_lang_Thread_args__void));

    /* findField and findMethod do not throw an exception... */
    if((root == NULL) || (addThread_mb == NULL) || (remove_thread == NULL))
        goto error;

    rmveThrd_mtbl_idx = remove_thread->method_table_index;

    /* Add the main thread to the root thread group */
    INST_DATA(java_thread)[group_offset] = root->static_value;
    {
        DummyFrame dummy;
        executeMethod(&dummy, ((Object*)root->static_value), addThread_mb, java_thread);
    }

    // dyn
    INST_DATA(java_thread)[vmthread_offset] = 0;

    /* Setup signal handling.  This will be inherited by all
       threads created within Java */
    initialiseSignals();

    /* Create the signal handler thread.  It is responsible for
       catching and handling SIGQUIT (thread dump) and SIGINT
       (user-termination of the VM, e.g. via Ctrl-C).  Note it
       must be a valid Java-level thread as it needs to run the
       shutdown hooks in the event of user-termination */
    createVMThread("Signal Handler", dumpThreadsLoop);

    return;

error:
    jam_fprintf(stderr, "Error initialising VM (initialiseMainThread)\nCheck "
                        "the README for compatible versions of GNU Classpath\n");
    printException();
    exitVM(1);
}