Skip to content

Commit

Permalink
Merge pull request #18169 from tajila/issue2
Browse files Browse the repository at this point in the history
Fix reflect ConstantPool bootstrapping issues
  • Loading branch information
babsingh committed Sep 21, 2023
2 parents 27f0069 + 4b61672 commit 1859981
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
18 changes: 16 additions & 2 deletions runtime/jcl/common/sun_reflect_ConstantPool.c
Expand Up @@ -292,7 +292,7 @@ getFieldAt(JNIEnv *env, jobject constantPoolOop, jint cpIndex, UDATA resolveFlag
if (NULL != constantPoolOop) {
J9RAMConstantRef *ramConstantRef = NULL;
jclass jlClass = NULL;

vmFunctions->internalEnterVMFromJNI(vmThread);
resolveFlags |= (J9_RESOLVE_FLAG_NO_THROW_ON_FAIL | J9_RESOLVE_FLAG_NO_CLASS_INIT | J9_RESOLVE_FLAG_NO_CP_UPDATE);
retry:
Expand Down Expand Up @@ -526,7 +526,7 @@ Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(JNIEnv *env, jobject unusedObj
jobject nameObject = NULL;
jobject signatureObject = NULL;
J9VMThread *vmThread = (J9VMThread *) env;
J9InternalVMFunctions *vmFunctions = vmThread->javaVM->internalVMFunctions;
J9InternalVMFunctions *vmFunctions = vmThread->javaVM->internalVMFunctions;
J9MemoryManagerFunctions *gcFunctions = vmThread->javaVM->memoryManagerFunctions;
SunReflectCPResult result = NULL_POINTER_EXCEPTION;

Expand Down Expand Up @@ -834,6 +834,12 @@ Java_jdk_internal_reflect_ConstantPool_getTagAt0(JNIEnv *env, jobject unusedObje
return 0;
}

void JNICALL
Java_jdk_internal_reflect_ConstantPool_registerNatives(JNIEnv *env, jclass unused)
{
registerJdkInternalReflectConstantPoolNatives(env);
}

/**
* Registers natives for jdk.internal.reflect.ConstantPool.
*
Expand All @@ -842,6 +848,8 @@ Java_jdk_internal_reflect_ConstantPool_getTagAt0(JNIEnv *env, jobject unusedObje
jint
registerJdkInternalReflectConstantPoolNatives(JNIEnv *env) {
jint result = 0;
J9JavaVM *vm = ((J9VMThread *)env)->javaVM;

JNINativeMethod natives[] = {
{
(char*)"getSize0",
Expand Down Expand Up @@ -919,6 +927,12 @@ registerJdkInternalReflectConstantPoolNatives(JNIEnv *env) {
/* jdk.internal.reflect.ConstantPool is currently cached in CLS_sun_reflect_ConstantPool */
jclass jdk_internal_reflect_ConstantPool = JCL_CACHE_GET(env, CLS_sun_reflect_ConstantPool);

/* This is temporary code, will be removed in the future. */
if (J9_ARE_ANY_BITS_SET(vm->extendedRuntimeFlags2, J9_EXTENDED_RUNTIME2_REFLECT_CONSTANTPOOL_REGISTER_NATIVES_CALLED)) {
goto _end;
}
vm->extendedRuntimeFlags2 |= J9_EXTENDED_RUNTIME2_REFLECT_CONSTANTPOOL_REGISTER_NATIVES_CALLED;

if (NULL == jdk_internal_reflect_ConstantPool) {
BOOLEAN rc = initializeSunReflectConstantPoolIDCache(env);

Expand Down
1 change: 1 addition & 0 deletions runtime/jcl/exports.cmake
Expand Up @@ -591,6 +591,7 @@ if(NOT JAVA_SPEC_VERSION LESS 9)
Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefIndexAt0
Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefInfoAt0
Java_jdk_internal_reflect_ConstantPool_getTagAt0
Java_jdk_internal_reflect_ConstantPool_registerNatives
)
endif()

Expand Down
9 changes: 5 additions & 4 deletions runtime/jcl/uma/se9_exports.xml
@@ -1,19 +1,19 @@
<!--
<!--
Copyright IBM Corp. and others 2016
This program and the accompanying materials are made available under
the terms of the Eclipse Public License 2.0 which accompanies this
distribution and is available at https://www.eclipse.org/legal/epl-2.0/
or the Apache License, Version 2.0 which accompanies this distribution and
is available at https://www.apache.org/licenses/LICENSE-2.0.
This Source Code may also be made available under the following
Secondary Licenses when the conditions for such availability set
forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
General Public License, version 2 with the GNU Classpath
Exception [1] and GNU General Public License, version 2 with the
OpenJDK Assembly Exception [2].
[1] https://www.gnu.org/software/classpath/license.html
[2] https://openjdk.org/legal/assembly-exception.html
Expand Down Expand Up @@ -62,6 +62,7 @@
<export name="Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefIndexAt0" />
<export name="Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefInfoAt0" />
<export name="Java_jdk_internal_reflect_ConstantPool_getTagAt0" />
<export name="Java_jdk_internal_reflect_ConstantPool_registerNatives" />
<export name="Java_java_lang_StackWalker_walkWrapperImpl" />
<export name="Java_java_lang_StackWalker_getImpl" />
<export name="Java_java_lang_invoke_MethodHandles_findNativeAddress">
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/j9consts.h
Expand Up @@ -362,6 +362,7 @@ extern "C" {
#define J9_EXTENDED_RUNTIME2_USE_CONTAINER_SUPPORT 0x200000
#define J9_EXTENDED_RUNTIME2_SHOW_CARRIER_FRAMES 0x400000
#define J9_EXTENDED_RUNTIME2_CRIU_SINGLE_THROW_BLOCKING_EXCEPTIONS 0x800000
#define J9_EXTENDED_RUNTIME2_REFLECT_CONSTANTPOOL_REGISTER_NATIVES_CALLED 0x1000000

#define J9_OBJECT_HEADER_AGE_DEFAULT 0xA /* OBJECT_HEADER_AGE_DEFAULT */
#define J9_OBJECT_HEADER_SHAPE_MASK 0xE /* OBJECT_HEADER_SHAPE_MASK */
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/jclprots.h
Expand Up @@ -1092,6 +1092,7 @@ jint JNICALL Java_jdk_internal_reflect_ConstantPool_getClassRefIndexAt0(JNIEnv *
jint JNICALL Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefIndexAt0(JNIEnv *env, jobject unusedObject, jobject constantPoolOop, jint cpIndex);
jobject JNICALL Java_jdk_internal_reflect_ConstantPool_getNameAndTypeRefInfoAt0(JNIEnv *env, jobject unusedObject, jobject constantPoolOop, jint cpIndex);
jbyte JNICALL Java_jdk_internal_reflect_ConstantPool_getTagAt0(JNIEnv *env, jobject unusedObject, jobject constantPoolOop, jint cpIndex);
void JNICALL Java_jdk_internal_reflect_ConstantPool_registerNatives(JNIEnv *env, jclass unused);
jint registerJdkInternalReflectConstantPoolNatives(JNIEnv *env);

/* java_lang_Access.c */
Expand Down

0 comments on commit 1859981

Please sign in to comment.