Skip to content

Commit

Permalink
Merge pull request #7744 from DanHeidinga/djh/initialMethodAPI
Browse files Browse the repository at this point in the history
Add API for checking for VM initialMethods
  • Loading branch information
gacholio committed Nov 17, 2019
2 parents 3df3796 + 71b7e6e commit a3a3664
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 23 deletions.
8 changes: 4 additions & 4 deletions runtime/compiler/runtime/IProfiler.cpp
Expand Up @@ -37,6 +37,7 @@
#include "j9cfg.h"
#include "rommeth.h"
#include "vmaccess.h"
#include "VMHelpers.hpp"
#include "control/Options.hpp"
#include "control/Options_inlines.hpp"
#include "compile/Compilation.hpp"
Expand Down Expand Up @@ -4155,10 +4156,9 @@ UDATA TR_IProfiler::parseBuffer(J9VMThread * vmThread, const U_8* dataStart, UDA
callee = *(J9Method**)cursor;
cursor += sizeof(J9Method *);

if (callee
&& (javaVM->initialMethods.initialVirtualMethod != callee)
&& (javaVM->initialMethods.invokePrivateMethod != callee)
&& !fanInDisabled)
callee = VM_VMHelpers::filterVMInitialMethods(vmThread, callee);

if ((callee != NULL) && !fanInDisabled)
{
uint32_t offset = (uint32_t) (pc - caller->bytecodes);
findOrCreateMethodEntry(caller, callee , true , offset);
Expand Down
4 changes: 2 additions & 2 deletions runtime/jit_vm/CMakeLists.txt
@@ -1,5 +1,5 @@
################################################################################
# Copyright (c) 2017, 2018 IBM Corp. and others
# Copyright (c) 2017, 2019 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
Expand All @@ -23,7 +23,7 @@
add_library(j9jit_vm STATIC
artifact.c
cthelpers.cpp
ctsupport.c
ctsupport.cpp
)

target_include_directories(j9jit_vm
Expand Down
21 changes: 11 additions & 10 deletions runtime/jit_vm/ctsupport.c → runtime/jit_vm/ctsupport.cpp
Expand Up @@ -24,14 +24,17 @@
#include "j9cp.h"
#include "rommeth.h"
#include "ute.h"
#include "VMHelpers.hpp"

extern "C" {

#define J9_IS_STATIC_SPLIT_TABLE_INDEX(value) J9_ARE_ALL_BITS_SET(value, J9_STATIC_SPLIT_TABLE_INDEX_FLAG)
#define J9_IS_SPECIAL_SPLIT_TABLE_INDEX(value) J9_ARE_ALL_BITS_SET(value, J9_SPECIAL_SPLIT_TABLE_INDEX_FLAG)
#define J9_IS_SPLIT_TABLE_INDEX(value) J9_ARE_ANY_BITS_SET(value, J9_STATIC_SPLIT_TABLE_INDEX_FLAG | J9_SPECIAL_SPLIT_TABLE_INDEX_FLAG)

J9_DECLARE_CONSTANT_UTF8(newInstancePrototypeName, "newInstancePrototype");
J9_DECLARE_CONSTANT_UTF8(newInstancePrototypeSig, "(Ljava/lang/Class;)Ljava/lang/Object;");
const J9NameAndSignature newInstancePrototypeNameAndSig = { (J9UTF8*)&newInstancePrototypeName, (J9UTF8*)&newInstancePrototypeSig };
extern const J9NameAndSignature newInstancePrototypeNameAndSig = { (J9UTF8*)&newInstancePrototypeName, (J9UTF8*)&newInstancePrototypeSig };

static void jitResetAllMethodsAtStartupHelper(J9VMThread *vmStruct, J9Class *root);

Expand Down Expand Up @@ -64,7 +67,7 @@ jitGetClassInClassloaderFromUTF8(J9VMThread *vmStruct, J9ClassLoader *classLoade
J9Class *result = NULL;

if (0 != signatureLength){
result = vmStruct->javaVM->internalVMFunctions->internalFindClassUTF8(vmStruct, signatureChars,
result = vmStruct->javaVM->internalVMFunctions->internalFindClassUTF8(vmStruct, (U_8*)signatureChars,
signatureLength, classLoader, J9_FINDCLASS_FLAG_EXISTING_ONLY);
}

Expand Down Expand Up @@ -609,7 +612,9 @@ jitGetRealCPIndex(J9VMThread *currentThread, J9ROMClass *romClass, UDATA cpOrSpl
* @param constantPool Constant pool of the class that 'owns' the 'cpOrSplitIndex'
* @param cpOrSplitIndex Index of a method. Either an index into constant pool or into split table
*
* @return J9Method represented by 'cpOrSplitIndex' or NULL if the method is one of the "special" initialMethods or invokePrivateMethod
* @return J9Method represented by 'cpOrSplitIndex'
* or NULL if the method is one of the "special" initialMethods
* or if invokePrivateMethod, the real private targetmethod from the constantpool at cpOrSplitIndex if provided.
*/
J9Method *
jitGetJ9MethodUsingIndex(J9VMThread *currentThread, J9ConstantPool *constantPool, UDATA cpOrSplitIndex)
Expand All @@ -628,13 +633,7 @@ jitGetJ9MethodUsingIndex(J9VMThread *currentThread, J9ConstantPool *constantPool
} else {
method = ((J9RAMStaticMethodRef*)(constantPool + cpOrSplitIndex))->method;
}
if ((method == (J9Method*)currentThread->javaVM->initialMethods.initialStaticMethod)
|| (method == (J9Method*)currentThread->javaVM->initialMethods.initialSpecialMethod)
|| (method == (J9Method*)currentThread->javaVM->initialMethods.initialVirtualMethod)
|| (method == (J9Method*)currentThread->javaVM->initialMethods.invokePrivateMethod)
) {
method = NULL;
}
method = VM_VMHelpers::filterVMInitialMethods(currentThread, method, constantPool, cpOrSplitIndex);
return method;
}

Expand Down Expand Up @@ -717,3 +716,5 @@ jitGetDeclaringClassOfROMField(J9VMThread *vmStruct, J9Class *clazz, J9ROMFieldS
} while (NULL != currentClass);
return currentClass;
}

} /* extern "C" */
41 changes: 41 additions & 0 deletions runtime/oti/VMHelpers.hpp
Expand Up @@ -1427,6 +1427,47 @@ class VM_VMHelpers
&& (ramClass->romClass->majorVersion >= 53);
}

/**
* Filter out the initialMethods use to initialize constantpool entries
* as the methods aren't real Java methods and shouldn't be exposed to
* other APIs.
* For the special case of the `invokePrivateMethod`, lookup the real
* private target method from the cp and cpIndex if they have been
* provided.
*
* Note, there are also two defines that can be used to check the vtable
* index is one of the special methods:
* * J9VTABLE_INITIAL_VIRTUAL_OFFSET, &
* * J9VTABLE_INVOKE_PRIVATE_OFFSET
*
* @param vmThread[in] a J9VMThread
* @param method[in] the J9Method to filter
* @param cp[in] the RAM constantpool to look in for the real method for invokePrivateMethod (default = NULL)
* @param cpIndex[in] the constantpool entry to fetch the real method from for invokePrivateMethod (default = 0)
* @return The real J9Method pointer or null if it was an initialMethod.
*/
static VMINLINE J9Method*
filterVMInitialMethods(J9VMThread const *vmThread, J9Method *method, J9ConstantPool const * cp = NULL, UDATA cpIndex = 0)
{
J9InitializerMethods *initialMethods = &(vmThread->javaVM->initialMethods);
if ((method == initialMethods->initialStaticMethod)
|| (method == initialMethods->initialSpecialMethod)
|| (method == initialMethods->initialVirtualMethod)
) {
method = NULL;
}
if (method == initialMethods->invokePrivateMethod) {
method = NULL;
if (NULL != cp) {
/* Read the second slot from the CP entry to get the "real"
* target method. Note, the cpIndex cannot be a split index
* in the case of an invokePrivateMethod.
*/
method = (((J9RAMVirtualMethodRef*) cp)[cpIndex]).method;
}
}
return method;
}
};

#endif /* VMHELPERS_HPP_ */
8 changes: 4 additions & 4 deletions runtime/oti/j9nonbuilder.h
Expand Up @@ -2893,10 +2893,10 @@ typedef struct J9IndexableObjectDiscontiguousFull {
} J9IndexableObjectDiscontiguousFull;

typedef struct J9InitializerMethods {
void* initialStaticMethod;
void* initialSpecialMethod;
void* initialVirtualMethod;
void* invokePrivateMethod;
struct J9Method* initialStaticMethod;
struct J9Method* initialSpecialMethod;
struct J9Method* initialVirtualMethod;
struct J9Method* invokePrivateMethod;
} J9InitializerMethods;

typedef struct J9VMInterface {
Expand Down
2 changes: 1 addition & 1 deletion runtime/verbose/CMakeLists.txt
Expand Up @@ -34,7 +34,7 @@ add_library(j9vrb SHARED
${j9vm_SOURCE_DIR}/vm/linearswalk.c

${j9vm_SOURCE_DIR}/codert_vm/jswalk.c #IF J9VM_INTERP_NATIVE_SUPPORT
${j9vm_SOURCE_DIR}/jit_vm/ctsupport.c #IF J9VM_INTERP_USE_SPLIT_SIDE_TABLES
${j9vm_SOURCE_DIR}/jit_vm/ctsupport.cpp #IF J9VM_INTERP_USE_SPLIT_SIDE_TABLES
${j9vm_SOURCE_DIR}/compiler/runtime/MethodMetaData.c

${CMAKE_CURRENT_BINARY_DIR}/ut_j9vrb.c
Expand Down
4 changes: 2 additions & 2 deletions runtime/verbose/module.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2006, 2018 IBM Corp. and others
Copyright (c) 2006, 2019 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
Expand Down Expand Up @@ -114,7 +114,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-excepti
<vpath pattern="MethodMetaData.c" path="../compiler/runtime" augmentObjects="true" type="relativepath">
<include-if condition="spec.flags.J9VM_INTERP_NATIVE_SUPPORT"/>
</vpath>
<vpath pattern="ctsupport.c" path="j9jit_vm" augmentObjects="true"/>
<vpath pattern="ctsupport.cpp" path="j9jit_vm" augmentObjects="true"/>
</vpaths>

<libraries>
Expand Down

0 comments on commit a3a3664

Please sign in to comment.