diff --git a/jcl/src/java.base/share/classes/java/lang/invoke/FilterArgumentsWithCombinerHandle.java b/jcl/src/java.base/share/classes/java/lang/invoke/FilterArgumentsWithCombinerHandle.java deleted file mode 100644 index e92a7eee36d..00000000000 --- a/jcl/src/java.base/share/classes/java/lang/invoke/FilterArgumentsWithCombinerHandle.java +++ /dev/null @@ -1,134 +0,0 @@ -/*[INCLUDE-IF (JAVA_SPEC_VERSION >= 12) & !OPENJDK_METHODHANDLES]*/ -/******************************************************************************* - * Copyright (c) 2018, 2020 IBM Corp. and others - * - * 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 madpe 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] http://openjdk.java.net/legal/assembly-exception.html - * - * 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-exception - *******************************************************************************/ -package java.lang.invoke; - -/*[IF JAVA_SPEC_VERSION >= 15]*/ -import java.util.List; -/*[ENDIF] JAVA_SPEC_VERSION >= 15 */ - -/* - * Pseudocode example: - * handle: D original(A, B, C) - * filterPosition: 1 - * preprocessor: B filter(B, A) - * argumentIndices: {1, 0} - * - * resulting handle: - * D result(A a, B b, C c) { - * B e = filter(b, a) - * return original(a, e, c) - * } - */ -final class FilterArgumentsWithCombinerHandle extends MethodHandle { - protected final MethodHandle next; - protected final MethodHandle combiner; - private final int filterPosition; - private final int[] argumentIndices; - - FilterArgumentsWithCombinerHandle(MethodHandle next, int filterPosition, MethodHandle combiner, int... argumentIndices) { - super(next.type, KIND_FILTERARGUMENTS_WITHCOMBINER, infoAffectingThunks(combiner.type(), filterPosition, argumentIndices)); - this.next = next; - this.combiner = combiner; - this.filterPosition = filterPosition; - this.argumentIndices = argumentIndices; - } - - FilterArgumentsWithCombinerHandle(FilterArgumentsWithCombinerHandle originalHandle, MethodType newType) { - super(originalHandle, newType); - this.next = originalHandle.next; - this.combiner = originalHandle.combiner; - this.filterPosition = originalHandle.filterPosition; - this.argumentIndices = originalHandle.argumentIndices; - } - - static FilterArgumentsWithCombinerHandle get(MethodHandle next, int filterPosition, MethodHandle combiner, int... argumentIndices) { - return new FilterArgumentsWithCombinerHandle(next, filterPosition, combiner, argumentIndices); - } - - @Override - MethodHandle cloneWithNewType(MethodType newType) { - return new FilterArgumentsWithCombinerHandle(this, newType); - } - -/*[IF JAVA_SPEC_VERSION >= 15]*/ - @Override - boolean addRelatedMHs(List relatedMHs) { - relatedMHs.add(next); - relatedMHs.add(combiner); - return true; - } -/*[ENDIF] JAVA_SPEC_VERSION >= 15 */ - - private static Object[] infoAffectingThunks(MethodType combinerType, int filterPosition, int...argumentIndices) { - MethodType thunkableType = ThunkKey.computeThunkableType(combinerType); - Object[] result = {thunkableType, filterPosition, argumentIndices}; - return result; - } - - private static final ThunkTable _thunkTable = new ThunkTable(); - @Override - protected ThunkTable thunkTable(){ return _thunkTable; } - - @Override - protected final ThunkTuple computeThunks(Object info) { - return thunkTable().get(new ThunkKeyWithObjectArray(ThunkKey.computeThunkableType(type()), (Object[])info)); - } - - private static native int filterPosition(); - private static native int argumentIndices(); - /* create placeholder for combiner based on argumentIndices the original handle's arguments */ - private static native int argumentsForCombiner(int indice, int argPlaceholder); - /* number of arguments remaining after the filtered argument */ - private static native int numSuffixArgs(); - - @FrameIteratorSkip - private final int invokeExact_thunkArchetype_X(int argPlaceholder) { - if (ILGenMacros.isShareableThunk()) { - undoCustomizationLogic(combiner, next); - } - if (!ILGenMacros.isCustomThunk()) { - doCustomizationLogic(); - } - - return ILGenMacros.invokeExact_X(next, ILGenMacros.placeholder( - ILGenMacros.firstN(filterPosition(), argPlaceholder), - ILGenMacros.invokeExact(combiner, argumentsForCombiner(argumentIndices(), argPlaceholder)), - ILGenMacros.lastN(numSuffixArgs(), argPlaceholder))); - } - - @Override - final void compareWith(MethodHandle right, Comparator c) { - if (right instanceof FilterArgumentsWithCombinerHandle) { - ((FilterArgumentsWithCombinerHandle)right).compareWithFilterArgumentsWithCombiner(this, c); - } else { - c.fail(); - } - } - - final void compareWithFilterArgumentsWithCombiner(FilterArgumentsWithCombinerHandle left, Comparator c) { - c.compareChildHandle(left.next, this.next); - c.compareChildHandle(left.combiner, this.combiner); - c.compareStructuralParameter(left.filterPosition, this.filterPosition); - c.compareStructuralParameter(left.argumentIndices, this.argumentIndices); - } -} diff --git a/runtime/compiler/env/J9KnownObjectTable.cpp b/runtime/compiler/env/J9KnownObjectTable.cpp index a3374fb309f..5ddb57c9b91 100644 --- a/runtime/compiler/env/J9KnownObjectTable.cpp +++ b/runtime/compiler/env/J9KnownObjectTable.cpp @@ -300,6 +300,7 @@ J9::KnownObjectTable::dumpObjectTo(TR::FILE *file, Index i, const char *fieldNam int32_t offs = simpleNameOffset(className, len); trfprintf(file, "%*s%s%sobj%d @ %p hash %8x %.*s", indent, "", fieldName, sep, i, *ref, hashCode, len-offs, className+offs); +#if defined(J9VM_OPT_METHOD_HANDLE) if (len == 29 && !strncmp("java/lang/invoke/DirectHandle", className, 29)) { J9Method *j9method = (J9Method*)J9VMJAVALANGINVOKEPRIMITIVEHANDLE_VMSLOT(j9fe->vmThread(), (J9Object*)(*ref)); @@ -310,6 +311,7 @@ J9::KnownObjectTable::dumpObjectTo(TR::FILE *file, Index i, const char *fieldNam J9UTF8_LENGTH(className)-offs, utf8Data(className)+offs, J9UTF8_LENGTH(methName), utf8Data(methName)); } +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ TR_VMFieldsInfo *fieldsInfo = fieldsInfoByIndex[i]; if (fieldsInfo) diff --git a/runtime/compiler/env/VMJ9.cpp b/runtime/compiler/env/VMJ9.cpp index 5fe5a72d3b5..74160f17bac 100644 --- a/runtime/compiler/env/VMJ9.cpp +++ b/runtime/compiler/env/VMJ9.cpp @@ -4015,7 +4015,9 @@ TR_J9VMBase::canDereferenceAtCompileTimeWithFieldSymbol(TR::Symbol * fieldSymbol { case TR::Symbol::Java_lang_invoke_PrimitiveHandle_rawModifiers: case TR::Symbol::Java_lang_invoke_PrimitiveHandle_defc: +#if defined(J9VM_OPT_METHOD_HANDLE) case TR::Symbol::Java_lang_invoke_VarHandle_handleTable: +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ case TR::Symbol::Java_lang_invoke_MethodHandleImpl_LoopClauses_clauses: { return true; @@ -5306,7 +5308,13 @@ TR_J9VMBase::getStringFieldByName(TR::Compilation * comp, TR::SymbolReference * TR::Symbol::RecognizedField field = fieldRef->getSymbol()->getRecognizedField(); if (field == TR::Symbol::Java_lang_String_count) + { +#if JAVA_SPEC_VERSION == 8 pResult = (U_8*)string + J9VMJAVALANGSTRING_COUNT_OFFSET(vmThread()); +#else /* JAVA_SPEC_VERSION == 8 */ + return false; +#endif /* JAVA_SPEC_VERSION == 8 */ + } else if (field == TR::Symbol::Java_lang_String_hashCode) { if (J9VMJAVALANGSTRING_HASH(vmThread(), string) == 0) @@ -5511,7 +5519,12 @@ TR_J9VMBase::getStringUTF8(uintptr_t objectPointer, char *buffer, intptr_t buffe uint32_t TR_J9VMBase::getVarHandleHandleTableOffset(TR::Compilation * comp) { +#if defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) return uint32_t(J9VMJAVALANGINVOKEVARHANDLE_HANDLETABLE_OFFSET(vmThread())); +#else /* defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) */ + Assert_JIT_unreachable(); + return 0; +#endif /* defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) */ } // set a 32 bit field that will be printed if the VM crashes diff --git a/runtime/compiler/optimizer/J9ValuePropagation.cpp b/runtime/compiler/optimizer/J9ValuePropagation.cpp index d60dd26596d..15b14dcf720 100644 --- a/runtime/compiler/optimizer/J9ValuePropagation.cpp +++ b/runtime/compiler/optimizer/J9ValuePropagation.cpp @@ -1370,6 +1370,7 @@ J9::ValuePropagation::constrainRecognizedMethod(TR::Node *node) } break; } +#if defined(J9VM_OPT_METHOD_HANDLE) case TR::java_lang_invoke_PrimitiveHandle_initializeClassIfRequired: { TR::Node* mh = node->getArgument(0); @@ -1414,6 +1415,7 @@ J9::ValuePropagation::constrainRecognizedMethod(TR::Node *node) } break; } +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ case TR::java_lang_invoke_DirectHandle_nullCheckIfRequired: { TR::Node* mh = node->getArgument(0); diff --git a/runtime/gc_base/StringTable.cpp b/runtime/gc_base/StringTable.cpp index 690d9728a6d..db2afb63d91 100644 --- a/runtime/gc_base/StringTable.cpp +++ b/runtime/gc_base/StringTable.cpp @@ -32,7 +32,7 @@ #include "StringTable.hpp" #include "VMHelpers.hpp" -/* the following is all ones except the least significant bit */ +/* the following is all zeros except the least significant bit */ #define TYPE_UTF8 ((UDATA)1) extern "C" { @@ -784,17 +784,17 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s if (compressStrings) { if (isASCIIorLatin1) { - if (J2SE_VERSION(vm) >= J2SE_V11) { - J9VMJAVALANGSTRING_SET_CODER(vmThread, result, 0); - } else { - J9VMJAVALANGSTRING_SET_COUNT(vmThread, result, (I_32)unicodeLength); - } +#if JAVA_SPEC_VERSION >= 11 + J9VMJAVALANGSTRING_SET_CODER(vmThread, result, 0); +#else /* JAVA_SPEC_VERSION >= 11 */ + J9VMJAVALANGSTRING_SET_COUNT(vmThread, result, (I_32)unicodeLength); +#endif /* JAVA_SPEC_VERSION >= 11 */ } else { - if (J2SE_VERSION(vm) >= J2SE_V11) { - J9VMJAVALANGSTRING_SET_CODER(vmThread, result, 1); - } else { - J9VMJAVALANGSTRING_SET_COUNT(vmThread, result, (I_32)unicodeLength | (I_32)0x80000000); - } +#if JAVA_SPEC_VERSION >= 11 + J9VMJAVALANGSTRING_SET_CODER(vmThread, result, 1); +#else /* JAVA_SPEC_VERSION >= 11 */ + J9VMJAVALANGSTRING_SET_COUNT(vmThread, result, (I_32)unicodeLength | (I_32)0x80000000); +#endif /* JAVA_SPEC_VERSION >= 11 */ if (J9VMJAVALANGSTRING_COMPRESSIONFLAG(vmThread, stringClass) == 0) { /* @@ -817,11 +817,11 @@ j9gc_createJavaLangString(J9VMThread *vmThread, U_8 *data, UDATA length, UDATA s } } } else { - if (J2SE_VERSION(vm) >= J2SE_V11) { - J9VMJAVALANGSTRING_SET_CODER(vmThread, result, 1); - } else { - J9VMJAVALANGSTRING_SET_COUNT(vmThread, result, (I_32)unicodeLength); - } +#if JAVA_SPEC_VERSION >= 11 + J9VMJAVALANGSTRING_SET_CODER(vmThread, result, 1); +#else /* JAVA_SPEC_VERSION >= 11 */ + J9VMJAVALANGSTRING_SET_COUNT(vmThread, result, (I_32)unicodeLength); +#endif /* JAVA_SPEC_VERSION >= 11 */ } MM_AtomicOperations::writeBarrier(); @@ -905,11 +905,11 @@ setupCharArray(J9VMThread *vmThread, j9object_t sourceString, j9object_t newStri J9VMJAVALANGSTRING_SET_VALUE(vmThread, newString, newChars); - if (J2SE_VERSION(vm) >= J2SE_V11) { - J9VMJAVALANGSTRING_SET_CODER(vmThread, newString, J9VMJAVALANGSTRING_CODER(vmThread, sourceString)); - } else { - J9VMJAVALANGSTRING_SET_COUNT(vmThread, newString, J9VMJAVALANGSTRING_COUNT(vmThread, sourceString)); - } +#if JAVA_SPEC_VERSION >= 11 + J9VMJAVALANGSTRING_SET_CODER(vmThread, newString, J9VMJAVALANGSTRING_CODER(vmThread, sourceString)); +#else /* JAVA_SPEC_VERSION >= 11 */ + J9VMJAVALANGSTRING_SET_COUNT(vmThread, newString, J9VMJAVALANGSTRING_COUNT(vmThread, sourceString)); +#endif /* JAVA_SPEC_VERSION >= 11 */ result = newString; } @@ -917,7 +917,7 @@ setupCharArray(J9VMThread *vmThread, j9object_t sourceString, j9object_t newStri return result; } -j9object_t +j9object_t j9gc_internString(J9VMThread *vmThread, j9object_t sourceString) { J9JavaVM *vm = vmThread->javaVM; diff --git a/runtime/j9vm/java11vmi.c b/runtime/j9vm/java11vmi.c index 44a04d33bb7..eafd55d6a2e 100644 --- a/runtime/j9vm/java11vmi.c +++ b/runtime/j9vm/java11vmi.c @@ -35,6 +35,8 @@ #include "j9vmnls.h" #include "j9version.h" +#if JAVA_SPEC_VERSION >= 11 + #define J9TIME_NANOSECONDS_PER_SECOND ((jlong) 1000000000) /* Need to do a |currentSecondsTime - secondsOffset| < (2^32) check to ensure that the * resulting time fits into a long so it doesn't overflow. This is equivalent to doing @@ -1106,7 +1108,7 @@ trcModulesAddReadsModule(J9VMThread *currentThread, jobject toModule, J9Module * Assert_SC_true(J9VM_PACKAGE_NAME_BUFFER_LENGTH > sizeof(LOOSE_MODULE)); memcpy(toModuleNameBuf, LOOSE_MODULE, sizeof(LOOSE_MODULE)); toModuleNameUTF = toModuleNameBuf; -#undef LOOSE_MODULE +#undef LOOSE_MODULE } if ((NULL != fromModuleNameUTF) && (NULL != toModuleNameUTF)) { Trc_MODULE_addReadsModule(currentThread, fromModuleNameUTF, j9FromMod, toModuleNameUTF, toModule); @@ -1306,7 +1308,6 @@ JVM_AddModuleExportsToAllUnnamed(JNIEnv * env, jobject fromModule, const char *p f_monitorEnter(vm->classLoaderModuleAndLocationMutex); #endif /* defined(CALL_BUNDLED_FUNCTIONS_DIRECTLY) */ - #if JAVA_SPEC_VERSION >= 15 if (NULL != packageObj) { j9object_t stringObject = J9_JNI_UNWRAP_REFERENCE(packageObj); @@ -1349,40 +1350,45 @@ JVM_AddModuleExportsToAllUnnamed(JNIEnv * env, jobject fromModule, const char *p f_monitorExit(vm->classLoaderModuleAndLocationMutex); #endif /* defined(CALL_BUNDLED_FUNCTIONS_DIRECTLY) */ vmFuncs->internalExitVMToJNI(currentThread); - } jstring JNICALL -JVM_GetSimpleBinaryName(JNIEnv *env, jclass arg1) { +JVM_GetSimpleBinaryName(JNIEnv *env, jclass arg1) +{ assert(!"JVM_GetSimpleBinaryName unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ return NULL; } void JNICALL -JVM_SetMethodInfo(JNIEnv *env, jobject arg1) { +JVM_SetMethodInfo(JNIEnv *env, jobject arg1) +{ assert(!"JVM_SetMethodInfo unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ } jint JNICALL -JVM_ConstantPoolGetNameAndTypeRefIndexAt(JNIEnv *env, jobject arg1, jobject arg2, jint arg3) { +JVM_ConstantPoolGetNameAndTypeRefIndexAt(JNIEnv *env, jobject arg1, jobject arg2, jint arg3) +{ assert(!"JVM_ConstantPoolGetNameAndTypeRefIndexAt unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ - return -1; + return -1; } jint JNICALL -JVM_MoreStackWalk(JNIEnv *env, jobject arg1, jlong arg2, jlong arg3, jint arg4, jint arg5, jobjectArray arg6, jobjectArray arg7) { +JVM_MoreStackWalk(JNIEnv *env, jobject arg1, jlong arg2, jlong arg3, jint arg4, jint arg5, jobjectArray arg6, jobjectArray arg7) +{ assert(!"JVM_MoreStackWalk unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ - return -1; + return -1; } jint JNICALL -JVM_ConstantPoolGetClassRefIndexAt(JNIEnv *env, jobject arg1, jlong arg2, jint arg3) { +JVM_ConstantPoolGetClassRefIndexAt(JNIEnv *env, jobject arg1, jlong arg2, jint arg3) +{ assert(!"JVM_ConstantPoolGetClassRefIndexAt unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ - return -1; + return -1; } jobjectArray JNICALL -JVM_GetVmArguments(JNIEnv *env) { +JVM_GetVmArguments(JNIEnv *env) +{ J9VMThread* currentThread = (J9VMThread*)env; J9JavaVM* vm = currentThread->javaVM; J9InternalVMFunctions* internalFunctions = vm->internalVMFunctions; @@ -1414,7 +1420,6 @@ JVM_GetVmArguments(JNIEnv *env) { } } } - } /* if code reaches here, something went wrong */ internalFunctions->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGINTERNALERROR, NULL); @@ -1425,46 +1430,56 @@ JVM_GetVmArguments(JNIEnv *env) { } void JNICALL -JVM_FillStackFrames(JNIEnv *env, jclass arg1, jint arg2, jobjectArray arg3, jint arg4, jint arg5) { +JVM_FillStackFrames(JNIEnv *env, jclass arg1, jint arg2, jobjectArray arg3, jint arg4, jint arg5) +{ assert(!"JVM_FillStackFrames unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ } jclass JNICALL -JVM_FindClassFromCaller(JNIEnv* env, const char* arg1, jboolean arg2, jobject arg3, jclass arg4) { +JVM_FindClassFromCaller(JNIEnv* env, const char* arg1, jboolean arg2, jobject arg3, jclass arg4) +{ assert(!"JVM_FindClassFromCaller unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ - return NULL; + return NULL; } jobjectArray JNICALL -JVM_ConstantPoolGetNameAndTypeRefInfoAt(JNIEnv *env, jobject arg1, jobject arg2, jint arg3) { - assert(!"JVM_ConstantPoolGetNameAndTypeRefInfoAt unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ - return NULL; +JVM_ConstantPoolGetNameAndTypeRefInfoAt(JNIEnv *env, jobject arg1, jobject arg2, jint arg3) +{ + assert(!"JVM_ConstantPoolGetNameAndTypeRefInfoAt unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ + return NULL; } jbyte JNICALL -JVM_ConstantPoolGetTagAt(JNIEnv *env, jobject arg1, jobject arg2, jint arg3) { - assert(!"JVM_ConstantPoolGetTagAt unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ - return 0; +JVM_ConstantPoolGetTagAt(JNIEnv *env, jobject arg1, jobject arg2, jint arg3) +{ + assert(!"JVM_ConstantPoolGetTagAt unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ + return 0; } jobject JNICALL -JVM_CallStackWalk(JNIEnv *env, jobject arg1, jlong arg2, jint arg3, jint arg4, jint arg5, jobjectArray arg6, jobjectArray arg7) { - assert(!"JVM_CallStackWalk unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ - return NULL; +JVM_CallStackWalk(JNIEnv *env, jobject arg1, jlong arg2, jint arg3, jint arg4, jint arg5, jobjectArray arg6, jobjectArray arg7) +{ + assert(!"JVM_CallStackWalk unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ + return NULL; } JNIEXPORT jobject JNICALL -JVM_GetAndClearReferencePendingList(JNIEnv *env) { +JVM_GetAndClearReferencePendingList(JNIEnv *env) +{ assert(!"JVM_GetAndClearReferencePendingList unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ return NULL; } + JNIEXPORT jboolean JNICALL -JVM_HasReferencePendingList(JNIEnv *env) { +JVM_HasReferencePendingList(JNIEnv *env) +{ assert(!"JVM_HasReferencePendingList unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ return JNI_FALSE; } + JNIEXPORT void JNICALL -JVM_WaitForReferencePendingList(JNIEnv *env) { +JVM_WaitForReferencePendingList(JNIEnv *env) +{ assert(!"JVM_WaitForReferencePendingList unimplemented"); /* Jazz 108925: Revive J9JCL raw pConfig build */ return; } @@ -1482,7 +1497,8 @@ JVM_WaitForReferencePendingList(JNIEnv *env) { * @throws NullPointerException if module is NULL */ void JNICALL -JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module) { +JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module) +{ J9VMThread * const currentThread = (J9VMThread*)env; J9JavaVM * vm = currentThread->javaVM; J9InternalVMFunctions const * const vmFuncs = vm->internalVMFunctions; @@ -1521,27 +1537,26 @@ JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module) { void JNICALL JVM_ToStackTraceElement(JNIEnv* env, jobject arg1, jobject arg2) { - assert(!"JVM_ToStackTraceElement unimplemented"); + assert(!"JVM_ToStackTraceElement unimplemented"); } void JNICALL JVM_GetStackTraceElements(JNIEnv *env, jobject throwable, jobjectArray elements) { - assert(!"JVM_GetStackTraceElements unimplemented"); + assert(!"JVM_GetStackTraceElements unimplemented"); } void JNICALL JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject throwable) { - assert(!"JVM_InitStackTraceElementArray unimplemented"); + assert(!"JVM_InitStackTraceElementArray unimplemented"); } - void JNICALL +void JNICALL JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo) - { - assert(!"JVM_InitStackTraceElement unimplemented"); - } - +{ + assert(!"JVM_InitStackTraceElement unimplemented"); +} /* JVM_GetModuleByPackageName is to be deleted for b156 */ /** @@ -1640,7 +1655,6 @@ JVM_GetModuleByPackageName(JNIEnv *env, jobject classLoader, jstring packageName return module; } - /** * Return the clock time in nanoseconds at given offset * @@ -1677,7 +1691,6 @@ JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass clazz, jlong offsetSeconds) return result; } -#if JAVA_SPEC_VERSION >= 11 JNIEXPORT jclass JNICALL JVM_GetNestHost(JNIEnv *env, jclass clz) { @@ -1773,6 +1786,7 @@ JVM_IsCDSDumpingEnabled(JNIEnv *env) #endif /* JAVA_SPEC_VERSION >= 15 */ #if JAVA_SPEC_VERSION >= 16 + JNIEXPORT jlong JNICALL JVM_GetRandomSeedForDumping() { @@ -1786,7 +1800,8 @@ JVM_IsSharingEnabled(JNIEnv *env) /* OpenJ9 does not support CDS, so we return false unconditionally. */ return JNI_FALSE; } -#endif /* JAVA_SPEC_VERSION == 15 */ + +#endif /* JAVA_SPEC_VERSION >= 16 */ JNIEXPORT jboolean JNICALL JVM_IsUseContainerSupport(JNIEnv *env) diff --git a/runtime/jcl/CMakeLists.txt b/runtime/jcl/CMakeLists.txt index ace6d7c71f7..f8ab9ff4788 100644 --- a/runtime/jcl/CMakeLists.txt +++ b/runtime/jcl/CMakeLists.txt @@ -73,7 +73,11 @@ add_custom_command( -cmakeCache "${CMAKE_CURRENT_BINARY_DIR}/parsed_cache.txt" -version ${JAVA_SPEC_VERSION} VERBATIM - DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/parsed_cache.txt" j9vmcp objectmodel + DEPENDS + ${j9vm_SOURCE_DIR}/oti/vmconstantpool.xml + "${CMAKE_CURRENT_BINARY_DIR}/parsed_cache.txt" + j9vmcp + objectmodel ) add_custom_target(run_cptool DEPENDS ${gen_constpool_files} diff --git a/runtime/jcl/common/java_lang_Class.cpp b/runtime/jcl/common/java_lang_Class.cpp index 897e8aa7ac8..6697807e6fd 100644 --- a/runtime/jcl/common/java_lang_Class.cpp +++ b/runtime/jcl/common/java_lang_Class.cpp @@ -1181,11 +1181,13 @@ skip: ; return result; } +#if JAVA_SPEC_VERSION >= 14 jarray JNICALL Java_java_lang_Class_getRecordComponentsImpl(JNIEnv *env, jobject cls) { return getRecordComponentsHelper(env, cls); } +#endif /* JAVA_SPEC_VERSION >= 14 */ jarray JNICALL Java_java_lang_Class_permittedSubclassesImpl(JNIEnv *env, jobject cls) diff --git a/runtime/jcl/common/java_lang_invoke_VarHandle.c b/runtime/jcl/common/java_lang_invoke_VarHandle.c index e4d67ea63c8..6f296ba596c 100644 --- a/runtime/jcl/common/java_lang_invoke_VarHandle.c +++ b/runtime/jcl/common/java_lang_invoke_VarHandle.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2020 IBM Corp. and others + * Copyright (c) 2016, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -39,7 +39,7 @@ #include "j9vmconstantpool.h" #include "j9jclnls.h" -#if defined(J9VM_OPT_METHOD_HANDLE) +#if defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) static BOOLEAN accessCheckFieldType(J9VMThread *currentThread, J9Class* lookupClass, J9Class* type, J9UTF8 *lookupSig) { @@ -163,7 +163,7 @@ Java_java_lang_invoke_FieldVarHandle_unreflectField(JNIEnv *env, jobject handle, vmFuncs->internalExitVMToJNI(vmThread); return fieldOffset; } -#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ +#endif /* defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) */ jobject JNICALL Java_java_lang_invoke_VarHandle_get(JNIEnv *env, jobject handle, jobject args) diff --git a/runtime/jcl/common/jclexception.cpp b/runtime/jcl/common/jclexception.cpp index a2dc3293500..51019fb0388 100644 --- a/runtime/jcl/common/jclexception.cpp +++ b/runtime/jcl/common/jclexception.cpp @@ -147,52 +147,50 @@ getStackTraceIterator(J9VMThread * vmThread, void * voidUserData, UDATA bytecode } /* Fill in module name and version */ - if (JAVA_SPEC_VERSION >= 11) { - if (NULL != classLoader) { - j9object_t classLoaderName = J9VMJAVALANGCLASSLOADER_CLASSLOADERNAME(vmThread, classLoader->classLoaderObject); - J9VMJAVALANGSTACKTRACEELEMENT_SET_CLASSLOADERNAME(vmThread, element, classLoaderName); +#if JAVA_SPEC_VERSION >= 11 + if (NULL != classLoader) { + j9object_t classLoaderName = J9VMJAVALANGCLASSLOADER_CLASSLOADERNAME(vmThread, classLoader->classLoaderObject); + J9VMJAVALANGSTACKTRACEELEMENT_SET_CLASSLOADERNAME(vmThread, element, classLoaderName); + } + if (J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED)) { + string = mmfns->j9gc_createJavaLangString(vmThread, (U_8 *)JAVA_BASE_MODULE, LITERAL_STRLEN(JAVA_BASE_MODULE), J9_STR_XLAT | J9_STR_TENURE); + if (NULL == string) { + rc = FALSE; + /* exception is pending from the call */ + goto done; } - if (J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED)) { - string = mmfns->j9gc_createJavaLangString(vmThread, (U_8 *)JAVA_BASE_MODULE, LITERAL_STRLEN(JAVA_BASE_MODULE), J9_STR_XLAT | J9_STR_TENURE); - if (NULL == string) { - rc = FALSE; - /* exception is pending from the call */ - goto done; - } - element = PEEK_OBJECT_IN_SPECIAL_FRAME(vmThread, 0); - J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULENAME(vmThread, element, string); + element = PEEK_OBJECT_IN_SPECIAL_FRAME(vmThread, 0); + J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULENAME(vmThread, element, string); - string = mmfns->j9gc_createJavaLangString(vmThread, (U_8 *)JAVA_SPEC_VERSION_STRING, LITERAL_STRLEN(JAVA_SPEC_VERSION_STRING), J9_STR_XLAT | J9_STR_TENURE); - if (NULL == string) { - rc = FALSE; - /* exception is pending from the call */ - goto done; - } - element = PEEK_OBJECT_IN_SPECIAL_FRAME(vmThread, 0); - J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULEVERSION(vmThread, element, string); + string = mmfns->j9gc_createJavaLangString(vmThread, (U_8 *)JAVA_SPEC_VERSION_STRING, LITERAL_STRLEN(JAVA_SPEC_VERSION_STRING), J9_STR_XLAT | J9_STR_TENURE); + if (NULL == string) { + rc = FALSE; + /* exception is pending from the call */ + goto done; + } + element = PEEK_OBJECT_IN_SPECIAL_FRAME(vmThread, 0); + J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULEVERSION(vmThread, element, string); + } else { + /* Fetch the J9Module from the j.l.Class->j.l.Module field if we have a class. + * Otherwise the more painful package-based lookup must be performed + */ + J9Module *module = NULL; + if (NULL != ramClass) { + j9object_t moduleObject = J9VMJAVALANGCLASS_MODULE(vmThread, ramClass->classObject); + module = (J9Module*)J9OBJECT_ADDRESS_LOAD(vmThread, moduleObject, vm->modulePointerOffset); } else { - /* Fetch the J9Module from the j.l.Class->j.l.Module field if we have a class. - * Otherwise the more painful package-based lookup must be performed - */ - J9Module *module = NULL; - if (NULL != ramClass) { - j9object_t moduleObject = J9VMJAVALANGCLASS_MODULE(vmThread, ramClass->classObject); - module = (J9Module*)J9OBJECT_ADDRESS_LOAD(vmThread, moduleObject, vm->modulePointerOffset); - } else { - UDATA length = packageNameLength(romClass); - omrthread_monitor_enter(vm->classLoaderModuleAndLocationMutex); - module = vmFuncs->findModuleForPackage(vmThread, classLoader, J9UTF8_DATA(utfClassName), (U_32) length); - omrthread_monitor_exit(vm->classLoaderModuleAndLocationMutex); - } - if (NULL != module) { - J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULENAME(vmThread, element, module->moduleName); - J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULEVERSION(vmThread, element, module->version); - } + UDATA length = packageNameLength(romClass); + omrthread_monitor_enter(vm->classLoaderModuleAndLocationMutex); + module = vmFuncs->findModuleForPackage(vmThread, classLoader, J9UTF8_DATA(utfClassName), (U_32) length); + omrthread_monitor_exit(vm->classLoaderModuleAndLocationMutex); + } + if (NULL != module) { + J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULENAME(vmThread, element, module->moduleName); + J9VMJAVALANGSTACKTRACEELEMENT_SET_MODULEVERSION(vmThread, element, module->version); } -#if JAVA_SPEC_VERSION >= 11 - setStackTraceElementFields(vmThread, element, classLoader); -#endif /* JAVA_SPEC_VERSION >= 11 */ } + setStackTraceElementFields(vmThread, element, classLoader); +#endif /* JAVA_SPEC_VERSION >= 11 */ if (NULL != ramClass) { /* Fill in method class */ diff --git a/runtime/jcl/common/reflecthelp.c b/runtime/jcl/common/reflecthelp.c index 021264a4257..a01bb415605 100644 --- a/runtime/jcl/common/reflecthelp.c +++ b/runtime/jcl/common/reflecthelp.c @@ -1746,6 +1746,7 @@ getFieldsHelper(JNIEnv *env, jobject cls) return result; } +#if JAVA_SPEC_VERSION >= 14 /* Determine whether currentMethod is the accessor method for a record component with name componentName. * an accessor method will have the same name as the component and take zero parameters. */ @@ -1883,8 +1884,8 @@ getRecordComponentsHelper(JNIEnv *env, jobject cls) nameUTF = J9ROMRECORDCOMPONENTSHAPE_NAME(recordComponent); nameString = mmFuncs->j9gc_createJavaLangStringWithUTFCache(vmThread, nameUTF); if (NULL == nameString) { - DROP_OBJECT_IN_SPECIAL_FRAME(vmThread); /* recordComponentObject */ - goto heapoutofmemory; + DROP_OBJECT_IN_SPECIAL_FRAME(vmThread); /* recordComponentObject */ + goto heapoutofmemory; } recordComponentObject = PEEK_OBJECT_IN_SPECIAL_FRAME(vmThread, 0); J9VMJAVALANGREFLECTRECORDCOMPONENT_SET_NAME(vmThread, recordComponentObject, nameString); @@ -1976,6 +1977,7 @@ getRecordComponentsHelper(JNIEnv *env, jobject cls) vmFuncs->internalExitVMToJNI(vmThread); return result; } +#endif /* JAVA_SPEC_VERSION >= 14 */ /* Create an array of string names for class's PermittedSubclasses */ jarray diff --git a/runtime/jcl/exports.cmake b/runtime/jcl/exports.cmake index 768d5b4d1a9..284fbb90a0b 100644 --- a/runtime/jcl/exports.cmake +++ b/runtime/jcl/exports.cmake @@ -335,7 +335,6 @@ omr_add_exports(jclse Java_java_lang_Class_isClassADeclaredClass Java_java_lang_Class_isClassAnEnclosedClass Java_java_lang_Class_isCircularDeclaringClass - Java_java_lang_Class_getRecordComponentsImpl Java_java_lang_Class_permittedSubclassesImpl Java_java_lang_Compiler_commandImpl Java_java_lang_Compiler_compileClassImpl @@ -595,6 +594,7 @@ endif() # java 15+ if(NOT JAVA_SPEC_VERSION LESS 15) omr_add_exports(jclse + Java_java_lang_Class_getRecordComponentsImpl Java_java_lang_Class_isHiddenImpl Java_java_lang_ClassLoader_defineClassImpl1 ) diff --git a/runtime/jcl/jcl_internal.h b/runtime/jcl/jcl_internal.h index 3108130e5c3..13f155eb1d2 100644 --- a/runtime/jcl/jcl_internal.h +++ b/runtime/jcl/jcl_internal.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2001, 2020 IBM Corp. and others + * Copyright (c) 2001, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -130,6 +130,7 @@ getFieldsHelper(JNIEnv *env, jobject cls); J9Class * fetchArrayClass(struct J9VMThread *vmThread, J9Class *elementTypeClass); +#if JAVA_SPEC_VERSION >= 14 /** * Build an array of java.lang.reflect.RecordComponent for the record components of a record class * @@ -142,6 +143,7 @@ fetchArrayClass(struct J9VMThread *vmThread, J9Class *elementTypeClass); */ jarray getRecordComponentsHelper(JNIEnv *env, jobject cls); +#endif /* JAVA_SPEC_VERSION >= 14 */ /** * Build an array of java.lang.String to return names of all permitted subclasses diff --git a/runtime/jvmti/jvmtiModules.c b/runtime/jvmti/jvmtiModules.c index 96756efa477..35655199baf 100644 --- a/runtime/jvmti/jvmtiModules.c +++ b/runtime/jvmti/jvmtiModules.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016, 2020 IBM Corp. and others + * Copyright (c) 2016, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -24,12 +24,15 @@ #include "j9cp.h" #include "j2sever.h" +#if JAVA_SPEC_VERSION >= 11 + #define JVMTI_PACKAGE_NAME_BUFFER_LENGTH 80 static void -charReplace(J9UTF8 * utf8, char oldChar, char newChar) { +charReplace(J9UTF8 * utf8, char oldChar, char newChar) +{ IDATA i = 0; - for (;i < J9UTF8_LENGTH(utf8); i++) { + for (; i < J9UTF8_LENGTH(utf8); i++) { if (oldChar == J9UTF8_DATA(utf8)[i]) { J9UTF8_DATA(utf8)[i] = newChar; } @@ -665,3 +668,5 @@ jvmtiIsModifiableModule(jvmtiEnv* env, } return rc; } + +#endif /* JAVA_SPEC_VERSION >= 11 */ diff --git a/runtime/oti/VMHelpers.hpp b/runtime/oti/VMHelpers.hpp index d8f48dada42..71d1947ef06 100644 --- a/runtime/oti/VMHelpers.hpp +++ b/runtime/oti/VMHelpers.hpp @@ -343,11 +343,13 @@ class VM_VMHelpers methodHandleCompiledEntryPoint(J9JavaVM *vm, J9VMThread *currentThread, j9object_t methodHandle) { void *compiledEntryPoint = NULL; +#if defined(J9VM_OPT_METHOD_HANDLE) if (J9_EXTENDED_RUNTIME_I2J_MH_TRANSITION_ENABLED == (vm->extendedRuntimeFlags & J9_EXTENDED_RUNTIME_I2J_MH_TRANSITION_ENABLED)) { j9object_t thunks = J9VMJAVALANGINVOKEMETHODHANDLE_THUNKS(currentThread, methodHandle); I_64 i2jEntry = J9VMJAVALANGINVOKETHUNKTUPLE_I2JINVOKEEXACTTHUNK(currentThread, thunks); compiledEntryPoint = (void *)(UDATA)i2jEntry; } +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ return compiledEntryPoint; } @@ -1818,6 +1820,7 @@ class VM_VMHelpers isLambdaFormGeneratedMethod(J9VMThread const *currentThread, J9Method *method) { bool result = false; +#if defined(J9VM_OPT_OPENJDK_METHODHANDLE) J9Class *methodClass = J9_CLASS_FROM_METHOD(method); if (J9_ARE_ANY_BITS_SET(methodClass->classFlags, J9ClassIsAnonymous) || J9ROMCLASS_IS_HIDDEN(methodClass->romClass)) { J9Class *lambdaFormClass = J9VMJAVALANGINVOKELAMBDAFORM_OR_NULL(currentThread->javaVM); @@ -1825,6 +1828,7 @@ class VM_VMHelpers result = true; } } +#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ return result; } diff --git a/runtime/oti/VM_MethodHandleKinds.h b/runtime/oti/VM_MethodHandleKinds.h index 6e5eb088208..7f1ea14cc95 100644 --- a/runtime/oti/VM_MethodHandleKinds.h +++ b/runtime/oti/VM_MethodHandleKinds.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2019 IBM Corp. and others + * Copyright (c) 1991, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -58,6 +58,5 @@ #ifdef J9VM_OPT_PANAMA #define J9_METHOD_HANDLE_KIND_NATIVE 0x20 #endif -#define J9_METHOD_HANDLE_KIND_FILTER_ARGUMENTS_WITH_COMBINER 0x21 #endif /* VM_METHODHANDLEKINDS_H_ */ diff --git a/runtime/oti/j9.h b/runtime/oti/j9.h index f13eb4fca51..7077caeab4a 100644 --- a/runtime/oti/j9.h +++ b/runtime/oti/j9.h @@ -130,37 +130,52 @@ typedef struct J9ClassLoaderWalkState { #define IS_STRING_COMPRESSION_ENABLED_VM(javaVM) (FALSE != (javaVM)->strCompEnabled) +#if JAVA_SPEC_VERSION >= 11 + +#define IS_STRING_COMPRESSED(vmThread, object) \ + (IS_STRING_COMPRESSION_ENABLED(vmThread) ? \ + (((I_32) J9VMJAVALANGSTRING_CODER(vmThread, object)) == 0) : \ + FALSE) + +#define IS_STRING_COMPRESSED_VM(javaVM, object) \ + (IS_STRING_COMPRESSION_ENABLED_VM(javaVM) ? \ + (((I_32) J9VMJAVALANGSTRING_CODER_VM(javaVM, object)) == 0) : \ + FALSE) + +#define J9VMJAVALANGSTRING_LENGTH(vmThread, object) \ + (IS_STRING_COMPRESSION_ENABLED(vmThread) ? \ + (J9INDEXABLEOBJECT_SIZE(vmThread, J9VMJAVALANGSTRING_VALUE(vmThread, object)) >> ((I_32) J9VMJAVALANGSTRING_CODER(vmThread, object))) : \ + (J9INDEXABLEOBJECT_SIZE(vmThread, J9VMJAVALANGSTRING_VALUE(vmThread, object)) >> 1)) + +#define J9VMJAVALANGSTRING_LENGTH_VM(javaVM, object) \ + (IS_STRING_COMPRESSION_ENABLED_VM(javaVM) ? \ + (J9INDEXABLEOBJECT_SIZE_VM(javaVM, J9VMJAVALANGSTRING_VALUE_VM(javaVM, object)) >> ((I_32) J9VMJAVALANGSTRING_CODER_VM(javaVM, object))) : \ + (J9INDEXABLEOBJECT_SIZE_VM(javaVM, J9VMJAVALANGSTRING_VALUE_VM(javaVM, object)) >> 1)) + +#else /* JAVA_SPEC_VERSION >= 11 */ + #define IS_STRING_COMPRESSED(vmThread, object) \ (IS_STRING_COMPRESSION_ENABLED(vmThread) ? \ - (J2SE_VERSION((vmThread)->javaVM) >= J2SE_V11 ? \ - (((I_32) J9VMJAVALANGSTRING_CODER(vmThread, object)) == 0) : \ - (((I_32) J9VMJAVALANGSTRING_COUNT(vmThread, object)) >= 0)) : \ + (((I_32) J9VMJAVALANGSTRING_COUNT(vmThread, object)) >= 0) : \ FALSE) #define IS_STRING_COMPRESSED_VM(javaVM, object) \ (IS_STRING_COMPRESSION_ENABLED_VM(javaVM) ? \ - (J2SE_VERSION(javaVM) >= J2SE_V11 ? \ - (((I_32) J9VMJAVALANGSTRING_CODER_VM(javaVM, object)) == 0) : \ - (((I_32) J9VMJAVALANGSTRING_COUNT_VM(javaVM, object)) >= 0)) : \ + (((I_32) J9VMJAVALANGSTRING_COUNT_VM(javaVM, object)) >= 0) : \ FALSE) #define J9VMJAVALANGSTRING_LENGTH(vmThread, object) \ (IS_STRING_COMPRESSION_ENABLED(vmThread) ? \ - (J2SE_VERSION((vmThread)->javaVM) >= J2SE_V11 ? \ - (J9INDEXABLEOBJECT_SIZE(vmThread, J9VMJAVALANGSTRING_VALUE(vmThread, object)) >> ((I_32) J9VMJAVALANGSTRING_CODER(vmThread, object))) : \ - (J9VMJAVALANGSTRING_COUNT(vmThread, object) & 0x7FFFFFFF)) : \ - (J2SE_VERSION((vmThread)->javaVM) >= J2SE_V11 ? \ - (J9INDEXABLEOBJECT_SIZE(vmThread, J9VMJAVALANGSTRING_VALUE(vmThread, object)) >> 1) : \ - (J9VMJAVALANGSTRING_COUNT(vmThread, object)))) + (J9VMJAVALANGSTRING_COUNT(vmThread, object) & 0x7FFFFFFF) : \ + (J9VMJAVALANGSTRING_COUNT(vmThread, object))) #define J9VMJAVALANGSTRING_LENGTH_VM(javaVM, object) \ (IS_STRING_COMPRESSION_ENABLED_VM(javaVM) ? \ - (J2SE_VERSION(javaVM) >= J2SE_V11 ? \ - (J9INDEXABLEOBJECT_SIZE_VM(javaVM, J9VMJAVALANGSTRING_VALUE_VM(javaVM, object)) >> ((I_32) J9VMJAVALANGSTRING_CODER_VM(javaVM, object))) : \ - (J9VMJAVALANGSTRING_COUNT_VM(javaVM, object) & 0x7FFFFFFF)) : \ - (J2SE_VERSION(javaVM) >= J2SE_V11 ? \ - (J9INDEXABLEOBJECT_SIZE_VM(javaVM, J9VMJAVALANGSTRING_VALUE_VM(javaVM, object)) >> 1) : \ - (J9VMJAVALANGSTRING_COUNT_VM(javaVM, object)))) + (J9VMJAVALANGSTRING_COUNT_VM(javaVM, object) & 0x7FFFFFFF) : \ + (J9VMJAVALANGSTRING_COUNT_VM(javaVM, object))) + +#endif /* JAVA_SPEC_VERSION >= 11 */ + /* UTF8 access macros - all access to J9UTF8 fields should be done through these macros */ diff --git a/runtime/oti/j9nonbuilder.h b/runtime/oti/j9nonbuilder.h index 0f84be407cd..3ddea8cf287 100644 --- a/runtime/oti/j9nonbuilder.h +++ b/runtime/oti/j9nonbuilder.h @@ -4713,7 +4713,9 @@ typedef struct J9InternalVMFunctions { j9object_t ( *resolveConstantDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) ; j9object_t ( *resolveInvokeDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) ; void (JNICALL *sendResolveOpenJDKInvokeHandle)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, I_32 refKind, J9Class *resolvedClass, J9ROMNameAndSignature* nameAndSig) ; +#if JAVA_SPEC_VERSION >= 11 void (JNICALL *sendResolveConstantDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData) ; +#endif /* JAVA_SPEC_VERSION >= 11 */ void (JNICALL *sendResolveInvokeDynamic)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA callSiteIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData) ; j9object_t ( *resolveMethodHandleRef)(struct J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) ; UDATA ( *resolveNativeAddress)(struct J9VMThread *currentThread, J9Method *nativeMethod, UDATA runtimeBind) ; @@ -4738,7 +4740,9 @@ typedef struct J9InternalVMFunctions { omrthread_monitor_t ( *getMonitorForWait)(struct J9VMThread* vmThread, j9object_t object) ; void ( *jvmPhaseChange)(struct J9JavaVM* vm, UDATA phase) ; void ( *prepareClass)(struct J9VMThread *currentThread, struct J9Class *clazz) ; +#if defined(J9VM_OPT_METHOD_HANDLE) struct J9SFMethodTypeFrame* ( *buildMethodTypeFrame)(struct J9VMThread *currentThread, j9object_t methodType) ; +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ void ( *fatalRecursiveStackOverflow)(struct J9VMThread *currentThread) ; void ( *setIllegalAccessErrorNonPublicInvokeInterface)(struct J9VMThread *currentThread, J9Method *method) ; IDATA ( *createThreadWithCategory)(omrthread_t* handle, UDATA stacksize, UDATA priority, UDATA suspend, omrthread_entrypoint_t entrypoint, void* entryarg, U_32 category) ; diff --git a/runtime/oti/j9protos.h b/runtime/oti/j9protos.h index f0c5179805d..e6483b6e330 100644 --- a/runtime/oti/j9protos.h +++ b/runtime/oti/j9protos.h @@ -1356,7 +1356,9 @@ extern J9_CFUNC void JNICALL sendFromMethodDescriptorString (J9VMThread *vmThre extern J9_CFUNC void JNICALL sendResolveMethodHandle (J9VMThread *vmThread, UDATA cpIndex, J9ConstantPool *ramCP, J9Class *definingClass, J9ROMNameAndSignature* nameAndSig); extern J9_CFUNC void JNICALL sendForGenericInvoke (J9VMThread *vmThread, j9object_t methodHandle, j9object_t methodType, UDATA dropFirstArg); extern J9_CFUNC void JNICALL sendResolveOpenJDKInvokeHandle (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, I_32 refKind, J9Class *resolvedClass, J9ROMNameAndSignature* nameAndSig); +#if JAVA_SPEC_VERSION >= 11 extern J9_CFUNC void JNICALL sendResolveConstantDynamic (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData); +#endif /* JAVA_SPEC_VERSION >= 11 */ extern J9_CFUNC void JNICALL sendResolveInvokeDynamic (J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA callSiteIndex, J9ROMNameAndSignature* nameAndSig, U_16* bsmData); extern J9_CFUNC void JNICALL jitFillOSRBuffer (struct J9VMThread *vmContext, void *osrBlock); extern J9_CFUNC void JNICALL sendRunThread(J9VMThread *vmContext, j9object_t tenantContext); diff --git a/runtime/oti/util_api.h b/runtime/oti/util_api.h index 9edbe71cb73..1888bc4eced 100644 --- a/runtime/oti/util_api.h +++ b/runtime/oti/util_api.h @@ -2711,6 +2711,9 @@ UDATA setVMState(J9VMThread *currentThread, UDATA newState); /* ---------------- modularityHelper.c ---------------- */ + +#if JAVA_SPEC_VERSION >= 11 + #define ERRCODE_SUCCESS 0 #define ERRCODE_GENERAL_FAILURE 1 #define ERRCODE_PACKAGE_ALREADY_DEFINED 2 @@ -2825,6 +2828,8 @@ addUTFNameToPackage(J9VMThread *currentThread, J9Package *j9package, const char J9Package* getPackageDefinitionWithName(J9VMThread *currentThread, J9Module *fromModule, U_8 *packageName, U_16 len, UDATA *errCode); +#endif /* JAVA_SPEC_VERSION >= 11 */ + /* ---------------- strhelp.c ---------------- */ /* This function searches for the last occurrence of the character c in a string given its length * diff --git a/runtime/oti/vm_api.h b/runtime/oti/vm_api.h index 0dbfe00414b..3eedb667e43 100644 --- a/runtime/oti/vm_api.h +++ b/runtime/oti/vm_api.h @@ -4414,6 +4414,7 @@ setLogOptions (J9JavaVM *vm, char *options); /* -------------------- NativeHelpers.cpp ------------ */ +#if defined(J9VM_OPT_METHOD_HANDLE) /** * @brief * @param currentThread @@ -4422,6 +4423,7 @@ setLogOptions (J9JavaVM *vm, char *options); */ J9SFMethodTypeFrame * buildMethodTypeFrame(J9VMThread * currentThread, j9object_t methodType); +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ /* -------------------- drophelp.c ------------ */ diff --git a/runtime/oti/vmconstantpool.xml b/runtime/oti/vmconstantpool.xml index e46842cbf5e..3be16931ec2 100644 --- a/runtime/oti/vmconstantpool.xml +++ b/runtime/oti/vmconstantpool.xml @@ -100,7 +100,6 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti - @@ -292,8 +291,6 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti - - @@ -336,8 +333,6 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti - - @@ -392,7 +387,6 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti - diff --git a/runtime/util/modularityHelper.c b/runtime/util/modularityHelper.c index d0a637ebb76..108c7429a7a 100644 --- a/runtime/util/modularityHelper.c +++ b/runtime/util/modularityHelper.c @@ -24,6 +24,8 @@ #include "j9protos.h" #include "ut_j9util.h" +#if JAVA_SPEC_VERSION >= 11 + static J9Package* hashPackageTableAtWithUTF8Name(J9VMThread *currentThread, J9ClassLoader *classLoader, J9UTF8 *packageName); static BOOLEAN isPackageExportedToModuleHelper(J9VMThread *currentThread, J9Module *fromModule, J9Package *j9package, J9Module *toModule, BOOLEAN toUnnamed); @@ -243,3 +245,5 @@ isPackageExportedToModuleWithName(J9VMThread *currentThread, J9Module *fromModul { return isPackageExportedToModuleHelper(currentThread, fromModule, getPackageDefinitionWithName(currentThread, fromModule, packageName, len, errCode), toModule, toUnnamed); } + +#endif /* JAVA_SPEC_VERSION >= 11 */ diff --git a/runtime/vm/BytecodeInterpreter.hpp b/runtime/vm/BytecodeInterpreter.hpp index 57657af55b2..22e8d09a574 100644 --- a/runtime/vm/BytecodeInterpreter.hpp +++ b/runtime/vm/BytecodeInterpreter.hpp @@ -174,7 +174,6 @@ class INTERPRETER_CLASS VMStructHasBeenUpdated(REGISTER_ARGS); return next; } -#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ /** * Modify the MH.invocationCount so that invocations from the interpreter don't @@ -195,6 +194,7 @@ class INTERPRETER_CLASS I_32 count = J9VMJAVALANGINVOKEMETHODHANDLE_INVOCATIONCOUNT(_currentThread, methodHandle); J9VMJAVALANGINVOKEMETHODHANDLE_SET_INVOCATIONCOUNT(_currentThread, methodHandle, count - 1); } +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ #if defined(DO_SINGLE_STEP) void VMINLINE @@ -8966,7 +8966,7 @@ class INTERPRETER_CLASS VMINLINE VM_BytecodeAction invokevarhandle(REGISTER_ARGS_LIST) { -#if defined(J9VM_OPT_METHOD_HANDLE) +#if defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) VM_BytecodeAction rc = GOTO_RUN_METHODHANDLE; /* Determine stack shape */ @@ -9042,11 +9042,11 @@ class INTERPRETER_CLASS } done: return rc; -#else /* defined(J9VM_OPT_METHOD_HANDLE) */ - /* invokevarhandle is not used for OpenJDK VarHandles (J9VM_OPT_OPENJDK_METHODHANDLE). */ - Assert_VM_unreachable(); - return EXECUTE_BYTECODE; -#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ +#else /* defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) */ + /* invokevarhandle is not used for OpenJDK VarHandles (J9VM_OPT_OPENJDK_METHODHANDLE). */ + Assert_VM_unreachable(); + return EXECUTE_BYTECODE; +#endif /* defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) */ } VMINLINE VM_BytecodeAction diff --git a/runtime/vm/MHInterpreter.hpp b/runtime/vm/MHInterpreter.hpp index a2b09655fc0..0616ec46918 100644 --- a/runtime/vm/MHInterpreter.hpp +++ b/runtime/vm/MHInterpreter.hpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1991, 2020 IBM Corp. and others + * Copyright (c) 1991, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -158,17 +158,6 @@ class VM_MHInterpreter return J9VMJAVALANGINVOKESPREADHANDLE_ARRAYCLASS(_currentThread, methodHandle); } - /** - * Fetch the filterPosition field from the j.l.i.MethodHandle. - * @param methodHandle[in] A MethodHandle object - * @return The filterPosition field from the j.l.i.MethodHandle. - */ - VMINLINE U_32 - getMethodHandleFilterPosition(j9object_t methodHandle) const - { - return (U_32)J9VMJAVALANGINVOKEFILTERARGUMENTSWITHCOMBINERHANDLE_FILTERPOSITION(_currentThread, methodHandle); - } - /** * Fetch the foldPosition field from the j.l.i.MethodHandle. * @param methodHandle[in] A MethodHandle object @@ -191,12 +180,6 @@ class VM_MHInterpreter return J9VMJAVALANGINVOKEFOLDHANDLE_COMBINER(_currentThread, methodHandle); } - VMINLINE j9object_t - getCombinerHandleForFilter(j9object_t methodHandle) const - { - return J9VMJAVALANGINVOKEFILTERARGUMENTSWITHCOMBINERHANDLE_COMBINER(_currentThread, methodHandle); - } - /** * Fetch the returnType field from the j.l.i.MethodType. * @param methodType[in] A MethodType object @@ -375,7 +358,7 @@ class VM_MHInterpreter /** * @brief Call class initializer if the class is not already initialized. * @param methodHandle[in] The MethodHandle describing the stack - * @return + * @return */ VMINLINE j9object_t initializeClassIfNeeded(j9object_t methodHandle) @@ -448,7 +431,7 @@ class VM_MHInterpreter break; } } - + /** * @brief Convert argument or return type from J9Class to J9NativeTypeCode * @param type[in] The pointer to the J9Class of the type @@ -541,15 +524,6 @@ class VM_MHInterpreter j9object_t foldForFoldArguments(j9object_t methodHandle); - /** - * @brief - * Perform argument filtering for filterArgumentsWithCombiner. - * @param methodHandle - * @return j9object_t The target MethodHandle with argument filtered by combinerHandle - */ - j9object_t - filterArgumentsWithCombiner(j9object_t methodHandle); - /** * @brief * Insert the return value of combinerHandle to the argument list of foldHandle. @@ -558,14 +532,6 @@ class VM_MHInterpreter j9object_t insertReturnValueForFoldArguments(); - /** - * @brief - * Insert the return value of combinerHandle to the argument list of the methodHandle. - * @return j9object_t The target MethodHandle - */ - j9object_t - replaceReturnValueForFilterArgumentsWithCombiner(); - /** * @brief * Perform argument permuting for PermuteHandle. @@ -635,7 +601,7 @@ class VM_MHInterpreter #ifdef J9VM_OPT_PANAMA VMINLINE VM_BytecodeAction runNativeMethodHandle(j9object_t methodHandle); - + VMINLINE FFI_Return callFunctionFromNativeMethodHandle(void * nativeMethodStartAddress, UDATA *javaArgs, U_8 *returnType, j9object_t methodHandle); @@ -686,7 +652,8 @@ class VM_MHInterpreter , _vm(_currentThread->javaVM) , _objectAllocate(objectAllocate) , _objectAccessBarrier(objectAccessBarrier) - { }; + { + } }; #endif /* MHINTERPRETER_HPP_ */ diff --git a/runtime/vm/MHInterpreter.inc b/runtime/vm/MHInterpreter.inc index 33f77612bcc..067ec6f279f 100644 --- a/runtime/vm/MHInterpreter.inc +++ b/runtime/vm/MHInterpreter.inc @@ -67,7 +67,6 @@ static const char * names[] = { /* #else */ "", /* #endif J9VM_OPT_PANAMA */ - "J9_METHOD_HANDLE_KIND_FILTER_ARGUMENTS_WITH_COMBINER", }; #endif /* MH_TRACE */ @@ -286,13 +285,6 @@ VM_MHInterpreter::dispatchLoop(j9object_t methodHandle) } break; } - case J9_METHOD_HANDLE_KIND_FILTER_ARGUMENTS_WITH_COMBINER: { - methodHandle = filterArgumentsWithCombiner(methodHandle); - if (VM_VMHelpers::exceptionPending(_currentThread)) { - goto throwCurrentException; - } - break; - } case J9_METHOD_HANDLE_KIND_GUARD_WITH_TEST: { /* Get GWT_Handle.type and GWT_Handle.type.argSlots (GWT - GuardWithTest) */ /* [... GWT_Handle args] */ @@ -545,6 +537,7 @@ VM_MHInterpreter::dispatchLoop(j9object_t methodHandle) } break; } +#if defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) case J9_METHOD_HANDLE_KIND_VARHANDLE_INVOKE_EXACT: /* fallthrough */ case J9_METHOD_HANDLE_KIND_VARHANDLE_INVOKE_GENERIC: { @@ -623,6 +616,7 @@ VM_MHInterpreter::dispatchLoop(j9object_t methodHandle) ((j9object_t*)_currentThread->sp)[slotCount] = methodHandle; break; } +#endif /* defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11) */ default: Assert_VM_unreachable(); break; @@ -720,9 +714,6 @@ VM_MHInterpreter::impdep1() } } _currentThread->tempSlot = (UDATA) filterHandle; - } else if (J9VMJAVALANGINVOKEMETHODHANDLE_FILTERARGUMENTSWITHCOMBINERPLACEHOLDER_METHOD(_vm) == _currentThread->literals) { - rc = GOTO_RUN_METHODHANDLE; - _currentThread->tempSlot = (UDATA) replaceReturnValueForFilterArgumentsWithCombiner(); } else if (J9VMJAVALANGINVOKEMETHODHANDLE_FOLDHANDLEPLACEHOLDER_METHOD(_vm) == _currentThread->literals) { rc = GOTO_RUN_METHODHANDLE; _currentThread->tempSlot = (UDATA) insertReturnValueForFoldArguments(); @@ -873,7 +864,6 @@ VM_MHInterpreter::impdep1() j9object_t VM_MHInterpreter::convertArgumentsForAsType(j9object_t methodHandle) { - j9object_t result = NULL; j9object_t currentType = J9VMJAVALANGINVOKEMETHODHANDLE_TYPE(_currentThread, methodHandle); U_32 currentArgSlots = (U_32)J9VMJAVALANGINVOKEMETHODTYPE_ARGSLOTS(_currentThread, currentType); @@ -1079,7 +1069,7 @@ VM_MHInterpreter::spreadForAsSpreader(j9object_t methodHandle) buildMethodTypeFrame(_currentThread, currentType); #if JAVA_SPEC_VERSION >= 11 setCurrentException(_currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL); -#else +#else /* JAVA_SPEC_VERSION >= 11 */ setCurrentException(_currentThread, J9VMCONSTANTPOOL_JAVALANGILLEGALARGUMENTEXCEPTION, NULL); #endif /* JAVA_SPEC_VERSION >= 11 */ goto exitSpreadForAsSpreader; @@ -1358,131 +1348,6 @@ VM_MHInterpreter::getArgSlotsBeforePosition(j9object_t argumentTypes, U_32 argPo return argumentSlots; } -j9object_t -VM_MHInterpreter::filterArgumentsWithCombiner(j9object_t methodHandle) -{ - /* Get filterHandle.type and filterHandle.type.argSlots */ - /* [... filterHandle args] */ - j9object_t filterHandleType = getMethodHandleMethodType(methodHandle); - j9object_t argumentTypes = getMethodTypeArguments(filterHandleType); - U_32 filterArgSlots = getMethodTypeArgSlots(filterHandleType); - j9object_t argumentIndices = J9VMJAVALANGINVOKEFILTERARGUMENTSWITHCOMBINERHANDLE_ARGUMENTINDICES(_currentThread, methodHandle); - U_32 argumentIndicesCount = J9INDEXABLEOBJECT_SIZE(_currentThread, argumentIndices); - UDATA *spFirstFilterArgSlot = _currentThread->sp + filterArgSlots; - - /* [... filterHandle args descriptionBytes MethodTypeFrame] */ - (void)buildMethodTypeFrame(_currentThread, filterHandleType); - - /* Get combinerHandle, combinerHandle.type and combinerHandle.type.argSlots */ - j9object_t combinerHandle = getCombinerHandleForFilter(methodHandle); - j9object_t combinerType = getMethodHandleMethodType(combinerHandle); - U_32 combinerArgSlots = getMethodTypeArgSlots(combinerType); - - /* Adjust sp to make room for combinerHandle and combinerArgs. There is no point in actually adding the - * combinerHandle to the stack here because it will later be overwritten by insertPlaceHolderFrame. */ - /* [... filterHandle args descriptionBytes MethodTypeFrame combinerHandle(empty) combinerArgs(empty)] */ - _currentThread->sp -= (combinerArgSlots + 1); - UDATA *spCombinerSlot = _currentThread->sp + combinerArgSlots; - - /* Copy all arguments specified by argumentIndices from filterHandle to the stack slots used by combinerHandler */ - U_32 arrayIndex = 0; - for (arrayIndex = 0; arrayIndex < argumentIndicesCount; arrayIndex++) { - U_32 argumentTypeIndex = (U_32)J9JAVAARRAYOFINT_LOAD(_currentThread, argumentIndices, arrayIndex); - - /* Determine the slot index of each argument specified by the index in argumentIndices */ - U_32 argumentTypeSlots = getArgSlotsBeforePosition(argumentTypes, argumentTypeIndex); - - /* Determine the type of each argument specified by argumentIndices before copying. - * Note: long/double type takes 2 slots while other types take 1 slot. - */ - j9object_t argumentTypeAtIndex = - _objectAccessBarrier->inlineIndexableObjectReadObject( - _currentThread, - argumentTypes, - argumentTypeIndex); - J9Class *argumentClassAtIndex = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, argumentTypeAtIndex); - - if ((_vm->doubleReflectClass == argumentClassAtIndex) - || (_vm->longReflectClass == argumentClassAtIndex) - ) { - spCombinerSlot -= 2; - *(U_64*)spCombinerSlot = *(U_64*)(spFirstFilterArgSlot - argumentTypeSlots - 2); - } else { - spCombinerSlot -= 1; - *spCombinerSlot = *(spFirstFilterArgSlot - argumentTypeSlots - 1); - } - } - /* after loop spCombinerSlot is at the top of the combiner arguments */ - Assert_VM_true(spCombinerSlot == _currentThread->sp); - - /* [... filterHandle args descriptionBytes MethodTypeFrame filterHandle PlaceHolderFrame filterHandle combinerArgs] */ - insertPlaceHolderFrame(combinerArgSlots, methodHandle, J9VMJAVALANGINVOKEMETHODHANDLE_FILTERARGUMENTSWITHCOMBINERPLACEHOLDER_METHOD(_vm)); - - /* insertPlaceHolderFrame adds methodHandle to the stack in the slot where combinerHandle should be. Insert combinerHandle - * so the stack is correctly set up to call the combiner handle */ - /* [... filterHandle args descriptionBytes MethodTypeFrame filterHandle PlaceHolderFrame combinerHandle combinerArgs] */ - ((j9object_t *)_currentThread->sp)[combinerArgSlots] = combinerHandle; - - return combinerHandle; -} - -j9object_t -VM_MHInterpreter::replaceReturnValueForFilterArgumentsWithCombiner() -{ - UDATA *bp = _currentThread->arg0EA - (sizeof(J9SFStackFrame)/sizeof(UDATA*)); - J9SFStackFrame *frame = (J9SFStackFrame*)(bp); - - /* [... filterHandle args descriptionBytes MethodTypeFrame filterHandle PlaceHolderFrame combinerReturnValue] */ - j9object_t filterHandle = *(j9object_t*)_currentThread->arg0EA; - j9object_t filterType = getMethodHandleMethodType(filterHandle); - j9object_t argumentTypes = getMethodTypeArguments(filterType); - U_32 filterArgSlots = (U_32)getMethodTypeArgSlots(filterType); - U_32 filterPosition = getMethodHandleFilterPosition(filterHandle); - - /* Count the slot number of all the arguments before the specified filter position */ - U_32 argumentSlots = getArgSlotsBeforePosition(argumentTypes, filterPosition); - - /* Locally store the return value from the combinerHandle and determine stackslots required by the return value */ - j9object_t combinerHandle = getCombinerHandleForFilter(filterHandle); - j9object_t combinerType = getMethodHandleMethodType(combinerHandle); - j9object_t combinerReturnType = J9VMJAVALANGINVOKEMETHODTYPE_RTYPE(_currentThread, combinerType); - J9Class *combinerReturnTypeClass = J9VM_J9CLASS_FROM_HEAPCLASS(_currentThread, combinerReturnType); - U_32 combinerReturnSlots = 1; - UDATA combinerReturnValue0 = _currentThread->sp[0]; - UDATA combinerReturnValue1 = 0; - if ((_vm->doubleReflectClass == combinerReturnTypeClass) || (_vm->longReflectClass == combinerReturnTypeClass)) { - combinerReturnSlots = 2; - combinerReturnValue1 = _currentThread->sp[1]; - } - - /* Determine the number of argument slots starting after the filterPosition */ - U_32 remainingArgSlots = filterArgSlots - argumentSlots - combinerReturnSlots; - - /* Set local variables to restore state of the _currentThread during updateVMStruct */ - UDATA *mhPtr = UNTAGGED_A0(frame); - - /* Advance past the frame and single argument (now filterHandle is at the top of the stack)) */ - bp = (UDATA *)(((J9SFStackFrame*)(bp+1)) + 1); - - J9SFMethodTypeFrame *mtFrame = (J9SFMethodTypeFrame*)(bp); - _currentThread->literals = mtFrame->savedCP; - _currentThread->pc = mtFrame->savedPC; - _currentThread->arg0EA = UNTAGGED_A0(mtFrame); - _currentThread->sp = mhPtr - filterArgSlots; - - /* Overwrite initial filterHandle with filterHandle.next */ - j9object_t nextHandle = J9VMJAVALANGINVOKEFILTERARGUMENTSWITHCOMBINERHANDLE_NEXT(_currentThread, filterHandle); - *(j9object_t*)(mhPtr) = nextHandle; - - /* Add the combinerReturnValue at filterPosition */ - _currentThread->sp[remainingArgSlots] = combinerReturnValue0; - if (2 == combinerReturnSlots) { - _currentThread->sp[remainingArgSlots + 1] = combinerReturnValue1; - } - - return nextHandle; -} - j9object_t VM_MHInterpreter::foldForFoldArguments(j9object_t methodHandle) { @@ -2540,10 +2405,10 @@ VM_MHInterpreter::nativeMethodHandleCallout(void *function, UDATA *javaArgs, U_8 } if (FFI_OK == status) { - /** - * TODO Add ZOS support to perform the zaap offload switch. See VM_VMHelpers::beforeJNICall(_currentThread) and VM_VMHelpers::afterJNICall(_currentThread). - * In these functions, the J9Method in the J9SFJNINativeMethodFrame is incorrect for Panama native calls. - */ + /* + * TODO Add ZOS support to perform the zaap offload switch. See VM_VMHelpers::beforeJNICall(_currentThread) and VM_VMHelpers::afterJNICall(_currentThread). + * In these functions, the J9Method in the J9SFJNINativeMethodFrame is incorrect for Panama native calls. + */ VM_VMAccess::inlineExitVMToJNI(_currentThread); #if FFI_NATIVE_RAW_API ffi_ptrarray_to_raw(cif, values, values_raw); diff --git a/runtime/vm/NativeHelpers.cpp b/runtime/vm/NativeHelpers.cpp index d1754a27518..f332e8fa305 100644 --- a/runtime/vm/NativeHelpers.cpp +++ b/runtime/vm/NativeHelpers.cpp @@ -162,6 +162,7 @@ convertToNativeArgArray(J9VMThread *currentThread, j9object_t argArray, U_64 *ff return ffiArgs; } +#if defined(J9VM_OPT_METHOD_HANDLE) J9SFMethodTypeFrame * buildMethodTypeFrame(J9VMThread * currentThread, j9object_t methodType) { @@ -170,9 +171,9 @@ buildMethodTypeFrame(J9VMThread * currentThread, j9object_t methodType) j9object_t stackDescriptionBits = J9VMJAVALANGINVOKEMETHODTYPE_STACKDESCRIPTIONBITS(currentThread, methodType); U_32 descriptionInts = J9INDEXABLEOBJECT_SIZE(currentThread, stackDescriptionBits); U_32 descriptionBytes = ROUND_U32_TO(sizeof(UDATA), descriptionInts * sizeof(I_32)); - I_32 * description; - U_32 i; - J9SFMethodTypeFrame * methodTypeFrame; + I_32 * description = NULL; + U_32 i = 0; + J9SFMethodTypeFrame * methodTypeFrame = NULL; UDATA * newA0 = currentThread->sp + argSlots; /* Push the description bits */ @@ -203,5 +204,6 @@ buildMethodTypeFrame(J9VMThread * currentThread, j9object_t methodType) return methodTypeFrame; #undef ROUND_U32_TO } +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ -} +} /* extern "C" */ diff --git a/runtime/vm/callin.cpp b/runtime/vm/callin.cpp index 6f80288ec10..dfc1d30ed30 100644 --- a/runtime/vm/callin.cpp +++ b/runtime/vm/callin.cpp @@ -39,9 +39,6 @@ extern "C" { -static bool isAccessibleToAllModulesViaReflection(J9VMThread *currentThread, J9Class *clazz, bool javaBaseLoaded); - - UDATA pushReflectArguments(J9VMThread *currentThread, j9object_t parameterTypes, j9object_t arguments) { @@ -740,8 +737,10 @@ sendCompleteInitialization(J9VMThread *currentThread) Trc_VM_sendCompleteInitialization_Exit(currentThread); } +#if JAVA_SPEC_VERSION >= 11 static bool -isAccessibleToAllModulesViaReflection(J9VMThread *currentThread, J9Class *clazz, bool javaBaseLoaded) { +isAccessibleToAllModulesViaReflection(J9VMThread *currentThread, J9Class *clazz, bool javaBaseLoaded) +{ J9JavaVM *vm = currentThread->javaVM; bool isAccessible = true; J9Module *module = clazz->module; @@ -767,11 +766,11 @@ isAccessibleToAllModulesViaReflection(J9VMThread *currentThread, J9Class *clazz, } else { isAccessible = false; } - } return isAccessible; } +#endif /* JAVA_SPEC_VERSION >= 11 */ void JNICALL sendInit(J9VMThread *currentThread, j9object_t object, J9Class *senderClass, UDATA lookupOptions) @@ -789,7 +788,11 @@ sendInit(J9VMThread *currentThread, j9object_t object, J9Class *senderClass, UDA bool javaBaseLoaded = J9_ARE_ALL_BITS_SET(vm->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED); if (J9_ARE_ANY_BITS_SET(clazz->romClass->modifiers, J9AccPublic)) { if (J9_ARE_ANY_BITS_SET(J9_ROM_METHOD_FROM_RAM_METHOD(method)->modifiers, J9AccPublic)) { - if (!J9_ARE_MODULES_ENABLED(vm) || isAccessibleToAllModulesViaReflection(currentThread, clazz, javaBaseLoaded)) { + if (!J9_ARE_MODULES_ENABLED(vm) +#if JAVA_SPEC_VERSION >= 11 + || isAccessibleToAllModulesViaReflection(currentThread, clazz, javaBaseLoaded) +#endif /* JAVA_SPEC_VERSION >= 11 */ + ) { clazz->initializerCache = method; } else if (javaBaseLoaded) { /* remember that this class is not accessible to all. We can only set this @@ -930,6 +933,7 @@ sendResolveMethodHandle(J9VMThread *currentThread, UDATA cpIndex, J9ConstantPool void JNICALL sendForGenericInvoke(J9VMThread *currentThread, j9object_t methodHandle, j9object_t methodType, UDATA dropFirstArg) { +#if defined(J9VM_OPT_METHOD_HANDLE) Trc_VM_sendForGenericInvoke_Entry(currentThread); J9VMEntryLocalStorage newELS; if (buildCallInStackFrame(currentThread, &newELS, true, false)) { @@ -943,6 +947,9 @@ sendForGenericInvoke(J9VMThread *currentThread, j9object_t methodHandle, j9objec restoreCallInFrame(currentThread); } Trc_VM_sendForGenericInvoke_Exit(currentThread); +#else /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ + Assert_VM_unreachable(); +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ } void JNICALL @@ -982,6 +989,7 @@ sendResolveOpenJDKInvokeHandle(J9VMThread *currentThread, J9ConstantPool *ramCP, #endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ } +#if JAVA_SPEC_VERSION >= 11 void JNICALL sendResolveConstantDynamic(J9VMThread *currentThread, J9ConstantPool *ramCP, UDATA cpIndex, J9ROMNameAndSignature *nameAndSig, U_16 *bsmData) { @@ -1028,6 +1036,7 @@ sendResolveConstantDynamic(J9VMThread *currentThread, J9ConstantPool *ramCP, UDA } Trc_VM_sendResolveConstantDynamic_Exit(currentThread); } +#endif /* JAVA_SPEC_VERSION >= 11 */ void JNICALL sendResolveInvokeDynamic(J9VMThread *currentThread, J9ConstantPool *ramCP, UDATA callSiteIndex, J9ROMNameAndSignature *nameAndSig, U_16 *bsmData) diff --git a/runtime/vm/createramclass.cpp b/runtime/vm/createramclass.cpp index e3c50ce2750..fa8544935b5 100644 --- a/runtime/vm/createramclass.cpp +++ b/runtime/vm/createramclass.cpp @@ -180,7 +180,9 @@ static I_32 interfaceDepthCompare(const void *a, const void *b); #if defined(J9VM_INTERP_CUSTOM_SPIN_OPTIONS) static void checkForCustomSpinOptions(void *element, void *userData); #endif /* J9VM_INTERP_CUSTOM_SPIN_OPTIONS */ +#if JAVA_SPEC_VERSION >= 11 static void trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader *classLoader, J9UTF8 *className); +#endif /* JAVA_SPEC_VERSION >= 11 */ static void initializeClassLinks(J9Class *ramClass, J9Class *superclass, J9MemorySegment *segment, UDATA options); /* * A class which extends (perhaps indirectly) the 'magic' @@ -1803,7 +1805,9 @@ static VMINLINE BOOLEAN checkSuperClassAndInterfaces(J9VMThread *vmThread, J9ClassLoader *classLoader, J9ROMClass *romClass, UDATA options, UDATA packageID, BOOLEAN hotswapping, J9Class *superclass, J9Module *module, J9ROMClass **badClassOut, bool *incompatibleOut) { +#if JAVA_SPEC_VERSION >= 11 J9JavaVM *vm = vmThread->javaVM; +#endif /* JAVA_SPEC_VERSION >= 11 */ BOOLEAN isExemptFromValidation = J9_ARE_ANY_BITS_SET(options, J9_FINDCLASS_FLAG_UNSAFE); if (!hotswapping) { @@ -1840,7 +1844,9 @@ checkSuperClassAndInterfaces(J9VMThread *vmThread, J9ClassLoader *classLoader, J */ bool superClassIsPublic = J9_ARE_ALL_BITS_SET(superROMClass->modifiers, J9AccPublic); if ((!superClassIsPublic && (packageID != superclass->packageID)) +#if JAVA_SPEC_VERSION >= 11 || (superClassIsPublic && (J9_VISIBILITY_ALLOWED != checkModuleAccess(vmThread, vm, romClass, module, superclass->romClass, superclass->module, superclass->packageID, 0))) +#endif /* JAVA_SPEC_VERSION >= 11 */ ) { Trc_VM_CreateRAMClassFromROMClass_superclassNotVisible(vmThread, superclass, superclass->classLoader, classLoader); return FALSE; @@ -1881,7 +1887,9 @@ checkSuperClassAndInterfaces(J9VMThread *vmThread, J9ClassLoader *classLoader, J */ bool interfaceIsPublic = J9_ARE_ALL_BITS_SET(interfaceROMClass->modifiers, J9AccPublic); if ((!interfaceIsPublic && (packageID != interfaceClass->packageID)) +#if JAVA_SPEC_VERSION >= 11 || (interfaceIsPublic && (J9_VISIBILITY_ALLOWED != checkModuleAccess(vmThread, vm, romClass, module, interfaceROMClass, interfaceClass->module, interfaceClass->packageID, 0))) +#endif /* JAVA_SPEC_VERSION >= 11 */ ) { Trc_VM_CreateRAMClassFromROMClass_interfaceNotVisible(vmThread, interfaceClass, interfaceClass->classLoader, classLoader); return FALSE; @@ -2039,7 +2047,9 @@ checkFlattenableFieldValueClasses(J9VMThread *currentThread, J9ClassLoader *clas bool classIsPublic = J9_ARE_ALL_BITS_SET(valueROMClass->modifiers, J9AccPublic); if ((!classIsPublic && (packageID != valueClass->packageID)) +#if JAVA_SPEC_VERSION >= 11 || (classIsPublic && (J9_VISIBILITY_ALLOWED != checkModuleAccess(currentThread, currentThread->javaVM, romClass, module, valueROMClass, valueClass->module, valueClass->packageID, 0))) +#endif /* JAVA_SPEC_VERSION >= 11 */ ) { Trc_VM_CreateRAMClassFromROMClass_nestedValueClassNotVisible(currentThread, valueClass, valueClass->classLoader, classLoader); *badClassOut = valueROMClass; @@ -2047,7 +2057,7 @@ checkFlattenableFieldValueClasses(J9VMThread *currentThread, J9ClassLoader *clas break; } } - } + } field = romFieldsNextDo(&fieldWalkState); } return result; @@ -2180,6 +2190,7 @@ internalCreateRAMClassDone(J9VMThread *vmThread, J9ClassLoader *classLoader, J9C /* store the classObject using an access barrier */ J9STATIC_OBJECT_STORE(vmThread, state->ramClass, (j9object_t*)&state->ramClass->classObject, (j9object_t)state->classObject); +#if JAVA_SPEC_VERSION >= 11 if (J9_ARE_ALL_BITS_SET(javaVM->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED)) { J9Module *module = state->ramClass->module; j9object_t moduleObject = NULL; @@ -2205,6 +2216,7 @@ internalCreateRAMClassDone(J9VMThread *vmThread, J9ClassLoader *classLoader, J9C Assert_VM_notNull(moduleObject); J9VMJAVALANGCLASS_SET_MODULE(vmThread, state->ramClass->classObject, moduleObject); } +#endif /* JAVA_SPEC_VERSION >= 11 */ } /* Ensure all previous writes have completed before making the new class visible. */ @@ -2282,6 +2294,7 @@ checkForCustomSpinOptions(void *element, void *userData) } #endif /* J9VM_INTERP_CUSTOM_SPIN_OPTIONS */ +#if JAVA_SPEC_VERSION >= 11 static void trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader *classLoader, J9UTF8 *className) { @@ -2295,17 +2308,17 @@ trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader if (javaVM->unamedModuleForSystemLoader == ramClass->module) { #define SYSTEMLOADER_UNNAMED_NAMED_MODULE "unnamed module for system loader" memcpy(moduleNameBuf, SYSTEMLOADER_UNNAMED_NAMED_MODULE, sizeof(SYSTEMLOADER_UNNAMED_NAMED_MODULE)); -#undef SYSTEMLOADER_UNNAMED_NAMED_MODULE +#undef SYSTEMLOADER_UNNAMED_NAMED_MODULE moduleNameUTF = moduleNameBuf; } else if (javaVM->javaBaseModule == ramClass->module) { #define JAVABASE_MODULE "java.base module" memcpy(moduleNameBuf, JAVABASE_MODULE, sizeof(JAVABASE_MODULE)); -#undef JAVABASE_MODULE +#undef JAVABASE_MODULE moduleNameUTF = moduleNameBuf; } else if (NULL == ramClass->module) { #define UNNAMED_NAMED_MODULE "unnamed module" memcpy(moduleNameBuf, UNNAMED_NAMED_MODULE, sizeof(UNNAMED_NAMED_MODULE)); -#undef UNNAMED_NAMED_MODULE +#undef UNNAMED_NAMED_MODULE moduleNameUTF = moduleNameBuf; } else { moduleNameUTF = vmFuncs->copyStringToUTF8WithMemAlloc( @@ -2321,7 +2334,7 @@ trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader } else { #define UNNAMED_NAMED_MODULE "system classloader" memcpy(classLoaderNameBuf, UNNAMED_NAMED_MODULE, sizeof(UNNAMED_NAMED_MODULE)); -#undef UNNAMED_NAMED_MODULE +#undef UNNAMED_NAMED_MODULE classLoaderNameUTF = classLoaderNameBuf; } if ((NULL != classLoaderNameUTF) && (NULL != moduleNameUTF)) { @@ -2336,6 +2349,7 @@ trcModulesSettingPackage(J9VMThread *vmThread, J9Class *ramClass, J9ClassLoader j9mem_free_memory(classLoaderNameUTF); } } +#endif /* JAVA_SPEC_VERSION >= 11 */ /** * This function initializes the subclass traversal links in the ramclass and the @@ -3257,12 +3271,14 @@ internalCreateRAMClassFromROMClassImpl(J9VMThread *vmThread, J9ClassLoader *clas omrthread_monitor_exit(javaVM->classLoaderModuleAndLocationMutex); } } - if ((J2SE_VERSION(javaVM) >= J2SE_V11) && (NULL == classBeingRedefined)) { +#if JAVA_SPEC_VERSION >= 11 + if (NULL == classBeingRedefined) { ramClass->module = module; if (TrcEnabled_Trc_MODULE_setPackage) { trcModulesSettingPackage(vmThread, ramClass, classLoader, className); } } +#endif /* JAVA_SPEC_VERSION >= 11 */ } else { if (J9ROMCLASS_IS_ARRAY(romClass)) { /* fill in the special array class fields */ diff --git a/runtime/vm/intfunc.c b/runtime/vm/intfunc.c index 29ef483abe1..53099795808 100644 --- a/runtime/vm/intfunc.c +++ b/runtime/vm/intfunc.c @@ -301,7 +301,9 @@ J9InternalVMFunctions J9InternalFunctions = { resolveConstantDynamic, resolveInvokeDynamic, sendResolveOpenJDKInvokeHandle, +#if JAVA_SPEC_VERSION >= 11 sendResolveConstantDynamic, +#endif /* JAVA_SPEC_VERSION >= 11 */ sendResolveInvokeDynamic, resolveMethodHandleRef, resolveNativeAddress, @@ -326,7 +328,9 @@ J9InternalVMFunctions J9InternalFunctions = { getMonitorForWait, jvmPhaseChange, prepareClass, +#if defined(J9VM_OPT_METHOD_HANDLE) buildMethodTypeFrame, +#endif /* defined(J9VM_OPT_METHOD_HANDLE) */ fatalRecursiveStackOverflow, setIllegalAccessErrorNonPublicInvokeInterface, createThreadWithCategory, diff --git a/runtime/vm/lookupmethod.c b/runtime/vm/lookupmethod.c index 8bad7c0fef4..163ab72e1c4 100644 --- a/runtime/vm/lookupmethod.c +++ b/runtime/vm/lookupmethod.c @@ -54,7 +54,6 @@ defaultMethodConflictExceptionMessage(J9VMThread *currentThread, J9Class *target static J9Method * searchClassForMethodCommon(J9Class * clazz, U_8 * name, UDATA nameLength, U_8 * sig, UDATA sigLength, BOOLEAN partialMatch); static J9Method* javaResolveInterfaceMethods(J9VMThread *currentThread, J9Class *targetClass, J9ROMNameAndSignature *nameAndSig, J9Class *senderClass, UDATA lookupOptions, J9InterfaceResolveData *data); -static char* getModuleNameUTF(J9VMThread *currentThread, j9object_t moduleObject, char *buffer, UDATA bufferLength); /** * Search method in target class @@ -988,6 +987,7 @@ defaultMethodConflictExceptionMessage(J9VMThread *currentThread, J9Class *target return buf; } +#if JAVA_SPEC_VERSION >= 11 /** * Get Module Name * @@ -1000,7 +1000,7 @@ defaultMethodConflictExceptionMessage(J9VMThread *currentThread, J9Class *target * * @return a char pointer to the module name */ -static char* +static char * getModuleNameUTF(J9VMThread *currentThread, j9object_t moduleObject, char *buffer, UDATA bufferLength) { J9JavaVM const * const vm = currentThread->javaVM; @@ -1014,13 +1014,14 @@ getModuleNameUTF(J9VMThread *currentThread, j9object_t moduleObject, char *buffe Assert_VM_true(bufferLength >= 128); j9str_printf(PORTLIB, buffer, bufferLength, "%s0x%p", UNNAMED_MODULE, moduleObject); nameBuffer = buffer; -#undef UNNAMED_MODULE +#undef UNNAMED_MODULE } else { nameBuffer = copyStringToUTF8WithMemAlloc( currentThread, module->moduleName, J9_STR_NULL_TERMINATE_RESULT, "", 0, buffer, bufferLength, NULL); } return nameBuffer; } +#endif /* JAVA_SPEC_VERSION >= 11 */ /** * illegalModuleAccessMessage @@ -1052,7 +1053,7 @@ illegalAccessMessage(J9VMThread *currentThread, IDATA badMemberModifier, J9Class char *destModuleMsg = NULL; char packageNameBuf[J9VM_PACKAGE_NAME_BUFFER_LENGTH]; char *packageNameMsg = NULL; - + PORT_ACCESS_FROM_VMC(currentThread); Trc_VM_illegalAccessMessage_Entry(currentThread, J9UTF8_LENGTH(senderClassNameUTF), J9UTF8_DATA(senderClassNameUTF), J9UTF8_LENGTH(targetClassNameUTF), J9UTF8_DATA(targetClassNameUTF), badMemberModifier); @@ -1127,9 +1128,7 @@ illegalAccessMessage(J9VMThread *currentThread, IDATA badMemberModifier, J9Class J9UTF8_LENGTH(nestHostNameUTF), J9UTF8_DATA(nestHostNameUTF)); } - } else -#endif /* JAVA_SPEC_VERSION >= 11 */ - if (J9_VISIBILITY_NON_MODULE_ACCESS_ERROR != errorType) { + } else if (J9_VISIBILITY_NON_MODULE_ACCESS_ERROR != errorType) { /* illegal module access */ j9object_t srcModuleObject = J9VMJAVALANGCLASS_MODULE(currentThread, senderClass->classObject); j9object_t destModuleObject = J9VMJAVALANGCLASS_MODULE(currentThread, targetClass->classObject); @@ -1212,7 +1211,9 @@ illegalAccessMessage(J9VMThread *currentThread, IDATA badMemberModifier, J9Class } } } - } else { + } else +#endif /* JAVA_SPEC_VERSION >= 11 */ + { /* illegal non-module access */ if (badMemberModifier == -1) { /* visibility failed from Class level */ errorMsg = j9nls_lookup_message(J9NLS_DO_NOT_PRINT_MESSAGE_TAG | J9NLS_DO_NOT_APPEND_NEWLINE, diff --git a/runtime/vm/resolvesupport.cpp b/runtime/vm/resolvesupport.cpp index ac11d2d4cc5..954fb4ec091 100644 --- a/runtime/vm/resolvesupport.cpp +++ b/runtime/vm/resolvesupport.cpp @@ -1436,6 +1436,7 @@ resolveVirtualMethodRefInto(J9VMThread *vmStruct, J9ConstantPool *ramCP, UDATA c J9Method *method = NULL; J9Class *cpClass = NULL; +#if defined(J9VM_OPT_OPENJDK_METHODHANDLE) || (defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11)) /* Stack allocate a byte array for MethodHandle & VarHandle method name and signature. The array size is: * - J9ROMNameAndSignature * - Modified method name @@ -1445,6 +1446,7 @@ resolveVirtualMethodRefInto(J9VMThread *vmStruct, J9ConstantPool *ramCP, UDATA c * - J9UTF8 for empty signature */ U_8 onStackNAS[sizeof(J9ROMNameAndSignature) + (sizeof(U_16) + 26 + 5) + sizeof(J9UTF8)]; +#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) || (defined(J9VM_OPT_METHOD_HANDLE) && (JAVA_SPEC_VERSION >= 11)) */ lookupOptions |= J9_LOOK_VIRTUAL; if ((resolveFlags & J9_RESOLVE_FLAG_JCL_CONSTANT_POOL) == J9_RESOLVE_FLAG_JCL_CONSTANT_POOL) { @@ -1553,6 +1555,7 @@ resolveVirtualMethodRefInto(J9VMThread *vmStruct, J9ConstantPool *ramCP, UDATA c goto done; } +#if JAVA_SPEC_VERSION >= 11 } else if (resolvedClass == J9VMJAVALANGINVOKEVARHANDLE_OR_NULL(vm)) { J9UTF8 *nameUTF = J9ROMNAMEANDSIGNATURE_NAME(nameAndSig); J9UTF8 *sigUTF = J9ROMNAMEANDSIGNATURE_SIGNATURE(nameAndSig); @@ -1635,6 +1638,7 @@ resolveVirtualMethodRefInto(J9VMThread *vmStruct, J9ConstantPool *ramCP, UDATA c } } } +#endif /* JAVA_SPEC_VERSION >= 11 */ } #else /* defined(J9VM_OPT_METHOD_HANDLE) */ Trc_VM_Assert_ShouldNeverHappen(); @@ -1702,9 +1706,9 @@ resolveVirtualMethodRef(J9VMThread *vmStruct, J9ConstantPool *ramCP, UDATA cpInd return resolveVirtualMethodRefInto(vmStruct, ramCP, cpIndex, resolveFlags, resolvedMethod, ramVirtualMethodRef); } - -j9object_t -resolveMethodTypeRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags, J9RAMMethodTypeRef *ramCPEntry) { +j9object_t +resolveMethodTypeRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags, J9RAMMethodTypeRef *ramCPEntry) +{ j9object_t methodType; J9ROMMethodTypeRef *romMethodTypeRef = NULL; J9UTF8 *lookupSig = NULL; @@ -1714,7 +1718,7 @@ resolveMethodTypeRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIn UDATA lookupOptions = 0; if (canRunJavaCode) { if (!throwException) { - lookupOptions = J9_LOOK_NO_THROW; + lookupOptions = J9_LOOK_NO_THROW; } } else { lookupOptions = J9_LOOK_NO_JAVA; @@ -1834,7 +1838,8 @@ resolveMethodTypeRef(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, } j9object_t -resolveMethodHandleRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags, J9RAMMethodHandleRef *ramCPEntry) { +resolveMethodHandleRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags, J9RAMMethodHandleRef *ramCPEntry) +{ J9ROMMethodHandleRef *romMethodHandleRef; U_32 fieldOrMethodIndex; J9ROMMethodRef *cpItem; @@ -1910,7 +1915,7 @@ resolveMethodHandleRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cp break; } } -#if defined(J9VM_OPT_OPENJDK_METHODHANDLE) +#if defined(J9VM_OPT_OPENJDK_METHODHANDLE) && (JAVA_SPEC_VERSION >= 11) if (resolvedClass == J9VMJAVALANGINVOKEVARHANDLE(vmThread->javaVM)) { J9ROMNameAndSignature* nameAndSig = J9ROMMETHODREF_NAMEANDSIGNATURE(romMethodRef); J9UTF8 *nameUTF = J9ROMNAMEANDSIGNATURE_NAME(nameAndSig); @@ -1920,7 +1925,7 @@ resolveMethodHandleRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cp break; } } -#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) */ +#endif /* defined(J9VM_OPT_OPENJDK_METHODHANDLE) && (JAVA_SPEC_VERSION >= 11) */ if (resolveVirtualMethodRef(vmThread, ramCP, fieldOrMethodIndex, resolveFlags, NULL) == 0) { /* private methods don't end up in the vtable - we need to determine if invokeSpecial is @@ -1930,7 +1935,7 @@ resolveMethodHandleRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cp /* Clear the exception and let the resolveSpecialMethodRef set an exception if necessary */ VM_VMHelpers::clearException(vmThread); - + memset(&ramSpecialMethodRef, 0, sizeof(J9RAMSpecialMethodRef)); if (resolveSpecialMethodRefInto(vmThread, ramCP, fieldOrMethodIndex, resolveFlags, &ramSpecialMethodRef) == NULL) { /* Only the class and {Name, Signature} are used by the java code so it is safe to use the fake specialMethodRef */ @@ -2071,10 +2076,11 @@ resolveOpenJDKInvokeHandle(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cp j9object_t resolveConstantDynamic(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIndex, UDATA resolveFlags) { + j9object_t value = NULL; +#if JAVA_SPEC_VERSION >= 11 Assert_VM_true(J9_RESOLVE_FLAG_RUNTIME_RESOLVE == resolveFlags); J9RAMConstantDynamicRef *ramCPEntry = (J9RAMConstantDynamicRef*)ramCP + cpIndex; J9JavaVM *vm = vmThread->javaVM; - j9object_t value = NULL; bool resolved = false; retry: @@ -2185,7 +2191,9 @@ resolveConstantDynamic(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpInde omrthread_monitor_notify_all(vm->constantDynamicMutex); omrthread_monitor_exit(vm->constantDynamicMutex); } - +#else /* JAVA_SPEC_VERSION >= 11 */ + Trc_VM_Assert_ShouldNeverHappen(); +#endif /* JAVA_SPEC_VERSION >= 11 */ return value; } diff --git a/runtime/vm/visible.c b/runtime/vm/visible.c index 97d40f9deb4..923e16c04c3 100644 --- a/runtime/vm/visible.c +++ b/runtime/vm/visible.c @@ -31,6 +31,7 @@ #include "j9protos.h" #include "j9vmnls.h" +#if JAVA_SPEC_VERSION >= 11 IDATA checkModuleAccess(J9VMThread *currentThread, J9JavaVM* vm, J9ROMClass* srcRomClass, J9Module* srcModule, J9ROMClass* destRomClass, J9Module* destModule, UDATA destPackageID, UDATA lookupOptions) { @@ -68,6 +69,7 @@ checkModuleAccess(J9VMThread *currentThread, J9JavaVM* vm, J9ROMClass* srcRomCla return result; } +#endif /* JAVA_SPEC_VERSION >= 11 */ /** * Check visibility from sourceClass to destClass with modifiers specified @@ -87,7 +89,9 @@ IDATA checkVisibility(J9VMThread *currentThread, J9Class* sourceClass, J9Class* destClass, UDATA modifiers, UDATA lookupOptions) { UDATA result = J9_VISIBILITY_ALLOWED; +#if JAVA_SPEC_VERSION >= 11 J9JavaVM * const vm = currentThread->javaVM; +#endif /* JAVA_SPEC_VERSION >= 11 */ Trc_VM_checkVisibility_Entry(currentThread, sourceClass, destClass, modifiers); sourceClass = J9_CURRENT_CLASS(sourceClass); @@ -100,9 +104,9 @@ checkVisibility(J9VMThread *currentThread, J9Class* sourceClass, J9Class* destCl if (!J9CLASS_IS_EXEMPT_FROM_VALIDATION(sourceClass)) { if ( modifiers & J9AccPublic ) { /* Public */ +#if JAVA_SPEC_VERSION >= 11 if (J9_ARE_NO_BITS_SET(lookupOptions, J9_LOOK_NO_MODULE_CHECKS) && (sourceClass != destClass) - && (J2SE_VERSION(vm) >= J2SE_V11) && J9_ARE_ALL_BITS_SET(vm->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED) && !J9ROMCLASS_IS_PRIMITIVE_TYPE(destClass->romClass) ) { @@ -111,6 +115,7 @@ checkVisibility(J9VMThread *currentThread, J9Class* sourceClass, J9Class* destCl result = checkModuleAccess(currentThread, vm, sourceClass->romClass, srcModule, destClass->romClass, destModule, destClass->packageID, lookupOptions ); } +#endif /* JAVA_SPEC_VERSION >= 11 */ } else if (modifiers & J9AccPrivate) { /* Private */ if (sourceClass != destClass) { @@ -340,7 +345,7 @@ loadAndVerifyNestHost(J9VMThread *vmThread, J9Class *clazz, UDATA options) J9SRP *nestMembers = J9ROMCLASS_NESTMEMBERS(nestHost->romClass); U_16 nestMemberCount = nestHost->romClass->nestMemberCount; U_16 i = 0; - + result = J9_VISIBILITY_NEST_MEMBER_NOT_CLAIMED_ERROR; for (i = 0; i < nestMemberCount; i++) { J9UTF8 *nestMemberName = NNSRP_GET(nestMembers[i], J9UTF8*); @@ -386,4 +391,5 @@ loadAndVerifyNestHost(J9VMThread *vmThread, J9Class *clazz, UDATA options) done: return result; } + #endif /* JAVA_SPEC_VERSION >= 11 */ diff --git a/runtime/vm/vm_internal.h b/runtime/vm/vm_internal.h index 187417c5f42..88ace969fb7 100644 --- a/runtime/vm/vm_internal.h +++ b/runtime/vm/vm_internal.h @@ -455,6 +455,7 @@ initializeROMClasses(J9JavaVM *vm); /* ------------------- visible.c ----------------- */ +#if JAVA_SPEC_VERSION >= 11 /** * Check module access from srcModule to destModule. * @@ -487,6 +488,7 @@ initializeROMClasses(J9JavaVM *vm); IDATA checkModuleAccess(J9VMThread *currentThread, J9JavaVM* vm, J9ROMClass* srcRomClass, J9Module* srcModule, J9ROMClass* destRomClass, J9Module* destModule, UDATA destPackageID, UDATA lookupOptions); +#endif /* JAVA_SPEC_VERSION >= 11 */ /* ------------------- guardedstorage.c ----------------- */ diff --git a/sourcetools/j9constantpool/CMakeLists.txt b/sourcetools/j9constantpool/CMakeLists.txt index efae00342b2..c57a8b64192 100644 --- a/sourcetools/j9constantpool/CMakeLists.txt +++ b/sourcetools/j9constantpool/CMakeLists.txt @@ -34,13 +34,12 @@ else() set(CYGWIN_CP) endif() - add_jar(j9vmcp SOURCES com/ibm/oti/VMCPTool/ClassRef.java com/ibm/oti/VMCPTool/CmakeFlagInfo.java - com/ibm/oti/VMCPTool/ConstantPoolItem.java com/ibm/oti/VMCPTool/ConstantPool.java + com/ibm/oti/VMCPTool/ConstantPoolItem.java com/ibm/oti/VMCPTool/ConstantPoolStream.java com/ibm/oti/VMCPTool/Constants.java com/ibm/oti/VMCPTool/FieldRef.java diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ClassRef.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ClassRef.java index eb212c56f4b..1f50d723b8d 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ClassRef.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ClassRef.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2019 IBM Corp. and others + * Copyright (c) 2004, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -26,9 +26,10 @@ import org.w3c.dom.Element; public class ClassRef extends PrimaryItem implements Constants { - private static class Alias extends PrimaryItem.Alias { + + private static final class Alias extends PrimaryItem.Alias { final J9UTF8 name; - + Alias(VersionRange[] versions, String[] flags, J9UTF8 name) { super(versions, flags); this.name = name; @@ -45,7 +46,7 @@ void writeSecondaryItems(ConstantPoolStream ds) { void write(ConstantPoolStream ds) { ds.alignTo(4); ds.markClass(); - ds.writeInt( ds.getOffset(name) - ds.getOffset() ); + ds.writeInt(ds.getOffset(name) - ds.getOffset()); Main.JCLRuntimeFlag flag; if (flags.length == 0) { @@ -55,7 +56,7 @@ void write(ConstantPoolStream ds) { System.err.println("Error: tool cannot handle complex flag expressions"); System.exit(-1); } - flag = Main.getRuntimeFlag( flags[0] ); + flag = Main.getRuntimeFlag(flags[0]); } ds.writeInt(flag.value); } @@ -70,7 +71,7 @@ public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) { } }); } - + protected String cMacroName() { char[] buf = ((Alias) primary).name.data.toCharArray(); int j = 0; @@ -83,14 +84,14 @@ protected String cMacroName() { return new String(buf, 0, j).toUpperCase(); } - public void writeMacros(ConstantPool pool, PrintWriter out) { + public void writeMacros(ConstantPool pool, PrintWriter out) { super.writeMacros(pool, out); - + String macroName = cMacroName(); out.println("#define J9VM" + macroName + "(vm) J9VMCONSTANTPOOL_CLASS_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")"); out.println("#define J9VM" + macroName + "_OR_NULL(vm) (J9VMCONSTANTPOOL_CLASSREF_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")->value)"); } - + public String getClassName() { return ((Alias) primary).name.data; } @@ -98,5 +99,5 @@ public String getClassName() { public String commentText() { return "ClassRef[" + getClassName() + "]"; } - + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/CmakeFlagInfo.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/CmakeFlagInfo.java index 8e131e876ca..ff0ac4159ee 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/CmakeFlagInfo.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/CmakeFlagInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2019 IBM Corp. and others + * Copyright (c) 2017, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -22,19 +22,18 @@ package com.ibm.oti.VMCPTool; import java.io.BufferedReader; -import java.io.File; import java.io.FileReader; import java.util.HashSet; import java.util.Set; -import java.util.regex.Pattern; import java.util.regex.Matcher; - +import java.util.regex.Pattern; class CmakeFlagInfo implements IFlagInfo { - private HashSet seenFlags = new HashSet(); - private HashSet setFlags = new HashSet(); - // Convert string to bool using same rules as cmake + private Set seenFlags = new HashSet<>(); + private Set setFlags = new HashSet<>(); + + // Convert string to bool using same rules as cmake private static boolean strToBool(String str) { str = str.trim().toUpperCase(); if (str.isEmpty() || str.equals("NO") || str.equals("FALSE") || str.equals("OFF") || str.endsWith("-NOTFOUND")) { @@ -49,37 +48,37 @@ public CmakeFlagInfo(String cacheInfo) throws Throwable { // Pick out any lines Where == BOOL Pattern cacheVarPattern = Pattern.compile("([a-zA-Z0-9_]+):BOOL=(.*)$"); - BufferedReader reader = new BufferedReader(new FileReader(cacheInfo)); - String line; + try (BufferedReader reader = new BufferedReader(new FileReader(cacheInfo))) { + String line; - while (null != (line = reader.readLine())) { - Matcher matcher = cacheVarPattern.matcher(line); - if (matcher.matches()) { - - String flagName = matcher.group(1); - boolean flagValue = strToBool(matcher.group(2)); - - if (flagName.startsWith("J9VM_")) { - flagName = Util.transformFlag(flagName); - if (flagValue) { - setFlags.add(flagName); - } - seenFlags.add(flagName); + while (null != (line = reader.readLine())) { + Matcher matcher = cacheVarPattern.matcher(line); + if (matcher.matches()) { + String flagName = matcher.group(1); + boolean flagValue = strToBool(matcher.group(2)); + if (flagName.startsWith("J9VM_")) { + flagName = Util.transformFlag(flagName); + if (flagValue) { + setFlags.add(flagName); + } + seenFlags.add(flagName); + } } } } } + @Override public Set getAllSetFlags() { return setFlags; } - + @Override public boolean isFlagValid(String flagName) { // TODO We need to properly define all the flags from cmake before we turn this on // return seenFlags.contains(Util.transformFlag(flagName)); return true; } - + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPool.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPool.java index 1400801266c..42a61c9db6e 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPool.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPool.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2019 IBM Corp. and others + * Copyright (c) 2004, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -23,20 +23,22 @@ import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Set; public class ConstantPool { - private List primaryItems = new ArrayList(); - + + private final List primaryItems = new ArrayList<>(); + public int constantPoolSize() { return primaryItems.size() + 1; } - + public void add(PrimaryItem item) { primaryItems.add(item); } - + public PrimaryItem findPrimaryItem(Object obj) { for (PrimaryItem item : primaryItems) { if (obj.equals(item)) { @@ -58,26 +60,26 @@ public void writeForClassLibrary(int version, Set flags, PrintWriter out // 2) Connect stream output, reset offset and write to the connected stream. ConstantPoolStream ds = new ConstantPoolStream(version, flags, this, primaryItems.size() + 1); writeConstantPool(ds); - - // Now the offsets have been calculated, start over again + + // Now the offsets have been calculated, start over again. ds.open(out); writeConstantPool(ds); ds.close(); } - + private void writeConstantPool(ConstantPoolStream ds) { // CP0 is reserved ds.writeInt(0); ds.writeInt(0); - + // Write the primary items. - int cpIndex=1; + int cpIndex = 1; for (PrimaryItem item : primaryItems) { ds.comment("cp[" + cpIndex + "] = " + item.commentText()); //$NON-NLS-1$ //$NON-NLS-2$ item.write(ds); cpIndex += 1; } - + // Write the secondary items. for (PrimaryItem item : primaryItems) { item.writeSecondaryItems(ds); @@ -89,4 +91,15 @@ private void writeConstantPool(ConstantPoolStream ds) { public int getIndex(PrimaryItem item) { return 1 + primaryItems.indexOf(item); } + + public void removeNonApplicableItems(int version, Set flags) { + for (Iterator items = primaryItems.iterator(); items.hasNext();) { + PrimaryItem item = items.next(); + + if (item.alias(version, flags) == null) { + items.remove(); + } + } + } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPoolStream.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPoolStream.java index 59d5b270dee..dfa3adc23d6 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPoolStream.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ConstantPoolStream.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2019 IBM Corp. and others + * Copyright (c) 2004, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -50,11 +50,11 @@ public class ConstantPoolStream { public final int version; public final Set flags; - private List outputQueue = new ArrayList(); + private final List outputQueue = new ArrayList<>(); private ConstantPool constantPool; private int[] cpDescription; - private PrintWriter out = null; - private int offset = 0; + private PrintWriter out; + private int offset; private int itemCount; private boolean even = true; @@ -79,7 +79,7 @@ public ConstantPoolStream(int version, Set flags, ConstantPool constantP this.constantPool = constantPool; this.itemCount = itemCount; this.cpDescription = new int[(itemCount + J9_CP_DESCRIPTIONS_PER_U32 - 1) / J9_CP_DESCRIPTIONS_PER_U32]; - + // Initialize constant pool descriptors for (int i = 0; i < itemCount; i++) { mark(i, J9CPTYPE_UNUSED); @@ -103,15 +103,15 @@ private void mark(int type) { public void markInstanceField() { mark(J9CPTYPE_INSTANCE_FIELD); } - + public void markStaticField() { mark(J9CPTYPE_STATIC_FIELD); } - + public void markStaticMethod() { mark(J9CPTYPE_STATIC_METHOD); } - + public void markVirtualMethod() { mark(J9CPTYPE_VIRTUAL_METHOD); } @@ -133,7 +133,7 @@ public void writeBoolean(boolean arg0) { } public void writeByte(int arg0) { - write(new byte[] { (byte)arg0 }); + write(new byte[] { (byte) arg0 }); } public void writeBytes(String arg0) { @@ -141,7 +141,7 @@ public void writeBytes(String arg0) { } public void writeChar(int arg0) { - writeShort((short)arg0); + writeShort((short) arg0); } public void writeChars(String arg0) { @@ -157,15 +157,17 @@ public void writeFloat(float arg0) { } public void writeInt(int arg0) { - write(new byte[] { (byte)(arg0 >> 24), (byte)(arg0 >> 16), (byte)(arg0 >> 8), (byte)arg0 } ); + write(new byte[] { (byte) (arg0 >> 24), (byte) (arg0 >> 16), (byte) (arg0 >> 8), (byte) arg0 }); } public void writeLong(long arg0) { - write(new byte[] { (byte)(arg0 >> 56), (byte)(arg0 >> 48), (byte)(arg0 >> 40), (byte)(arg0 >> 32), (byte)(arg0 >> 24), (byte)(arg0 >> 16), (byte)(arg0 >> 8), (byte)arg0 } ); + write(new byte[] { + (byte) (arg0 >> 56), (byte) (arg0 >> 48), (byte) (arg0 >> 40), (byte) (arg0 >> 32), + (byte) (arg0 >> 24), (byte) (arg0 >> 16), (byte) (arg0 >> 8), (byte) arg0 }); } public void writeShort(int arg0) { - write(new byte[] { (byte)(arg0 >> 8), (byte)arg0 } ); + write(new byte[] { (byte) (arg0 >> 8), (byte) arg0 }); } public void writeUTF(String arg0) { @@ -187,10 +189,10 @@ protected void write(byte[] data) { flushQueue(); } } - + offset += data.length; } - + public int getOffset() { return offset; } @@ -200,13 +202,13 @@ public void alignTo(int alignment) { writeByte(0); } } - + private void flushQueue() { for (Iterator iter = outputQueue.iterator(); iter.hasNext();) { if (even) { out.print("\t\t{"); } - + byte[] r0 = iter.next(); if (r0.length == 4) { out.print(hex(r0)); @@ -256,11 +258,12 @@ private static String hex(byte[] array) { return buffer.toString(); } - private Map secondaryItems = new HashMap(); - + private final Map secondaryItems = new HashMap<>(); + private class Offset { - int offset; - boolean wrote; + final int offset; + final boolean wrote; + Offset(int offset, boolean wrote) { this.offset = offset; this.wrote = wrote; @@ -275,7 +278,7 @@ public void writeSecondaryItem(ConstantPoolItem item) { item.write(this); } } - + public void setOffset(ConstantPoolItem item) { Offset offset = secondaryItems.get(item); if (null != offset && getOffset() != offset.offset) { @@ -369,4 +372,5 @@ public void comment(String string) { out.print("\t/* " + string + " */"); } } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/FieldRef.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/FieldRef.java index 55b4fd49b57..f03ab87fe90 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/FieldRef.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/FieldRef.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2019 IBM Corp. and others + * Copyright (c) 2004, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -27,6 +27,7 @@ import org.w3c.dom.Element; public class FieldRef extends PrimaryItem implements Constants { + protected static class Alias extends PrimaryItem.AliasWithClass { final NameAndSignature nas; final String cast; @@ -47,61 +48,62 @@ void write(ConstantPoolStream ds) { if (checkClassForWrite(ds)) { ds.alignTo(4); ds.markInstanceField(); - ds.writeInt( ds.getIndex(classRef) ); - ds.writeInt( ds.getOffset(nas) - ds.getOffset() ); + ds.writeInt(ds.getIndex(classRef)); + ds.writeInt(ds.getOffset(nas) - ds.getOffset()); } } } - + protected static class Factory implements Alias.Factory { - private Map classes; + + private final Map classes; private ClassRef classRef; - Factory(Map classes) { + Factory(Map classes) { this.classes = classes; this.classRef = null; } - + public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) { - Alias p = (Alias)proto; + Alias p = (Alias) proto; return new Alias( - versions(e, p), - flags(e, p), - classRef(e), - new NameAndSignature( - attribute(e, "name", p != null ? p.nas.name.data : ""), - attribute(e, "signature", p != null ? p.nas.signature.data : "")), - attribute(e, "cast", p != null ? p.cast : "")); + versions(e, p), + flags(e, p), + classRef(e), + new NameAndSignature( + attribute(e, "name", p != null ? p.nas.name.data : ""), + attribute(e, "signature", p != null ? p.nas.signature.data : "")), + attribute(e, "cast", p != null ? p.cast : "")); } - + protected ClassRef classRef(Element e) { String name = attribute(e, "class", null); if (name == null) { return classRef; } if (classRef == null) { - classRef = (ClassRef) classes.get(name); + classRef = classes.get(name); } - return (ClassRef) classes.get(name); + return classes.get(name); } } - public FieldRef(Element e, Map classes) { + public FieldRef(Element e, Map classes) { super(e, FIELDALIAS, new Factory(classes)); } - + protected FieldRef(Element e, String nodeName, com.ibm.oti.VMCPTool.PrimaryItem.Alias.Factory factory) { super(e, nodeName, factory); } - + protected String cMacroName() { return ((Alias) primary).classRef.cMacroName() + "_" + ((Alias) primary).nas.name.data.toUpperCase(); } - + protected String cSetterMacroName() { return ((Alias) primary).classRef.cMacroName() + "_SET_" + ((Alias) primary).nas.name.data.toUpperCase(); } - + protected String fieldType() { // helpers are: // j9gc_objaccess_mixedObjectReadI32 @@ -117,7 +119,7 @@ protected String fieldType() { // j9gc_objaccess_mixedObjectStoreObject // j9gc_objaccess_mixedObjectStoreAddress // j9gc_objaccess_mixedObjectStoreU64Split - + // Arrays and objects take precedence over cast to support pointer compression switch (((Alias) primary).nas.signature.data.charAt(0)) { case '[': @@ -126,7 +128,7 @@ protected String fieldType() { default: // Do nothing } - + // The cast then has first dibs to determine the field type String cast = ((Alias) primary).cast; if (cast.length() > 0) { @@ -146,7 +148,7 @@ protected String fieldType() { throw new UnsupportedOperationException("Unrecognized cast: " + cast); } } - + // Otherwise just determine it from the signature switch (((Alias) primary).nas.signature.data.charAt(0)) { case '[': @@ -162,7 +164,7 @@ protected String fieldType() { return "U32"; } } - + public void writeMacros(ConstantPool pool, PrintWriter out) { super.writeMacros(pool, out); String type = fieldType(); @@ -173,34 +175,34 @@ public void writeMacros(ConstantPool pool, PrintWriter out) { if (type.equals("ADDRESS")) { fieldOffset = "J9VMCONSTANTPOOL_ADDRESS_OFFSET(J9VMTHREAD_JAVAVM(vmThread), J9VMCONSTANTPOOL_" + macroName + ")"; } - + out.println("#define J9VM" + macroName + "_OFFSET(vmThread) " + fieldOffset); out.println("#define J9VM" + macroName + "(vmThread, object) ((void)0, \\"); out.println("\t" + castTo + "J9OBJECT_" + type + "_LOAD(vmThread, object, J9VM" + macroName + "_OFFSET(vmThread)))"); out.println("#define J9VM" + cSetterMacroName() + "(vmThread, object, value) ((void)0, \\"); out.println("\tJ9OBJECT_" + type + "_STORE(vmThread, object, J9VM" + macroName + "_OFFSET(vmThread), (value)))"); - + /* Generate a second set of macros that take a J9JavaVM parameter instead of a J9VMThread */ - + fieldOffset = "J9VMCONSTANTPOOL_FIELD_OFFSET(javaVM, J9VMCONSTANTPOOL_" + macroName + ")"; if (type.equals("ADDRESS")) { fieldOffset = "J9VMCONSTANTPOOL_ADDRESS_OFFSET(javaVM, J9VMCONSTANTPOOL_" + macroName + ")"; } - + out.println("#define J9VM" + macroName + "_OFFSET_VM(javaVM) " + fieldOffset); out.println("#define J9VM" + macroName + "_VM(javaVM, object) ((void)0, \\"); out.println("\t" + castTo + "J9OBJECT_" + type + "_LOAD_VM(javaVM, object, J9VM" + macroName + "_OFFSET_VM(javaVM)))"); out.println("#define J9VM" + cSetterMacroName() + "_VM(javaVM, object, value) ((void)0, \\"); out.println("\tJ9OBJECT_" + type + "_STORE_VM(javaVM, object, J9VM" + macroName + "_OFFSET_VM(javaVM), (value)))"); - } - + protected void superWriteMacros(ConstantPool pool, PrintWriter out) { super.writeMacros(pool, out); } - + public String commentText() { Alias alias = (Alias) primary; return "FieldRef[" + alias.classRef.getClassName() + "." + alias.nas.name.data + " " + alias.nas.signature.data + "]"; - } + } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/InterfaceMethodRef.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/InterfaceMethodRef.java index ed035110b87..4ea76642d59 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/InterfaceMethodRef.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/InterfaceMethodRef.java @@ -27,6 +27,7 @@ import org.w3c.dom.Element; public class InterfaceMethodRef extends PrimaryItem implements Constants { + private static class Alias extends PrimaryItem.AliasWithClass { final NameAndSignature nas; @@ -40,58 +41,58 @@ void writeSecondaryItems(ConstantPoolStream ds) { ds.writeSecondaryItem(nas); } } - + void write(ConstantPoolStream ds) { if (checkClassForWrite(ds)) { ds.alignTo(4); ds.markInterfaceMethod(); - ds.writeInt( ds.getIndex(classRef) ); - ds.writeInt( ds.getOffset(nas) - ds.getOffset() ); + ds.writeInt(ds.getIndex(classRef)); + ds.writeInt(ds.getOffset(nas) - ds.getOffset()); } } } - + private static class Factory implements Alias.Factory { - private Map classes; + private final Map classes; private ClassRef classRef; - Factory(Map classes) { + Factory(Map classes) { this.classes = classes; this.classRef = null; } - + public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) { Alias p = (Alias) proto; return new Alias( - versions(e, p), - flags(e, p), - classRef(e), - new NameAndSignature( - attribute(e, "name", p != null ? p.nas.name.data : ""), - attribute(e, "signature", p != null ? p.nas.signature.data : ""))); + versions(e, p), + flags(e, p), + classRef(e), + new NameAndSignature( + attribute(e, "name", p != null ? p.nas.name.data : ""), + attribute(e, "signature", p != null ? p.nas.signature.data : ""))); } - + private ClassRef classRef(Element e) { String name = attribute(e, "class", null); if (name == null) { return classRef; } if (classRef == null) { - classRef = (ClassRef) classes.get(name); + classRef = classes.get(name); } - return (ClassRef) classes.get(name); + return classes.get(name); } } - public InterfaceMethodRef(Element e, Map classes) { + public InterfaceMethodRef(Element e, Map classes) { super(e, METHODALIAS, new Factory(classes)); } - + protected String cMacroName() { String methodName = ((Alias) primary).nas.name.data.toUpperCase(); if (methodName.indexOf('<') != -1) { - StringBuffer newName = new StringBuffer(); - for (int i=0; i runtimeFlagDefs; @@ -277,8 +277,10 @@ public static void main(String[] args) throws Throwable { } ConstantPool pool = parseConstantPool(); - writeHeader(pool); + pool.removeNonApplicableItems(version.intValue(), flagInfo.getAllSetFlags()); + + writeHeader(pool); writeDefinition(pool, version.intValue(), flagInfo.getAllSetFlags()); } @@ -359,7 +361,7 @@ private static void writeHeader(ConstantPool pool) throws Throwable { } private static ConstantPool parseConstantPool() throws IOException { - NodeList nodes = null; + NodeList nodes; try { File dir = new File(rootDirectory, "oti"); @@ -371,23 +373,30 @@ private static ConstantPool parseConstantPool() throws IOException { } catch (Exception e) { e.printStackTrace(); System.exit(-1); + return null; // unreachable } - Map classes = new HashMap(); + Map classes = new HashMap<>(); final int nodeCount = nodes.getLength(); - // Find classrefs. + // Find classref elements. for (int i = 0; i < nodeCount; ++i) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(CLASSREF)) { - classes.put(((Element) node).getAttribute("name"), new ClassRef((Element) node)); + Element element = (Element) node; + if (element.hasAttribute("name")) { + classes.put(element.getAttribute("name"), new ClassRef(element)); + } else { + System.err.println("Missing name for " + CLASSREF + " element"); + System.exit(-1); + } } } // Build constant pool ConstantPool pool = new ConstantPool(); // TreeMap keeps flags ordered by name. - runtimeFlagDefs = new TreeMap(); + runtimeFlagDefs = new TreeMap<>(); int lastFlagValue = 0x1; JCLRuntimeFlag defaultFlag = new JCLRuntimeFlag("default", lastFlagValue); @@ -440,7 +449,7 @@ private static ConstantPool parseConstantPool() throws IOException { private static PrimaryItem cpItem(Element e, Map classes) { String type = e.getNodeName(); if (CLASSREF.equals(type)) { - return (ClassRef) classes.get(e.getAttribute("name")); + return classes.get(e.getAttribute("name")); } else if (FIELDREF.equals(type)) { return new FieldRef(e, classes); } else if (STATICFIELDREF.equals(type)) { diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/NameAndSignature.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/NameAndSignature.java index b0b7b795987..310f591d355 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/NameAndSignature.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/NameAndSignature.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2017 IBM Corp. and others + * Copyright (c) 2004, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -29,24 +29,25 @@ public NameAndSignature(String name, String signature) { this.name = new J9UTF8(name); this.signature = new J9UTF8(signature); } - + public boolean equals(Object nas) { - return (nas instanceof NameAndSignature) - && name.equals(((NameAndSignature)nas).name) - && signature.equals(((NameAndSignature)nas).signature); + return (nas instanceof NameAndSignature) + && name.equals(((NameAndSignature) nas).name) + && signature.equals(((NameAndSignature) nas).signature); } public int hashCode() { return name.hashCode() ^ signature.hashCode(); } - + public void write(ConstantPoolStream ds) { ds.writeSecondaryItem(name); ds.writeSecondaryItem(signature); ds.alignTo(4); ds.setOffset(this); - ds.writeInt( ds.getOffset(name) - ds.getOffset() ); - ds.writeInt( ds.getOffset(signature) - ds.getOffset() ); + ds.writeInt(ds.getOffset(name) - ds.getOffset()); + ds.writeInt(ds.getOffset(signature) - ds.getOffset()); } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/PrimaryItem.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/PrimaryItem.java index 0de41f64153..c1566301a5d 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/PrimaryItem.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/PrimaryItem.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2019 IBM Corp. and others + * Copyright (c) 2004, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -96,6 +96,8 @@ protected static final class VersionRange { protected static final VersionRange[] ALL = new VersionRange[] { new VersionRange(0, Integer.MAX_VALUE) }; + protected static final VersionRange[] NONE = new VersionRange[] { new VersionRange(0, -1) }; + private static final Pattern PATTERN = Pattern.compile("(\\d+)(-(\\d*))?"); protected static VersionRange parse(String rangeText) { @@ -148,7 +150,6 @@ static interface Factory { final VersionRange[] versions; final String[] flags; - static final Alias DEFAULT = new Alias(null, null); Alias(VersionRange[] versions, String[] flags) { this.versions = versions; @@ -176,7 +177,7 @@ private boolean matchesVersion(int version) { } return false; } - + private boolean hasFlag(Set flags) { for (String s : this.flags) { if (flags.contains(s)) { @@ -186,16 +187,16 @@ private boolean hasFlag(Set flags) { return false; } } - + protected static class AliasWithClass extends Alias { final ClassRef classRef; private boolean classIncluded; - + AliasWithClass(VersionRange[] versions, String[] flags, ClassRef classRef) { super(versions, flags); this.classRef = classRef; } - + boolean checkClassForWriteSecondary(ConstantPoolStream ds) { if (!classIncluded) { super.writeSecondaryItems(ds); @@ -211,10 +212,10 @@ boolean checkClassForWrite(ConstantPoolStream ds) { return classIncluded; } } - + private static Alias[] aliases(Element e, String nodeName, Alias proto, Alias.Factory factory) { NodeList nodes = e.getChildNodes(); - List list = new ArrayList(); + List list = new ArrayList<>(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE && nodeName.equals(node.getNodeName())) { @@ -223,37 +224,37 @@ private static Alias[] aliases(Element e, String nodeName, Alias proto, Alias.Fa } return list.toArray(new Alias[list.size()]); } - - Alias alias(ConstantPoolStream ds) { - // Look for an alias that explicitly supports the version and a flag + + Alias alias(int version, Set flags) { + // Look for an alias that explicitly supports the version and a flag. for (Alias alias : aliases) { - if (alias.matchesVersion(ds.version) && alias.hasFlag(ds.flags)) { + if (alias.matchesVersion(version) && alias.hasFlag(flags)) { return alias; } } - // Look for an alias that explicitly supports either the version or a flag + // Look for an alias that explicitly supports either the version or a flag. for (Alias alias : aliases) { - // Check if the alias explicitly supports the version and has no flags - if (alias.matchesVersion(ds.version) && alias.flags.length == 0) { - // Check that the primary alias supports a flag - if (primary.hasFlag(ds.flags) || primary.flags.length == 0) { + // Check if the alias explicitly supports the version and has no flags. + if (alias.matchesVersion(version) && alias.flags.length == 0) { + // Check that the primary alias supports a flag. + if (primary.hasFlag(flags) || primary.flags.length == 0) { return alias; } } - // Check if the alias implicitly supports the version and has a flag - if (alias.versions.length == 0 && alias.hasFlag(ds.flags)) { - // Check that the primary alias supports the version - if (primary.matchesVersion(ds.version) || primary.versions.length == 0) { + // Check if the alias implicitly supports the version and has a flag. + if (alias.versions.length == 0 && alias.hasFlag(flags)) { + // Check that the primary alias supports the version. + if (primary.matchesVersion(version) || primary.versions.length == 0) { return alias; } } } - // Check that the primary alias supports the version and flags - if (primary.matchesVersion(ds.version) || primary.versions.length == 0) { - if (primary.hasFlag(ds.flags) || primary.flags.length == 0) { - // Look for an alias that implicitly supports the version and flags + // Check that the primary alias supports the version and flags. + if (primary.matchesVersion(version) || primary.versions.length == 0) { + if (primary.hasFlag(flags) || primary.flags.length == 0) { + // Look for an alias that implicitly supports the version and flags. for (Alias alias : aliases) { if (alias.versions.length == 0 && alias.flags.length == 0) { return alias; @@ -264,8 +265,12 @@ Alias alias(ConstantPoolStream ds) { } } - // Return a default alias - return Alias.DEFAULT; + // This item is not applicable to the current configuration. + return null; + } + + Alias alias(ConstantPoolStream ds) { + return alias(ds.version, ds.flags); } public void write(ConstantPoolStream ds) { diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/SpecialMethodRef.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/SpecialMethodRef.java index bb7c3385583..8b5dd08306e 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/SpecialMethodRef.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/SpecialMethodRef.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2019 IBM Corp. and others + * Copyright (c) 2004, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -27,6 +27,7 @@ import org.w3c.dom.Element; public class SpecialMethodRef extends PrimaryItem implements Constants { + private static class Alias extends PrimaryItem.AliasWithClass { final NameAndSignature nas; @@ -40,58 +41,59 @@ void writeSecondaryItems(ConstantPoolStream ds) { ds.writeSecondaryItem(nas); } } - + void write(ConstantPoolStream ds) { if (checkClassForWrite(ds)) { ds.alignTo(4); ds.markSpecialMethod(); - ds.writeInt( ds.getIndex(classRef) ); - ds.writeInt( ds.getOffset(nas) - ds.getOffset() ); + ds.writeInt(ds.getIndex(classRef)); + ds.writeInt(ds.getOffset(nas) - ds.getOffset()); } } } - + private static class Factory implements Alias.Factory { - private Map classes; + + private final Map classes; private ClassRef classRef; - Factory(Map classes) { + Factory(Map classes) { this.classes = classes; this.classRef = null; } - + public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) { Alias p = (Alias) proto; return new Alias( - versions(e, p), - flags(e, p), - classRef(e), - new NameAndSignature( - attribute(e, "name", p != null ? p.nas.name.data : ""), - attribute(e, "signature", p != null ? p.nas.signature.data : ""))); + versions(e, p), + flags(e, p), + classRef(e), + new NameAndSignature( + attribute(e, "name", p != null ? p.nas.name.data : ""), + attribute(e, "signature", p != null ? p.nas.signature.data : ""))); } - + private ClassRef classRef(Element e) { String name = attribute(e, "class", null); if (name == null) { return classRef; } if (classRef == null) { - classRef = (ClassRef) classes.get(name); + classRef = classes.get(name); } - return (ClassRef) classes.get(name); + return classes.get(name); } } - public SpecialMethodRef(Element e, Map classes) { + public SpecialMethodRef(Element e, Map classes) { super(e, METHODALIAS, new Factory(classes)); } - + protected String cMacroName() { String methodName = ((Alias) primary).nas.name.data.toUpperCase(); if (methodName.indexOf('<') != -1) { - StringBuffer newName = new StringBuffer(); - for (int i=0; i classes) { super(classes); } - + public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) { - Alias p = (Alias)proto; + Alias p = (Alias) proto; return new Alias( - versions(e, p), - flags(e, p), - classRef(e), - new NameAndSignature( - attribute(e, "name", p != null ? p.nas.name.data : ""), - attribute(e, "signature", p != null ? p.nas.signature.data : "")), - attribute(e, "cast", p != null ? p.cast : "")); + versions(e, p), + flags(e, p), + classRef(e), + new NameAndSignature( + attribute(e, "name", p != null ? p.nas.name.data : ""), + attribute(e, "signature", p != null ? p.nas.signature.data : "")), + attribute(e, "cast", p != null ? p.cast : "")); } - + } - public StaticFieldRef(Element e, Map classes) { + public StaticFieldRef(Element e, Map classes) { super(e, FIELDALIAS, new Factory(classes)); } - + public void writeMacros(ConstantPool pool, PrintWriter out) { superWriteMacros(pool, out); String type = fieldType(); @@ -73,22 +74,22 @@ public void writeMacros(ConstantPool pool, PrintWriter out) { String castTo = cast.length() == 0 ? "" : "(" + cast + ")"; String macroName = cMacroName(); String fieldOffset = "J9VMCONSTANTPOOL_STATICFIELD_ADDRESS(J9VMTHREAD_JAVAVM(vmThread), J9VMCONSTANTPOOL_" + macroName + ")"; - + out.println("#define J9VM" + macroName + "_ADDRESS(vmThread) " + fieldOffset); out.println("#define J9VM" + macroName + "(vmThread, clazz) ((void)0, \\"); out.println("\t" + castTo + "J9STATIC_" + type + "_LOAD(vmThread, clazz, J9VM" + macroName + "_ADDRESS(vmThread)))"); out.println("#define J9VM" + cSetterMacroName() + "(vmThread, clazz, value) ((void)0, \\"); out.println("\tJ9STATIC_" + type + "_STORE(vmThread, clazz, J9VM" + macroName + "_ADDRESS(vmThread), (value)))"); - + /* Generate a second set of macros that take a J9JavaVM parameter instead of a J9VMThread */ - + fieldOffset = "J9VMCONSTANTPOOL_STATICFIELD_ADDRESS_VM(javaVM, J9VMCONSTANTPOOL_" + macroName + ")"; - + out.println("#define J9VM" + macroName + "_ADDRESS_VM(javaVM) " + fieldOffset); out.println("#define J9VM" + macroName + "_VM(javaVM, clazz) ((void)0, \\"); out.println("\t" + castTo + "J9STATIC_" + type + "_LOAD_VM(javaVM, clazz, J9VM" + macroName + "_ADDRESS_VM(javaVM)))"); out.println("#define J9VM" + cSetterMacroName() + "_VM(javaVM, clazz, value) ((void)0, \\"); out.println("\tJ9STATIC_" + type + "_STORE_VM(javaVM, clazz, J9VM" + macroName + "_ADDRESS_VM(javaVM), (value)))"); - } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/StaticMethodRef.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/StaticMethodRef.java index e006f008092..4850999f241 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/StaticMethodRef.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/StaticMethodRef.java @@ -27,6 +27,7 @@ import org.w3c.dom.Element; public class StaticMethodRef extends PrimaryItem implements Constants { + private static class Alias extends PrimaryItem.AliasWithClass { final NameAndSignature nas; @@ -40,67 +41,67 @@ void writeSecondaryItems(ConstantPoolStream ds) { ds.writeSecondaryItem(nas); } } - + void write(ConstantPoolStream ds) { if (checkClassForWrite(ds)) { ds.alignTo(4); ds.markStaticMethod(); - ds.writeInt( ds.getIndex(classRef) ); - ds.writeInt( ds.getOffset(nas) - ds.getOffset() ); + ds.writeInt(ds.getIndex(classRef)); + ds.writeInt(ds.getOffset(nas) - ds.getOffset()); } } } - + private static class Factory implements Alias.Factory { - private Map classes; + private final Map classes; private ClassRef classRef; - Factory(Map classes) { + Factory(Map classes) { this.classes = classes; this.classRef = null; } - + public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) { Alias p = (Alias) proto; return new Alias( - versions(e, p), - flags(e, p), - classRef(e), - new NameAndSignature( - attribute(e, "name", p != null ? p.nas.name.data : ""), - attribute(e, "signature", p != null ? p.nas.signature.data : ""))); + versions(e, p), + flags(e, p), + classRef(e), + new NameAndSignature( + attribute(e, "name", p != null ? p.nas.name.data : ""), + attribute(e, "signature", p != null ? p.nas.signature.data : ""))); } - + private ClassRef classRef(Element e) { String name = attribute(e, "class", null); if (name == null) { return classRef; } if (classRef == null) { - classRef = (ClassRef) classes.get(name); + classRef = classes.get(name); } - return (ClassRef) classes.get(name); + return classes.get(name); } } - public StaticMethodRef(Element e, Map classes) { + public StaticMethodRef(Element e, Map classes) { super(e, METHODALIAS, new Factory(classes)); } - + protected String cMacroName() { return ((Alias) primary).classRef.cMacroName() + "_" + ((Alias) primary).nas.name.data.toUpperCase(); } - + public void writeMacros(ConstantPool pool, PrintWriter out) { super.writeMacros(pool, out); String macroName = cMacroName(); out.println("#define J9VM" + macroName + "_REF(vm) J9VMCONSTANTPOOL_STATICMETHODREF_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")"); out.println("#define J9VM" + macroName + "_METHOD(vm) J9VMCONSTANTPOOL_STATICMETHOD_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")"); } - + public String commentText() { Alias alias = (Alias) primary; return "StaticMethodRef[" + alias.classRef.getClassName() + "." + alias.nas.name.data + alias.nas.signature.data + "]"; - } - + } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/UmaFlagInfo.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/UmaFlagInfo.java index edf89366318..a1526967a69 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/UmaFlagInfo.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/UmaFlagInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2017 IBM Corp. and others + * Copyright (c) 2017, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -24,17 +24,16 @@ import java.util.HashSet; import java.util.Set; - import com.ibm.j9tools.om.BuildSpec; import com.ibm.j9tools.om.ConfigDirectory; import com.ibm.j9tools.om.Flag; import com.ibm.j9tools.om.FlagDefinitions; import com.ibm.j9tools.om.ObjectFactory; -class UmaFlagInfo implements IFlagInfo { +class UmaFlagInfo implements IFlagInfo { - private BuildSpec buildSpec; - private FlagDefinitions flagDefs; + private final BuildSpec buildSpec; + private final FlagDefinitions flagDefs; public UmaFlagInfo(String configDirectory, String buildSpecId) throws Throwable { ObjectFactory factory = new ObjectFactory(new ConfigDirectory(configDirectory)); @@ -44,19 +43,19 @@ public UmaFlagInfo(String configDirectory, String buildSpecId) throws Throwable } public Set getAllSetFlags() { - HashSet allSetFlags = new HashSet(); - for ( String flagId : buildSpec.getFlags().keySet() ) { - if ( isFlagSet(flagId) ) { + HashSet allSetFlags = new HashSet<>(); + for (String flagId : buildSpec.getFlags().keySet()) { + if (isFlagSet(flagId)) { allSetFlags.add(flagId); } } - + return allSetFlags; } public boolean isFlagValid(String flag) { flag = Util.transformFlag(flag); - if (flagDefs.getFlagDefinition(flag) == null ) { + if (flagDefs.getFlagDefinition(flag) == null) { return false; } return true; @@ -64,12 +63,13 @@ public boolean isFlagValid(String flag) { private boolean isFlagSet(String flagId) { flagId = Util.transformFlag(flagId); - if ( isFlagValid(flagId) ) { + if (isFlagValid(flagId)) { Flag flag = buildSpec.getFlags().get(flagId); - if ( flag != null ) { + if (flag != null) { return flag.getState(); } } return false; } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/Util.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/Util.java index b6764032bf4..e376e1c59cf 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/Util.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/Util.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017, 2017 IBM Corp. and others + * Copyright (c) 2017, 2021 IBM Corp. and others * * This program and the accompanying materials are made available under * the terms of the Eclipse Public License 2.0 which accompanies this @@ -24,27 +24,32 @@ public class Util { public static String transformFlag(String oldFlag) { - if (!oldFlag.startsWith("J9VM_")) { + if (!oldFlag.startsWith("J9VM_")) { return oldFlag; } - - // hack some special cases in - if ( oldFlag.equals("J9VM_IVE_JXE_OERELOCATOR")) return "ive_jxeOERelocator"; - + + // hack some special cases in + if (oldFlag.equals("J9VM_IVE_JXE_OERELOCATOR")) { + return "ive_jxeOERelocator"; + } + String newFlag = oldFlag.substring(5); // trim off the J9VM_ - int pos = newFlag.indexOf("_") + 1; + int pos = newFlag.indexOf('_') + 1; String flag = newFlag.substring(0, pos).toLowerCase(); boolean makeUpper = false; - while ( true ) { + while (true) { int last = pos; - pos = newFlag.indexOf("_", last); - if ( pos < 0 ) { - if ( last >= newFlag.length() ) break; - else pos = newFlag.length(); + pos = newFlag.indexOf('_', last); + if (pos < 0) { + if (last >= newFlag.length()) { + break; + } else { + pos = newFlag.length(); + } } if (makeUpper) { flag += newFlag.substring(last, ++last).toUpperCase(); - } else { + } else { makeUpper = true; } flag += newFlag.substring(last, pos).toLowerCase(); @@ -52,4 +57,5 @@ public static String transformFlag(String oldFlag) { } return flag; } + } diff --git a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/VirtualMethodRef.java b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/VirtualMethodRef.java index 66904811f8b..f36b502b248 100644 --- a/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/VirtualMethodRef.java +++ b/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/VirtualMethodRef.java @@ -27,6 +27,7 @@ import org.w3c.dom.Element; public class VirtualMethodRef extends PrimaryItem implements Constants { + private static class Alias extends PrimaryItem.AliasWithClass { final NameAndSignature nas; @@ -40,58 +41,59 @@ void writeSecondaryItems(ConstantPoolStream ds) { ds.writeSecondaryItem(nas); } } - + void write(ConstantPoolStream ds) { if (checkClassForWrite(ds)) { ds.alignTo(4); ds.markVirtualMethod(); - ds.writeInt( ds.getIndex(classRef) ); - ds.writeInt( ds.getOffset(nas) - ds.getOffset() ); + ds.writeInt(ds.getIndex(classRef)); + ds.writeInt(ds.getOffset(nas) - ds.getOffset()); } } + } - + private static class Factory implements Alias.Factory { - private Map classes; + private final Map classes; private ClassRef classRef; - Factory(Map classes) { + Factory(Map classes) { this.classes = classes; this.classRef = null; } - + public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) { Alias p = (Alias) proto; return new Alias( - versions(e, p), - flags(e, p), - classRef(e), - new NameAndSignature( - attribute(e, "name", p != null ? p.nas.name.data : ""), - attribute(e, "signature", p != null ? p.nas.signature.data : ""))); + versions(e, p), + flags(e, p), + classRef(e), + new NameAndSignature( + attribute(e, "name", p != null ? p.nas.name.data : ""), + attribute(e, "signature", p != null ? p.nas.signature.data : ""))); } - + private ClassRef classRef(Element e) { String name = attribute(e, "class", null); if (name == null) { return classRef; } if (classRef == null) { - classRef = (ClassRef) classes.get(name); + classRef = classes.get(name); } - return (ClassRef) classes.get(name); + return classes.get(name); } } - public VirtualMethodRef(Element e, Map classes) { + public VirtualMethodRef(Element e, Map classes) { super(e, METHODALIAS, new Factory(classes)); } - + protected String cMacroName() { String methodName = ((Alias) primary).nas.name.data.toUpperCase(); if (methodName.indexOf('<') != -1) { - StringBuffer newName = new StringBuffer(); - for (int i=0; i