Esempio n. 1
0
Object *classlibThreadPreInit(Class *thread_class, Class *thrdGrp_class) {
    MethodBlock *system_init_mb, *main_init_mb;
    FieldBlock *thread_status_fb, *eetop_fb;
    Object *system, *main, *main_name;

    init_mb_with_name = findMethod(thread_class, SYMBOL(object_init),
                           SYMBOL(_java_lang_ThreadGroup_java_lang_String__V));

    init_mb_no_name = findMethod(thread_class, SYMBOL(object_init),
                         SYMBOL(_java_lang_ThreadGroup_java_lang_Runnable__V));

    thread_status_fb = findField(thread_class, SYMBOL(threadStatus),
                                               SYMBOL(I));

    eetop_fb = findField(thread_class, SYMBOL(eetop), SYMBOL(J));

    system_init_mb = findMethod(thrdGrp_class, SYMBOL(object_init),
                                               SYMBOL(___V));

    main_init_mb = findMethod(thrdGrp_class, SYMBOL(object_init),
                           SYMBOL(_java_lang_ThreadGroup_java_lang_String__V));

    if(init_mb_with_name   == NULL || init_mb_no_name == NULL ||
          system_init_mb   == NULL || main_init_mb    == NULL ||
          thread_status_fb == NULL || eetop_fb        == NULL)
        return NULL;

    CLASS_CB(thread_class)->flags |= JTHREAD;

    thread_status_offset = thread_status_fb->u.offset;
    eetop_offset = eetop_fb->u.offset;

    if((system = allocObject(thrdGrp_class)) == NULL)
        return NULL;

    executeMethod(system, system_init_mb);
    if(exceptionOccurred())
        return NULL;

    if((main = allocObject(thrdGrp_class)) == NULL ||
       (main_name = Cstr2String("main")) == NULL)
        return NULL;

    executeMethod(main, main_init_mb, system, main_name);
    if(exceptionOccurred())
        return NULL;

    return main;
}
Esempio n. 2
0
bool
CMediaPlayer::isPlaying()
{
	jboolean result = getEnv()->CallBooleanMethod(m_obj, m_isPlaying);
	exceptionOccurred();
	return (result) ? true : false;
}
Esempio n. 3
0
native_netscape_javascript_JSObject_getWindow(
    JRIEnv* env,
    struct java_lang_Class* clazz,
    struct java_applet_Applet* hint)
{
#ifndef JAVA
    return NULL;
#else
    struct netscape_javascript_JSObject *ret = NULL;
    JSContext *cx;
    JSSavedState saved;
    JSObject *jso;

    if (!JSJ_IsEnabled()) {
        js_throwJSException(env, "Java/JavaScript communication is disabled");
        return 0;
    }

    if (!enterJS(env, NULL, &cx, NULL, &saved))
        return NULL;

    jso = JSJ_GetDefaultObject(env, (jobject) hint);
    if (exceptionOccurred((ExecEnv *)env))
        goto out;

    ret = (struct netscape_javascript_JSObject *)
        js_ReflectJSObjectToJObject(cx, jso);

