Skip to content

Commit

Permalink
Merge pull request #2491 from gacholio/fnmf
Browse files Browse the repository at this point in the history
Optimize findNativeMethodFrame
  • Loading branch information
DanHeidinga committed Jul 27, 2018
2 parents cd590a1 + 47080e1 commit 64fcf04
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 35 deletions.
16 changes: 2 additions & 14 deletions runtime/gc_base/ObjectAccessBarrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "MemorySpace.hpp"
#include "VMThreadListIterator.hpp"
#include "ModronAssertions.h"
#include "VMHelpers.hpp"



Expand Down Expand Up @@ -2025,23 +2026,10 @@ MM_ObjectAccessBarrier::setOwnableSynchronizerLink(j9object_t object, j9object_t
*ownableSynchronizerLink = convertTokenFromPointer(value);
}

/**
* This is copy of function from jnimisc.cpp
*
* Find the J9SFJNINativeMethodFrame representing the current native.
* @param currentThread[in] the current J9VMThread
* @returns the native method frame
*/
static J9SFJNINativeMethodFrame*
findNativeMethodFrame(J9VMThread *currentThread)
{
return (J9SFJNINativeMethodFrame*)((UDATA)currentThread->sp + (UDATA)currentThread->literals);
}

void
MM_ObjectAccessBarrier::printNativeMethod(J9VMThread* vmThread)
{
J9SFJNINativeMethodFrame *nativeMethodFrame = findNativeMethodFrame(vmThread);
J9SFJNINativeMethodFrame *nativeMethodFrame = VM_VMHelpers::findNativeMethodFrame(vmThread);
J9Method *method = nativeMethodFrame->method;
J9JavaVM *javaVM = vmThread->javaVM;
PORT_ACCESS_FROM_JAVAVM(javaVM);
Expand Down
13 changes: 13 additions & 0 deletions runtime/oti/VMHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,19 @@ class VM_VMHelpers
}
}
}

/**
* Find the J9SFJNINativeMethodFrame representing the current native.
*
* @param currentThread[in] the current J9VMThread
*
* @returns the native method frame
*/
static VMINLINE J9SFJNINativeMethodFrame*
findNativeMethodFrame(J9VMThread *currentThread)
{
return (J9SFJNINativeMethodFrame*)((UDATA)currentThread->sp + (UDATA)currentThread->literals);
}
};

#endif /* VMHELPERS_HPP_ */
2 changes: 1 addition & 1 deletion runtime/vm/jnifield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static J9Method*
findFieldContext(J9VMThread *currentThread, IDATA *pcOffset)
{
IDATA bytecodePCOffset = 0;
J9Method *method = findNativeMethodFrame(currentThread)->method;
J9Method *method = VM_VMHelpers::findNativeMethodFrame(currentThread)->method;
if (NULL == method) {
J9StackWalkState *walkState = currentThread->stackWalkState;
walkState->walkThread = currentThread;
Expand Down
10 changes: 2 additions & 8 deletions runtime/vm/jnimisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ fetchArrayClass(J9VMThread *currentThread, J9Class *elementTypeClass)
return resultClass;
}

J9SFJNINativeMethodFrame*
findNativeMethodFrame(J9VMThread *currentThread)
{
return (J9SFJNINativeMethodFrame*)((UDATA)currentThread->sp + (UDATA)currentThread->literals);
}

/**
* Find the J9ClassLoader to use for the currently-running native method.
*
Expand All @@ -141,7 +135,7 @@ getCurrentClassLoader(J9VMThread *currentThread)
{
J9JavaVM *vm = currentThread->javaVM;
J9ClassLoader *classLoader = NULL;
J9SFJNINativeMethodFrame *nativeMethodFrame = findNativeMethodFrame(currentThread);
J9SFJNINativeMethodFrame *nativeMethodFrame = VM_VMHelpers::findNativeMethodFrame(currentThread);
J9Method *nativeMethod = nativeMethodFrame->method;
/* JNI 1.2 says: if there is no current native method, use the appClassLoader */
if (NULL == nativeMethod) {
Expand Down Expand Up @@ -975,7 +969,7 @@ jniResetStackReferences(JNIEnv *env)
{
J9VMThread *currentThread = (J9VMThread*)env;
Assert_VM_mustHaveVMAccess(currentThread);
J9SFJNINativeMethodFrame *nativeMethodFrame = findNativeMethodFrame(currentThread);
J9SFJNINativeMethodFrame *nativeMethodFrame = VM_VMHelpers::findNativeMethodFrame(currentThread);
UDATA flags = nativeMethodFrame->specialFrameFlags;
if (J9_ARE_ANY_BITS_SET(flags, J9_SSF_CALL_OUT_FRAME_ALLOC)) {
jniPopFrame(currentThread, JNIFRAME_TYPE_INTERNAL);
Expand Down
12 changes: 0 additions & 12 deletions runtime/vm/vm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,6 @@ fieldIndexTableNew(J9JavaVM* vm, J9PortLibrary *portLib);
void
fieldIndexTableFree(J9JavaVM* vm);

/* ---------------- jnimisc.c ---------------- */

/**
* Find the J9SFJNINativeMethodFrame representing the current native.
*
* @param currentThread[in] the current J9VMThread
*
* @returns the native method frame
*/
J9SFJNINativeMethodFrame*
findNativeMethodFrame(J9VMThread *currentThread);

/* ---------------- jniinv.c ---------------- */

/**
Expand Down

0 comments on commit 64fcf04

Please sign in to comment.