Exemplo n.º 1
0
/*
 * This method will pre-fetch all the necessary JNI ID's. It expects there to be
 * a valid JNIEnv in this->jnienv (so attachToJVM() should have been called first.
 *
 * This method will also create an instance of the java proxy class through which
 * RTIambassador calls will be routed.
 */
void JavaRTI::initialize() throw( RTIinternalError )
{
	//////////////////////////////////////////////////////////////
	// get the proxy class id data and create an instance of it //
	//////////////////////////////////////////////////////////////
	// find the ProxyRtiAmbassador class //

	// Get active environment
	JNIEnv* jnienv = getJniEnvironment();

	this->jproxyClass = jnienv->FindClass( "org/portico/impl/cpp1516e/ProxyRtiAmbassador" );
	if( jproxyClass != NULL )
	{
		// mark the object as a global reference so that the GC doesn't suck it up on us
		this->jproxyClass = (jclass)jnienv->NewGlobalRef( this->jproxyClass );
	}
	if( jproxyClass == NULL )
	{
		logger->fatal( "Can't locate: org.portico.impl.cpp1516e.ProxyRtiAmbassador" );
		exceptionCheck();
		throw RTIinternalError( L"Can't locate: org.portico.impl.cpp1516e.ProxyRtiAmbassador" );
	}

	// find the method id of the constructor //
	jmethodID constructor;
	constructor = jnienv->GetMethodID( jproxyClass, "<init>", "(I)V" );
	if( constructor == NULL )
	{
		logger->fatal( "Can't locate ProxyRtiAmbassador() constructor ID" );
		exceptionCheck();
		throw RTIinternalError( L"Can't locate ProxyRtiAmbassador() constructor ID" );
	}

	// create the instance of the ambassador //
	logger->debug( "Creating new instance of ProxyRtiAmbassador" );
	jobject localReference = jnienv->NewObject( jproxyClass, constructor, this->id );

	// check for an exception
	// we have to use the plain old JNI method of exception detection as to work, the
	// exception manager requires that the JavaRTI instance be in the Runtime's map of
	// instances, and that won't happen until after the constructor, which this method
	// is a part of (in terms of method flow)
	if( jnienv->ExceptionOccurred() )
	{
		jnienv->ExceptionDescribe();
		jnienv->ExceptionClear();
		throw RTIinternalError( L"Exception during ProxyRtiAmbassador() constructor" );
	}

	// turn the reference into something more persistent (stop it from being garbage collected)
	jproxy = jnienv->NewGlobalRef( localReference );
	if( jproxy == NULL )
	{
		logger->fatal( "Could not instantiate ProxyRtiAmbassador" );
		exceptionCheck();
	}

	logger->info( "Initialized new JavaRTI (rti-%d)", this->id );
}
static void setAndroidSdkVersion(JNIEnv *env)
{
    jclass androidVersionClass = env->FindClass("android/os/Build$VERSION");
    if (exceptionCheck(env))
        return;

    jfieldID androidSDKFieldID = env->GetStaticFieldID(androidVersionClass, "SDK_INT", "I");
    if (exceptionCheck(env))
        return;

    g_androidSdkVersion = env->GetStaticIntField(androidVersionClass, androidSDKFieldID);
}
Exemplo n.º 3
0
void QtAndroidPrivate::runOnUiThread(QRunnable *runnable, JNIEnv *env)
{
    Q_ASSERT(runnable != 0);
    env->CallStaticVoidMethod(g_jNativeClass, g_runQtOnUiThreadMethodID, reinterpret_cast<jlong>(runnable));
    if (exceptionCheck(env) && runnable != 0 && runnable->autoDelete())
        delete runnable;
}
Exemplo n.º 4
0
jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
{
    jclass jQtNative = env->FindClass("org/qtproject/qt5/android/QtNative");

    if (env->ExceptionCheck()) {
        env->ExceptionClear();
        return JNI_ERR;
    }

    jmethodID activityMethodID = env->GetStaticMethodID(jQtNative,
                                                        "activity",
                                                        "()Landroid/app/Activity;");

    if (exceptionCheck(env))
        return JNI_ERR;

    jobject activity = env->CallStaticObjectMethod(jQtNative, activityMethodID);
    if (exceptionCheck(env))
        return JNI_ERR;



    jmethodID classLoaderMethodID = env->GetStaticMethodID(jQtNative,
                                                           "classLoader",
                                                           "()Ljava/lang/ClassLoader;");

    if (exceptionCheck(env))
        return JNI_ERR;

    jobject classLoader = env->CallStaticObjectMethod(jQtNative, classLoaderMethodID);
    if (exceptionCheck(env))
        return JNI_ERR;

    setAndroidSdkVersion(env);

    g_jClassLoader = env->NewGlobalRef(classLoader);
    env->DeleteLocalRef(classLoader);
    g_jActivity = env->NewGlobalRef(activity);
    env->DeleteLocalRef(activity);
    g_javaVM = vm;

    return JNI_OK;
}
Exemplo n.º 5
0
jint QtAndroidPrivate::initJNI(JavaVM *vm, JNIEnv *env)
{
    jclass jQtNative = env->FindClass("org/qtproject/qt5/android/QtNative");

    if (exceptionCheck(env))
        return JNI_ERR;

    jmethodID activityMethodID = env->GetStaticMethodID(jQtNative,
                                                        "activity",
                                                        "()Landroid/app/Activity;");

    if (exceptionCheck(env))
        return JNI_ERR;

    jobject activity = env->CallStaticObjectMethod(jQtNative, activityMethodID);
    if (exceptionCheck(env))
        return JNI_ERR;



    jmethodID classLoaderMethodID = env->GetStaticMethodID(jQtNative,
                                                           "classLoader",
                                                           "()Ljava/lang/ClassLoader;");

    if (exceptionCheck(env))
        return JNI_ERR;

    jobject classLoader = env->CallStaticObjectMethod(jQtNative, classLoaderMethodID);
    if (exceptionCheck(env))
        return JNI_ERR;

    setAndroidSdkVersion(env);

    g_jClassLoader = env->NewGlobalRef(classLoader);
    env->DeleteLocalRef(classLoader);
    g_jActivity = env->NewGlobalRef(activity);
    env->DeleteLocalRef(activity);
    g_javaVM = vm;

    static const JNINativeMethod methods[] = {
        {"onAndroidUiThread", "(J)V", reinterpret_cast<void *>(onAndroidUiThread)}
    };

    const bool regOk = (env->RegisterNatives(jQtNative, methods, sizeof(methods) / sizeof(methods[0])) == JNI_OK);

    if (!regOk && exceptionCheck(env))
        return JNI_ERR;

    g_runQtOnUiThreadMethodID = env->GetStaticMethodID(jQtNative,
                                                       "runQtOnUiThread",
                                                       "(J)V");

    g_jNativeClass = static_cast<jclass>(env->NewGlobalRef(jQtNative));
    env->DeleteLocalRef(jQtNative);

    return JNI_OK;
}
Exemplo n.º 6
0
JavaRTI::~JavaRTI()
{
	// delete the global reference to the proxy
	if( this->jproxy != NULL )
	{
		JNIEnv* jnienv = getJniEnvironment();
		jnienv->DeleteGlobalRef( jproxy );
		exceptionCheck();
	}

	// detach from the JVM
	// TODO bring this back in when I can figure out a way to do it that
	//      won't stuff up in situations where there are multiple instances
	//      attaching in a single thread
	//this->detachFromJVM();

	delete this->logger;
}
Exemplo n.º 7
0
void JIT::compileCallEval(Instruction* instruction)
{
    addPtr(TrustedImm32(-static_cast<ptrdiff_t>(sizeof(CallerFrameAndPC))), stackPointerRegister, regT1);
    callOperationNoExceptionCheck(operationCallEval, regT1);

    Jump noException = emitExceptionCheck(InvertedExceptionCheck);
    addPtr(TrustedImm32(stackPointerOffsetFor(m_codeBlock) * sizeof(Register)), callFrameRegister, stackPointerRegister);    
    exceptionCheck(jump());

    noException.link(this);
    addSlowCase(branch64(Equal, regT0, TrustedImm64(JSValue::encode(JSValue()))));

    addPtr(TrustedImm32(stackPointerOffsetFor(m_codeBlock) * sizeof(Register)), callFrameRegister, stackPointerRegister);
    checkStackPointerAlignment();

    sampleCodeBlock(m_codeBlock);
    
    emitPutCallResult(instruction);
}
Exemplo n.º 8
0
/*
 * This will cache an individual method id. It will find the method of the given name
 * and signature and place it into the provided pointer. If there is a problem finding
 * the method, an exception is thrown.
 */