  out:
    if (!exitJS(env, NULL, cx, NULL, &saved))
        return NULL;
    return ret;
#endif
}
Esempio n. 4
0
File: jam.c Progetto: cfriedt/jamvm
int main(int argc, char *argv[]) {
    Class *array_class, *main_class;
    Object *system_loader, *array;
    MethodBlock *mb;
    InitArgs args;
    int class_arg;
    char *cpntr;
    int status;
    int i;

    setDefaultInitArgs(&args);
    class_arg = parseCommandLine(argc, argv, &args);

    args.main_stack_base = &array_class;

    if(!initVM(&args)) {
        printf("Could not initialise VM.  Aborting.\n");
        exit(1);
    }

   if((system_loader = getSystemClassLoader()) == NULL)
        goto error;

    mainThreadSetContextClassLoader(system_loader);

    for(cpntr = argv[class_arg]; *cpntr; cpntr++)
        if(*cpntr == '.')
            *cpntr = '/';

    main_class = findClassFromClassLoader(argv[class_arg], system_loader);
    if(main_class != NULL)
        initClass(main_class);

    if(exceptionOccurred())
        goto error;

    mb = lookupMethod(main_class, SYMBOL(main),
                                  SYMBOL(_array_java_lang_String__V));

    if(mb == NULL || !(mb->access_flags & ACC_STATIC)) {
        signalException(java_lang_NoSuchMethodError, "main");
        goto error;
    }

    /* Create the String array holding the command line args */

    i = class_arg + 1;
    if((array_class = findArrayClass(SYMBOL(array_java_lang_String))) &&
           (array = allocArray(array_class, argc - i, sizeof(Object*))))  {
        Object **args = ARRAY_DATA(array, Object*) - i;

        for(; i < argc; i++)
            if(!(args[i] = Cstr2String(argv[i])))
                break;

        /* Call the main method */
        if(i == argc)
            executeStaticMethod(main_class, mb, array);
    }
Esempio n. 5
0
void
CMediaPlayer::start()
{
	DEBUG_PRINT("CMediaPlayer::start() in...");
	getEnv()->CallVoidMethod(m_obj, m_start);
	exceptionOccurred();
	DEBUG_PRINT("CMediaPlayer::start() exit.");
}
Esempio n. 6
0
void
CMediaPlayer::setLooping(bool looping)
{
	DEBUG_PRINT("CMediaPlayer::setLooping() in...");
	getEnv()->CallVoidMethod(m_obj, m_setLooping, (jboolean)looping);
	exceptionOccurred();
	DEBUG_PRINT("CMediaPlayer::setLooping() exit.");
}
Esempio n. 7
0
s32
CMediaPlayer::getCurrentPos()
{
	s32 ret = 0;

	DEBUG_PRINT("CMediaPlayer::getCurrentPos() in...");
	ret = getEnv()->CallIntMethod(m_obj, m_getCurrentPos);
	exceptionOccurred();
	DEBUG_PRINT("CMediaPlayer::getCurrentPos() exit.");

	return ret;
}
Esempio n. 8
0
char classlibInitJavaThread(Thread *thread, Object *jlthread, Object *name,
                            Object *group, char is_daemon, int priority) {

    INST_DATA(jlthread, Thread*, eetop_offset) = thread;
    INST_DATA(jlthread, int, daemon_offset) = is_daemon;
    INST_DATA(jlthread, int, priority_offset) = priority;

    if(name == NULL)
        executeMethod(jlthread, init_mb_no_name, group, NULL);
    else
        executeMethod(jlthread, init_mb_with_name, group, name);

    return !exceptionOccurred();
}
Esempio n. 9
0
int classlibThreadPostInit() {
    Class *system = findSystemClass(SYMBOL(java_lang_System));

    if(system != NULL) {
        MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass),
                                               SYMBOL(___V));
        if(init != NULL) {
            executeStaticMethod(system, init);
            return !exceptionOccurred();
        }
    }

    return FALSE;
}
Esempio n. 10
0
File: excep.c Progetto: OPSF/uClinux
void signalChainedExceptionName(char *excep_name, char *message, Object *cause) {
    if(!inited) {
        jam_fprintf(stderr, "Exception occurred while VM initialising.\n");
        if(message)
            jam_fprintf(stderr, "%s: %s\n", excep_name, message);
        else
            jam_fprintf(stderr, "%s\n", excep_name);
        exit(1);
    } else {
        Class *exception = findSystemClass(excep_name);

        if(!exceptionOccurred())
            signalChainedExceptionClass(exception, message, cause);
    }
}
Esempio n. 11
0
File: excep.c Progetto: OPSF/uClinux
void signalChainedExceptionClass(Class *exception, char *message, Object *cause) {
    Object *exp = allocObject(exception);
    Object *str = message == NULL ? NULL : Cstr2String(message);
    MethodBlock *init = lookupMethod(exception, SYMBOL(object_init),
                                                SYMBOL(_java_lang_String__V));
    if(exp && init) {
        executeMethod(exp, init, str);

        if(cause && !exceptionOccurred()) {
            MethodBlock *mb = lookupMethod(exception, SYMBOL(initCause),
                                           SYMBOL(_java_lang_Throwable__java_lang_Throwable));
            if(mb)
                executeMethod(exp, mb, cause);
        }
        setException(exp);
    }
}
Esempio n. 12
0
static bool_t
exitJS(JRIEnv *env,
       struct netscape_javascript_JSObject* self,
       JSContext *cx, JSObject *jso, JSSavedState *saved)
{
#ifndef JAVA
	return JS_FALSE;
#else
    /* restore saved info */
    JS_SetErrorReporter(cx, saved->errReporter);

    js_JSErrorToJException(cx, (ExecEnv*)env);

    JSJ_ExitJS();

    if (exceptionOccurred((ExecEnv*)env))
        return FALSE;

    return TRUE;
#endif
}
Esempio n. 13
0
int classlibThreadPostInit() {
    Class *system;

#ifdef JSR292
    /* Initialise lock used in Method Handle resolution - this
       must be done before any invokedynamic instruction is executed */
    initVMLock(resolve_lock);
#endif

    /* Initialise System class */
    system = findSystemClass(SYMBOL(java_lang_System));
    if(system != NULL) {
        MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass),
                                               SYMBOL(___V));
        if(init != NULL) {
            executeStaticMethod(system, init);
            return !exceptionOccurred();
        }
    }

    return FALSE;
}
Esempio n. 14
0
void
CMediaPlayer::setDataSource(const char * path)
{
	DEBUG_PRINT("CMediaPlayer::setDataSource() in ... m_obj = %p", m_obj);
	jstring jpath = getEnv()->NewStringUTF(path);

	//
	jclass local_fs = getEnv()->FindClass("java/io/FileInputStream");
	jmethodID cns = getEnv()->GetMethodID(local_fs, "<init>", "(Ljava/lang/String;)V");
	jobject local_obj = getEnv()->NewObject(local_fs, cns, jpath);	// C++からアクセスするためのインスタンス作成
	jobject global_obj = getEnv()->NewGlobalRef(local_obj);
	jmethodID getFD = getEnv()->GetMethodID(local_fs, "getFD", "()Ljava/io/FileDescriptor;");

	getEnv()->CallVoidMethod( m_obj,
							  m_setDataSource,
			                  getEnv()->CallObjectMethod(global_obj, getFD) );

	getEnv()->DeleteGlobalRef(global_obj);
	CJNI::getJNIEnv()->DeleteLocalRef(local_fs);
	CJNI::getJNIEnv()->DeleteLocalRef(local_obj);
	CJNI::getJNIEnv()->DeleteLocalRef(jpath);
	exceptionOccurred();
	DEBUG_PRINT("CMediaPlayer::setDataSource(): path = %s", path);
}
Esempio n. 15
0
void detachThread(Thread *thread) {
    Object *group, *excep;
    //ExecEnv *ee = thread->ee;
    //Object *jThread = ee->thread;
    Object *jThread = thread->thread;
    Object *vmthread = (Object*)INST_DATA(jThread)[vmthread_offset];

    /* Get the thread's group */
    group = (Object *)INST_DATA(jThread)[group_offset];

    /* If there's an uncaught exception, call uncaughtException on the thread's
       exception handler, or the thread's group if this is unset */
    if((excep = exceptionOccurred())) {
        FieldBlock *fb = findField(thread_class, SYMBOL(exceptionHandler),
                                                 SYMBOL(sig_java_lang_Thread_UncaughtExceptionHandler));
        Object *thread_handler = fb == NULL ? NULL : (Object *)INST_DATA(jThread)[fb->offset];
        Object *handler = thread_handler == NULL ? group : thread_handler;

        MethodBlock *uncaught_exp = lookupMethod(handler->classobj, SYMBOL(uncaughtException),
                                                 SYMBOL(_java_lang_Thread_java_lang_Throwable__V));

        if(uncaught_exp) {
            clearException();
            DummyFrame dummy;
            executeMethod(&dummy, handler, uncaught_exp, jThread, excep);
        } else
            printException();
    }

    /* remove thread from thread group */
    DummyFrame dummy;
    executeMethod(&dummy, group, (CLASS_CB(group->classobj))->method_table[rmveThrd_mtbl_idx], jThread);

    /* set VMThread ref in Thread object to null - operations after this
       point will result in an IllegalThreadStateException */
    INST_DATA(jThread)[vmthread_offset] = 0;

    /* Remove thread from the ID map hash table */
    deleteThreadFromHash(thread);

    /* Disable suspend to protect lock operation */
    disableSuspend(thread);

    /* Grab global lock, and update thread structures protected by
       it (thread list, thread ID and number of daemon threads) */
    pthread_mutex_lock(&lock);

    /* remove from thread list... */
    if((thread->prev->next = thread->next))
        thread->next->prev = thread->prev;

    /* One less live thread */
    threads_count--;

    /* Recycle the thread's thread ID */
    freeThreadID(thread->id);

    /* Handle daemon thread status */
    if(!INST_DATA(jThread)[daemon_offset])
        non_daemon_thrds--;

    pthread_mutex_unlock(&lock);

    /* notify any threads waiting on VMThread object -
       these are joining this thread */
    objectLock(vmthread);
    objectNotifyAll(vmthread);
    objectUnlock(vmthread);

    /* It is safe to free the thread's ExecEnv and stack now as these are
       only used within the thread.  It is _not_ safe to free the native
       thread structure as another thread may be concurrently accessing it.
       However, they must have a reference to the VMThread -- therefore, it
       is safe to free during GC when the VMThread is determined to be no
       longer reachable. */
//    sysFree(ee->stack);
    //sysFree(ee);

    /* If no more daemon threads notify the main thread (which
       may be waiting to exit VM).  Note, this is not protected
       by lock, but main thread checks again */

    if(non_daemon_thrds == 0) {
        /* No need to bother with disabling suspension
         * around lock, as we're no longer on thread list */
        pthread_mutex_lock(&exit_lock);
        pthread_cond_signal(&exit_cv);
        pthread_mutex_unlock(&exit_lock);
    }

    TRACE("Thread 0x%x id: %d detached from VM\n", thread, thread->id);
}
Esempio n. 16
0
void
CMediaPlayer::setVolume(float leftVolume, float rightVolume)
{
	getEnv()->CallVoidMethod(m_obj, m_setVolume, leftVolume, rightVolume);
	exceptionOccurred();
}
Esempio n. 17
0
File: jam.c Progetto: OPSF/uClinux
int main(int argc, char *argv[]) {
    Class *array_class, *main_class;
    Object *system_loader, *array;
    MethodBlock *mb;
    InitArgs args;
    int class_arg;
    char *cpntr;
    int status;
    int i;

    setDefaultInitArgs(&args);
    class_arg = parseCommandLine(argc, argv, &args);

    args.main_stack_base = &array_class;
    initVM(&args);

   if((system_loader = getSystemClassLoader()) == NULL) {
        printf("Cannot create system class loader\n");
        printException();
        exitVM(1);
    }

    mainThreadSetContextClassLoader(system_loader);

    for(cpntr = argv[class_arg]; *cpntr; cpntr++)
        if(*cpntr == '.')
            *cpntr = '/';

    if((main_class = findClassFromClassLoader(argv[class_arg], system_loader)) != NULL)
        initClass(main_class);

    if(exceptionOccurred()) {
        printException();
        exitVM(1);
    }

    mb = lookupMethod(main_class, SYMBOL(main), SYMBOL(_array_java_lang_String__V));
    if(!mb || !(mb->access_flags & ACC_STATIC)) {
        printf("Static method \"main\" not found in %s\n", argv[class_arg]);
        exitVM(1);
    }

    /* Create the String array holding the command line args */

    i = class_arg + 1;
    if((array_class = findArrayClass(SYMBOL(array_java_lang_String))) &&
           (array = allocArray(array_class, argc - i, sizeof(Object*))))  {
        Object **args = (Object**)ARRAY_DATA(array) - i;

        for(; i < argc; i++)
            if(!(args[i] = Cstr2String(argv[i])))
                break;

        /* Call the main method */
        if(i == argc)
            executeStaticMethod(main_class, mb, array);
    }

    /* ExceptionOccurred returns the exception or NULL, which is OK
       for normal conditionals, but not here... */
    if((status = exceptionOccurred() ? 1 : 0))
        printException();

    /* Wait for all but daemon threads to die */
    mainThreadWaitToExitVM();
    exitVM(status);
}