Skip to content

Commit

Permalink
Merge pull request #4836 from keithc-ca/classname
Browse files Browse the repository at this point in the history
Rename JVM_GetClassName
  • Loading branch information
pshipton authored Feb 23, 2019
2 parents 7d70c48 + 2a104bc commit 14bf9fd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
8 changes: 7 additions & 1 deletion runtime/j9vm/j9vmnatives.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<export name="_JVM_GetClassConstantPool@8" />
<export name="_JVM_GetClassContext@4" />
<export name="_JVM_GetClassLoader@8" />
<export name="_JVM_GetClassName@8" />
<export name="_JVM_GetClassName@8">
<include-if condition="spec.java12 or not spec.java11"/>
<exclude-if condition="spec.java13"/>
</export>
<export name="_JVM_GetClassSignature@8" />
<export name="_JVM_GetEnclosingMethodInfo@8" />
<export name="_JVM_GetInterfaceVersion@0" />
Expand Down Expand Up @@ -329,6 +332,9 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<export name="JVM_GetNestHost"/>
<export name="JVM_GetNestMembers"/>
<export name="JVM_AreNestMates"/>
<export name="JVM_InitClassName">
<exclude-if condition="spec.java12 and not spec.java13"/>
</export>
</exports>

<exports group="jdk12">
Expand Down
27 changes: 24 additions & 3 deletions runtime/j9vm/jvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ static char * newPath = NULL;
J9JavaVM *BFUjavaVM = NULL;

static jclass jlClass = NULL;
static jfieldID classNameFID = NULL;
static jmethodID classDepthMID = NULL;
static jmethodID classLoaderDepthMID = NULL;
static jmethodID currentClassLoaderMID = NULL;
Expand Down Expand Up @@ -1681,7 +1682,12 @@ static jint initializeReflectionGlobals(JNIEnv * env, BOOLEAN includeAccessors)
return JNI_ERR;
}

if (J2SE_SHAPE_RAW != J2SE_SHAPE(vm)) {
if (J2SE_SHAPE_RAW == J2SE_SHAPE(vm)) {
classNameFID = (*env)->GetFieldID(env, clazz, "name", "Ljava/lang/String;");
if (!classNameFID) {
return JNI_ERR;
}
} else {
classDepthMID = (*env)->GetStaticMethodID(env, clazz, "classDepth", "(Ljava/lang/String;)I");
if (!classDepthMID) {
return JNI_ERR;
Expand Down Expand Up @@ -5491,10 +5497,18 @@ JVM_ActiveProcessorCount(void)
J9Class* java_lang_Class_vmRef(JNIEnv* env, jobject clazz);

/**
* JVM_GetClassName
* JVM_GetClassName / JVM_InitClassName
*
* The name was changed from JVM_GetClassName to JVM_InitClassName
* in interface version 6.
*/
jstring JNICALL
JVM_GetClassName(JNIEnv *env, jclass theClass)
#if (JAVA_SPEC_VERSION < 11) || (JAVA_SPEC_VERSION == 12)
JVM_GetClassName
#else /* (JAVA_SPEC_VERSION < 11) || (JAVA_SPEC_VERSION == 12) */
JVM_InitClassName
#endif /* (JAVA_SPEC_VERSION < 11) || (JAVA_SPEC_VERSION == 12) */
(JNIEnv *env, jclass theClass)
{
J9JavaVM* vm = ((J9VMThread*)env)->javaVM;
jstring result;
Expand Down Expand Up @@ -5546,6 +5560,13 @@ JVM_GetClassName(JNIEnv *env, jclass theClass)

result = (*env)->NewStringUTF(env, name);
j9mem_free_memory(name);
#if (JAVA_SPEC_VERSION >= 11) && (JAVA_SPEC_VERSION != 12)
// JVM_InitClassName is expected to also cache the result in the 'name' field
(*env)->SetObjectField(env, theClass, classNameFID, result);
if ((*env)->ExceptionCheck(env)) {
result = NULL;
}
#endif /* (JAVA_SPEC_VERSION >= 11) && (JAVA_SPEC_VERSION != 12) */
return result;
}
}
Expand Down
7 changes: 5 additions & 2 deletions runtime/redirector/forwarders.m4
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ _X(JVM_GetClassAnnotations,JNICALL,true,jbyteArray ,JNIEnv *env, jclass target)
_X(JVM_GetClassConstantPool,JNICALL,true,jobject ,JNIEnv *env, jclass target)
_X(JVM_GetClassContext,JNICALL,true,jobject ,JNIEnv *env)
_X(JVM_GetClassLoader,JNICALL,true,jobject ,JNIEnv *env, jobject obj)
_X(JVM_GetClassName,JNICALL,true,jstring ,JNIEnv *env, jclass theClass)
_X(JVM_GetClassSignature,JNICALL,true,jstring ,JNIEnv *env, jclass target)
_IF([(JAVA_SPEC_VERSION < 11) || (JAVA_SPEC_VERSION == 12)],
[_X(JVM_GetClassName,JNICALL,true,jstring, JNIEnv *env, jclass theClass)])
_IF([(JAVA_SPEC_VERSION == 11) || (JAVA_SPEC_VERSION >= 13)],
[_X(JVM_InitClassName,JNICALL,true,jstring, JNIEnv *env, jclass theClass)])
_X(JVM_GetClassSignature,JNICALL,true,jstring,JNIEnv *env, jclass target)
_X(JVM_GetEnclosingMethodInfo,JNICALL,true,jobjectArray ,JNIEnv *env, jclass theClass)
_X(JVM_GetInterfaceVersion,JNICALL,true,jint ,void)
_X(JVM_GetLastErrorString,JNICALL,true,jint ,char* buffer, jint length)
Expand Down

0 comments on commit 14bf9fd

Please sign in to comment.