void JavaRTI::cacheMethod( jmethodID *handle, 
                           const char *method, 
                           const char *signature )
	throw( HLA::RTIinternalError )
{
	logger->noisy( "Caching %s [%s]", method, signature );

	// get the method and store it
	*handle = jnienv->GetMethodID( jproxyClass, method, signature );
	if( *handle == NULL )
	{
		char *message = new char[1024];
		sprintf( message, "Could not find %s [%s]", method, signature );
		logger->error( message );
		exceptionCheck();
		throw HLA::RTIinternalError( message );
		delete [] message; // our Exception implementation takes a copy
	}
}
Exemplo n.º 9
0
JavaRTI::~JavaRTI()
{
	// delete the exception information
	if( this->eName != NULL )
		delete [] this->eName;
	if( this->eReason != NULL )
		delete [] this->eReason;

	// delete the global reference to the proxy
	if( this->jproxy != NULL )
	{
		jnienv->DeleteGlobalRef( jproxy );
		exceptionCheck();
	}

	// detach from the JVM
	// TODO bring this back in when I can figure out a way to do it that
	//      won't stuff up in situations where there are multiple instances
	//      attaching in a single thread
	//this->detachFromJVM();

	delete this->logger;
	Runtime::getRuntime()->removeRtiAmbassador( this->id );
}
Exemplo n.º 10
0
/*
 * This method will pre-fetch all the necessary JNI ID's. It expects there to be
 * a valid JNIEnv in this->jnienv (so attachToJVM() should have been called first.
 *
 * This method will also create an instance of the java proxy class through which
 * RTIambassador calls will be routed.
 */
