Skip to content

Commit

Permalink
Automerge master into ibm_sdk 2017-10-26-09:00:08
Browse files Browse the repository at this point in the history
  • Loading branch information
j9build committed Oct 26, 2017
2 parents b13c187 + 8808170 commit 08c9cc6
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 21 deletions.
12 changes: 7 additions & 5 deletions runtime/tr.source/trj9/runtime/JitRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
#include "runtime/Runtime.hpp"
#endif

#if defined(TR_HOST_X86)
#include "x/runtime/X86Runtime.hpp"
#endif

#include "runtime/J9ValueProfiler.hpp"

#if defined(J9ZOS390)
Expand Down Expand Up @@ -1268,9 +1272,7 @@ void initializeJitRuntimeHelperTable(char isSMP)
#undef SET
}

#if defined (TR_TARGET_X86)
extern "C" int32_t compareAndExchange4(uint32_t *ptr, uint32_t, uint32_t);
#elif defined (TR_HOST_S390)
#if defined (TR_HOST_S390)
extern "C" int32_t _CompareAndSwap4(int32_t * addr, uint32_t, uint32_t);
#elif defined (TR_HOST_PPC)
extern "C" _tr_try_lock(uint32_t *a, uint32_t b, uint32_t c); // return 1 if compareAndSwap "c" successfully into "a"; otherwise 0;
Expand All @@ -1293,7 +1295,7 @@ uint8_t platformLightweightLockingIsSupported()
uint32_t platformTryLock(uint32_t *ptr)
{
#if defined(TR_TARGET_X86)
return compareAndExchange4(ptr, PLATFORM_MONITOR_UNLOCKED, PLATFORM_MONITOR_LOCKED);
return AtomicCompareAndSwap(ptr, PLATFORM_MONITOR_UNLOCKED, PLATFORM_MONITOR_LOCKED);
#elif defined (TR_HOST_S390)
return _CompareAndSwap4((int32_t *)ptr, PLATFORM_MONITOR_UNLOCKED, PLATFORM_MONITOR_LOCKED);
#elif defined (TR_HOST_PPC)
Expand All @@ -1306,7 +1308,7 @@ uint32_t platformTryLock(uint32_t *ptr)
void platformUnlock(uint32_t *ptr)
{
#if defined(TR_TARGET_X86)
compareAndExchange4(ptr, PLATFORM_MONITOR_LOCKED, PLATFORM_MONITOR_UNLOCKED);
AtomicCompareAndSwap(ptr, PLATFORM_MONITOR_LOCKED, PLATFORM_MONITOR_UNLOCKED);
#elif defined (TR_HOST_S390)
_CompareAndSwap4((int32_t *)ptr, PLATFORM_MONITOR_LOCKED, PLATFORM_MONITOR_UNLOCKED);
#elif defined (TR_HOST_PPC)
Expand Down
10 changes: 5 additions & 5 deletions runtime/tr.source/trj9/runtime/Trampoline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ void ppcCodeCacheParameters(int32_t *trampolineSize, void **callBacks, int32_t *
#endif /*(TR_TARGET_POWER)*/

#if defined(TR_TARGET_X86) && defined(TR_TARGET_64BIT)
#include "x/runtime/X86Runtime.hpp"

// Hack markers
//
Expand All @@ -514,7 +515,6 @@ void ppcCodeCacheParameters(int32_t *trampolineSize, void **callBacks, int32_t *
#define IS_32BIT_RIP(x,rip) ((intptrj_t)(x) == (intptrj_t)(rip) + (int32_t)((intptrj_t)(x) - (intptrj_t)(rip)))
#define TRAMPOLINE_SIZE 16
#define CALL_INSTR_LENGTH 5
extern "C" void _patchingFence16(void *startAddr);

void amd64CodeCacheConfig(int32_t ccSizeInByte, uint32_t *numTempTrampolines)
{
Expand Down Expand Up @@ -641,11 +641,11 @@ int32_t amd64CodePatching(void *theMethod, void *callSite, void *currentPC, void

// Self-loop
*(uint16_t *)currentTramp = 0xfeeb;
_patchingFence16(currentTramp);
patchingFence16(currentTramp);

// Store the new address
*(intptrj_t *)((uint8_t *)currentTramp + 2) = (intptrj_t)entryAddress;
_patchingFence16(currentTramp);
patchingFence16(currentTramp);

// Restore the MOV instruction
*(uint16_t *)currentTramp = 0xbf48;
Expand Down Expand Up @@ -676,12 +676,12 @@ int32_t amd64CodePatching(void *theMethod, void *callSite, void *currentPC, void
// time.)

*(uint16_t *)patchAddr = 0xfeeb;
_patchingFence16(patchAddr);
patchingFence16(patchAddr);

patchAddr[2] = (distance>>8) & 0xff;
patchAddr[3] = (distance>>16) & 0xff;
patchAddr[4] = (distance>>24) & 0xff;
_patchingFence16(patchAddr);
patchingFence16(patchAddr);

*(uint16_t *)patchAddr = 0xe8 | ((distance<<8) & 0xff00);
}
Expand Down
10 changes: 4 additions & 6 deletions runtime/tr.source/trj9/x/runtime/Recomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
#include "env/jittypes.h"
#include "runtime/CodeCacheManager.hpp"
#include "runtime/Runtime.hpp"
#include "x/runtime/X86Runtime.hpp"
#include "trj9/env/VMJ9.h"

extern "C" int32_t compareAndExchange2(uint16_t *ptr, uint16_t, uint16_t);
extern "C" void _patchingFence16(void *startAddr);

#if defined(TR_HOST_X86) && defined(TR_HOST_64BIT)
#define IS_32BIT_RIP(x,rip) ((intptrj_t)(x) == (intptrj_t)(rip) + (int32_t)((intptrj_t)(x) - (intptrj_t)(rip)))

Expand Down Expand Up @@ -155,7 +153,7 @@ void J9::Recompilation::fixUpMethodCode(void *startPC)
uint16_t newInstruction = jitEntryJmpInstruction(startPC, START_PC_TO_RECOMPILE_SAMPLING);
uint16_t oldInstruction = *(uint16_t*)((uint8_t*)startPC + START_PC_TO_ORIGINAL_ENTRY_BYTES);
uint16_t *startBytes = (uint16_t*)((uint8_t*)startPC + jitEntryOffset(startPC));
compareAndExchange2(startBytes, oldInstruction, newInstruction);
AtomicCompareAndSwap(startBytes, oldInstruction, newInstruction);
}
}

Expand Down Expand Up @@ -207,7 +205,7 @@ void J9::Recompilation::methodHasBeenRecompiled(void *oldStartPC, void *newStart
offset = ((char*)helperAddr) - startByte - 5;

*((int16_t*)startByte) = SPIN_LOOP_INSTRUCTION;
_patchingFence16(startByte);
patchingFence16(startByte);
*((int32_t*)(startByte+2)) = offset >> 8;

// Offset from CALL's return address to oldStartPC
Expand All @@ -217,7 +215,7 @@ void J9::Recompilation::methodHasBeenRecompiled(void *oldStartPC, void *newStart

// Finish patching and unlock spin loop
//
_patchingFence16(startByte);
patchingFence16(startByte);
*((int16_t*)startByte) = ((offset & 0xFF) << 8) | CALL_INSTRUCTION;

bytesToSaveAtStart = 7 + jitEntryOffset(oldStartPC); // the new call instruction + 2-byte offset; TODO: this could be 5 on IA32
Expand Down
4 changes: 0 additions & 4 deletions runtime/tr.source/trj9/x/runtime/X86Codert.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1580,8 +1580,6 @@ ifndef TR_HOST_64BIT

public clearFPStack

include x/i386/runtime/IA32AsmUtil.inc

jitReleaseVMAccess PROC NEAR
pusha
push ebp
Expand Down Expand Up @@ -1616,8 +1614,6 @@ else
;
; --------------------------------------------------------------------------------

include x/amd64/runtime/AMD64AsmUtil.inc

jitReleaseVMAccess proc
; Save system-linkage volatile regs
; GPRs
Expand Down
4 changes: 4 additions & 0 deletions runtime/vm/j9vm.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -759,3 +759,7 @@ TraceEvent=Trc_VM_CreateRAMClassFromROMClass_nestTopLoaded Overhead=1 Level=3 Te
TraceException=Trc_VM_CreateRAMClassFromROMClass_nestTopNotSamePackage Overhead=1 Level=1 Template="The nest top class (RAM class=%p, class loader=%p, this class loader=%p) is not in the same package."
TraceException=Trc_VM_CreateRAMClassFromROMClass_nestTopNotSameClassLoader Overhead=1 Level=1 Template="The nest top class (RAM class=%p, class loader=%p, this class loader=%p) has not been loaded by the same class loader."
TraceException=Trc_VM_CreateRAMClassFromROMClass_nestTopNotVerified Overhead=1 Level=1 Template="The nest top (nest top class=%p, class loader=%p, this class loader=%p) does not claim the nest member (nest member=%p)."

TraceEntry=Trc_VM_sendResolveMethodTypeRefInto_Entry Overhead=1 Level=5 Template="sendResolveMethodTypeRefInto ramCP=%p cpIndex=%zu resolveFlags=%zu"
TraceException=Trc_VM_sendResolveMethodTypeRefInto_Exception Overhead=1 Level=1 Template="Sender class=%p cannot access receiver class=%p, errorCode=%zi."
TraceExit=Trc_VM_sendResolveMethodTypeRefInto_Exit Overhead=1 Level=5 Template="sendResolveMethodTypeRefInto methodType=%p."
57 changes: 56 additions & 1 deletion runtime/vm/resolvesupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,8 @@ resolveMethodTypeRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIn
J9ROMMethodTypeRef *romMethodTypeRef = NULL;
J9UTF8 *lookupSig = NULL;

Trc_VM_sendResolveMethodTypeRefInto_Entry(vmThread, ramCP, cpIndex, resolveFlags);

/* Check if already resolved */
if (ramCPEntry->type != NULL) {
return ramCPEntry->type;
Expand Down Expand Up @@ -1612,14 +1614,67 @@ resolveMethodTypeRefInto(J9VMThread *vmThread, J9ConstantPool *ramCP, UDATA cpIn
}
}

/* perform visibility checks for the returnType and all parameters */
if (NULL != methodType) {
/* check returnType */
J9Class *senderClass = ramCP->ramClass;
J9Class *returnTypeClass = J9VM_J9CLASS_FROM_HEAPCLASS(vmThread, J9VMJAVALANGINVOKEMETHODTYPE_RETURNTYPE(vmThread, methodType));
J9Class *illegalClass = NULL;
IDATA visibilityReturnCode = 0;

if (J9ROMCLASS_IS_ARRAY(senderClass->romClass)) {
senderClass = ((J9ArrayClass *)senderClass)->leafComponentType;
}
if (J9ROMCLASS_IS_ARRAY(returnTypeClass->romClass)) {
returnTypeClass = ((J9ArrayClass *)returnTypeClass)->leafComponentType;
}

visibilityReturnCode = checkVisibility(vmThread, senderClass, returnTypeClass, returnTypeClass->romClass->modifiers, resolveFlags);

if (J9_VISIBILITY_ALLOWED != visibilityReturnCode) {
illegalClass = returnTypeClass;
} else {
/* check paramTypes */
j9object_t argTypesObject = J9VMJAVALANGINVOKEMETHODTYPE_ARGUMENTS(vmThread, methodType);
U_32 typeCount = J9INDEXABLEOBJECT_SIZE(vmThread, argTypesObject);

for (UDATA i = 0; i < typeCount; i++) {
J9Class *paramClass = J9VM_J9CLASS_FROM_HEAPCLASS(vmThread, J9JAVAARRAYOFOBJECT_LOAD(vmThread, argTypesObject, i));

if (J9ROMCLASS_IS_ARRAY(paramClass->romClass)) {
paramClass = ((J9ArrayClass *)paramClass)->leafComponentType;
}

visibilityReturnCode = checkVisibility(vmThread, senderClass, paramClass, paramClass->romClass->modifiers, resolveFlags);

if (J9_VISIBILITY_ALLOWED != visibilityReturnCode) {
illegalClass = paramClass;
break;
}
}
}
if (NULL != illegalClass) {
char *errorMsg = illegalAccessMessage(vmThread, illegalClass->romClass->modifiers, senderClass, illegalClass, visibilityReturnCode);
if (NULL == errorMsg) {
setNativeOutOfMemoryError(vmThread, 0, 0);
} else {
setCurrentExceptionUTF(vmThread, J9VMCONSTANTPOOL_JAVALANGILLEGALACCESSERROR, errorMsg);
}
Trc_VM_sendResolveMethodTypeRefInto_Exception(vmThread, senderClass, illegalClass, visibilityReturnCode);
methodType = NULL;
}
}

/* Only write the value in if its not null */
if (methodType != NULL) {
if (NULL != methodType ) {
J9Class *clazz = J9_CLASS_FROM_CP(ramCP);
j9object_t *methodTypeObjectP = &ramCPEntry->type;
/* Overwriting NULL with an immortal pointer, so no exception can occur */
J9STATIC_OBJECT_STORE(vmThread, clazz, methodTypeObjectP, methodType);
}

Trc_VM_sendResolveMethodTypeRefInto_Exit(vmThread, methodType);

return methodType;
}

Expand Down

0 comments on commit 08c9cc6

Please sign in to comment.