Path: blob/master/runtime/jcl/common/compiler.c
6000 views
/*******************************************************************************1* Copyright (c) 1998, 2018 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#include "j9.h"23#include "jcl.h"242526void JNICALL Java_java_lang_Compiler_enable(JNIEnv *env, jclass clazz)27{28#ifdef J9VM_INTERP_NATIVE_SUPPORT29J9VMThread *currentThread = (J9VMThread *) env;30J9JavaVM *vm = currentThread->javaVM;31J9JITConfig * jitConfig = vm->jitConfig;3233if ((jitConfig != NULL) && (jitConfig->enableJit != NULL)) {34#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)35J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;36vmFuncs->internalEnterVMFromJNI(currentThread);37vmFuncs->internalReleaseVMAccess(currentThread);38#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */39jitConfig->enableJit(jitConfig);40}41#endif42}434445void JNICALL Java_java_lang_Compiler_disable(JNIEnv *env, jclass clazz)46{47#ifdef J9VM_INTERP_NATIVE_SUPPORT48J9VMThread *currentThread = (J9VMThread *) env;49J9JavaVM *vm = currentThread->javaVM;50J9JITConfig * jitConfig = vm->jitConfig;5152if ((jitConfig != NULL) && (jitConfig->disableJit != NULL)) {53#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)54J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;55vmFuncs->internalEnterVMFromJNI(currentThread);56vmFuncs->internalReleaseVMAccess(currentThread);57#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */58jitConfig->disableJit(jitConfig);59}60#endif61}626364jobject JNICALL Java_java_lang_Compiler_commandImpl(JNIEnv *env, jclass clazz, jobject cmd)65{66#ifdef J9VM_INTERP_NATIVE_SUPPORT67J9VMThread *currentThread = (J9VMThread *) env;68J9JavaVM *vm = currentThread->javaVM;69J9JITConfig * jitConfig = vm->jitConfig;7071if ((cmd != NULL) && (jitConfig != NULL) && (jitConfig->command != NULL)) {72jclass stringClass = (*env)->FindClass(env, "java/lang/String");7374if (stringClass != NULL) {75jclass intClass = (*env)->FindClass(env, "java/lang/Integer");7677if (intClass != NULL) {78jmethodID mid = (*env)->GetMethodID(env, intClass, "<init>", "(I)V");7980if (mid != NULL) {81if ((*env)->IsInstanceOf(env, cmd, stringClass)) {82const char * commandString = (const char *) (*env)->GetStringUTFChars(env, cmd, NULL);8384if (commandString != NULL) {85I_32 result = 0;86#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)87J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;88vmFuncs->internalEnterVMFromJNI(currentThread);89vmFuncs->internalReleaseVMAccess(currentThread);90#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */91result = jitConfig->command(currentThread, commandString);92(*env)->ReleaseStringUTFChars(env, cmd, commandString);93return (*env)->NewObject(env, intClass, mid, result);94}95}96}97}98}99}100#endif101return NULL;102}103104105jboolean JNICALL Java_java_lang_Compiler_compileClassImpl(JNIEnv *env, jclass clazz, jclass compileClass)106{107jboolean rc = JNI_FALSE;108#ifdef J9VM_INTERP_NATIVE_SUPPORT109J9VMThread *currentThread = (J9VMThread *) env;110J9JavaVM *vm = currentThread->javaVM;111J9JITConfig * jitConfig = vm->jitConfig;112113if ((compileClass != NULL) && (jitConfig != NULL) && (jitConfig->compileClass != NULL)) {114#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)115J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;116vmFuncs->internalEnterVMFromJNI(currentThread);117vmFuncs->internalReleaseVMAccess(currentThread);118#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */119rc = (jboolean)jitConfig->compileClass(currentThread, compileClass);120}121#endif122return rc;123}124125126jboolean JNICALL Java_java_lang_Compiler_compileClassesImpl(JNIEnv *env, jclass clazz, jstring nameRoot)127{128#ifdef J9VM_INTERP_NATIVE_SUPPORT129J9VMThread *currentThread = (J9VMThread *) env;130J9JavaVM *vm = currentThread->javaVM;131J9JITConfig * jitConfig = vm->jitConfig;132133if ((nameRoot != NULL) && (jitConfig != NULL) && (jitConfig->compileClasses != NULL)) {134const char * pattern;135136pattern = (const char *) (*env)->GetStringUTFChars(env, nameRoot, NULL);137if (pattern != NULL) {138jboolean rc;139140#if defined(J9VM_INTERP_ATOMIC_FREE_JNI)141J9InternalVMFunctions *vmFuncs = vm->internalVMFunctions;142vmFuncs->internalEnterVMFromJNI(currentThread);143vmFuncs->internalReleaseVMAccess(currentThread);144#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */145rc = (jboolean) jitConfig->compileClasses(currentThread, pattern);146(*env)->ReleaseStringUTFChars(env, nameRoot, pattern);147return rc;148}149}150#endif151return JNI_FALSE;152}153154155