void JavaRTI::initialize() throw( HLA::RTIinternalError )
{
	//////////////////////////////////////////////////////////////
	// get the proxy class id data and create an instance of it //
	//////////////////////////////////////////////////////////////
	// find the Region class //
	this->jregionClass = jnienv->FindClass( "org/portico/impl/hla13/types/HLA13Region" );
	if( jregionClass == NULL )
	{
		logger->fatal( "Can't locate: org.portico.impl.hla13.types.HLA13Region" );
		exceptionCheck();
		throw HLA::RTIinternalError( "Can't locate: org.portico.impl.hla13.types.HLA13Region" );
	}

	// find the ProxyRtiAmbassador class //
	this->jproxyClass = jnienv->FindClass( "org/portico/impl/cpp13/ProxyRtiAmbassador" );
	if( jproxyClass == NULL )
	{
		logger->fatal( "Can't locate: org.portico.impl.cpp13.ProxyRtiAmbassador" );
		exceptionCheck();
		throw HLA::RTIinternalError( "Can't locate: org.portico.impl.cpp13.ProxyRtiAmbassador" );
	}

	// find the method id of the constructor //
	jmethodID constructor;
	constructor = jnienv->GetMethodID( jproxyClass, "<init>", "(I)V" );
	if( constructor == NULL )
	{
		logger->fatal( "Can't locate ProxyRtiAmbassador() constructor ID" );
		exceptionCheck();
		throw HLA::RTIinternalError( "Can't locate ProxyRtiAmbassador() constructor ID" );
	}

	// create the instance of the ambassador //
	logger->debug( "Creating new instance of ProxyRtiAmbassador" );
	jobject localReference = jnienv->NewObject( jproxyClass, constructor, this->id );

	// check for an exception
	// we have to use the plain old JNI method of exception detection as to work, the
	// exception manager requires that the JavaRTI instance be in the Runtime's map of
	// instances, and that won't happen until after the constructor, which this method
	// is a part of (in terms of method flow)
	if( jnienv->ExceptionOccurred() )
	{
		jnienv->ExceptionDescribe();
		jnienv->ExceptionClear();
		throw HLA::RTIinternalError( "Exception during ProxyRtiAmbassador() constructor" );
	}

	// turn the reference into something more persistent (stop it from being garbage collected)
	jproxy = jnienv->NewGlobalRef( localReference );
	if( jproxy == NULL )
	{
		logger->fatal( "Could not instantiate ProxyRtiAmbassador" );
		exceptionCheck();
	}

	// cache the jclass for byte[] //
	BYTE_ARRAY = jnienv->FindClass( "[B" );
	BYTE_ARRAY = (jclass)jnienv->NewGlobalRef( BYTE_ARRAY );

	logger->info( "Initialized new JavaRTI (rti-%d)", this->id );
}