From 119b787e09718b7400d1660d2007d63908420ed9 Mon Sep 17 00:00:00 2001 From: Devin Papineau Date: Fri, 1 Jun 2018 14:02:30 -0400 Subject: [PATCH] Make java/lang/Class available in AOT Currently getClassClassPointer() refuses to return the J9Class pointer for java/lang/Class when compiling AOT (ahead of time) even though Class is practically guaranteed to be identical at AOT load time. This commit allows callers to opt in to finding Class, in which case they must ensure that their use of the J9Class pointer is acceptable for AOT compilation. Signed-off-by: Devin Papineau --- runtime/compiler/compile/J9Compilation.cpp | 37 +++++++++++++++++-- runtime/compiler/compile/J9Compilation.hpp | 7 +++- .../compiler/optimizer/InlinerTempForJ9.cpp | 2 +- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/runtime/compiler/compile/J9Compilation.cpp b/runtime/compiler/compile/J9Compilation.cpp index 03eb66cd5b1..c2a02fe2fbf 100644 --- a/runtime/compiler/compile/J9Compilation.cpp +++ b/runtime/compiler/compile/J9Compilation.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corp. and others + * Copyright (c) 2000, 2018 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 @@ -38,6 +38,7 @@ #include "control/Options_inlines.hpp" #include "control/Recompilation.hpp" #include "control/RecompilationInfo.hpp" +#include "env/j9method.h" #include "env/TRMemory.hpp" #include "env/VMJ9.h" #include "env/VMAccessCriticalSection.hpp" @@ -175,6 +176,9 @@ J9::Compilation::Compilation( _ReferenceClassPointer = fe->getClassFromSignature("Ljava/lang/ref/Reference;", 25, compilee); _JITHelpersClassPointer = fe->getClassFromSignature("Lcom/ibm/jit/JITHelpers;", 24, compilee); + _aotClassClassPointer = NULL; + _aotClassClassPointerInitialized = false; + _aotGuardPatchSites = new (m->trHeapMemory()) TR::list(getTypedAllocator(self()->allocator())); _aotClassInfo = new (m->trHeapMemory()) TR::list(getTypedAllocator(self()->allocator())); @@ -1144,9 +1148,36 @@ J9::Compilation::addAsMonitorAuto(TR::SymbolReference* symRef, bool dontAddIfDLT } TR_OpaqueClassBlock * -J9::Compilation::getClassClassPointer() +J9::Compilation::getClassClassPointer(bool isVettedForAOT) { - return _ObjectClassPointer ? self()->fe()->getClassClassPointer(_ObjectClassPointer) : 0; + if (!isVettedForAOT) + return _ObjectClassPointer ? self()->fe()->getClassClassPointer(_ObjectClassPointer) : 0; + + if (_aotClassClassPointerInitialized) + return _aotClassClassPointer; + + _aotClassClassPointerInitialized = true; + + bool jlObjectVettedForAOT = true; + TR_OpaqueClassBlock *jlObject = self()->fej9()->getClassFromSignature( + "Ljava/lang/Object;", + 18, + self()->getCurrentMethod(), + jlObjectVettedForAOT); + + if (jlObject == NULL) + return NULL; + + TR_OpaqueClassBlock *jlClass = self()->fe()->getClassClassPointer(jlObject); + if (jlClass == NULL) + return NULL; + + TR_ResolvedJ9Method *method = (TR_ResolvedJ9Method*)self()->getCurrentMethod(); + if (!method->validateArbitraryClass(self(), (J9Class*)jlClass)) + return NULL; + + _aotClassClassPointer = jlClass; + return jlClass; } /* diff --git a/runtime/compiler/compile/J9Compilation.hpp b/runtime/compiler/compile/J9Compilation.hpp index 4f847a45033..2b5b082331a 100644 --- a/runtime/compiler/compile/J9Compilation.hpp +++ b/runtime/compiler/compile/J9Compilation.hpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2017 IBM Corp. and others + * Copyright (c) 2000, 2018 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 @@ -258,7 +258,7 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector TR_OpaqueClassBlock *getSystemClassPointer() { return _SystemClassPointer; } TR_OpaqueClassBlock *getReferenceClassPointer() { return _ReferenceClassPointer; } TR_OpaqueClassBlock *getJITHelpersClassPointer() { return _JITHelpersClassPointer; } - TR_OpaqueClassBlock *getClassClassPointer(); + TR_OpaqueClassBlock *getClassClassPointer(bool isVettedForAOT = false); // Monitors TR_Array * > & getMonitorAutos() { return _monitorAutos; } @@ -343,6 +343,9 @@ class OMR_EXTENSIBLE Compilation : public OMR::CompilationConnector TR_OpaqueClassBlock *_ReferenceClassPointer; TR_OpaqueClassBlock *_JITHelpersClassPointer; + TR_OpaqueClassBlock *_aotClassClassPointer; + bool _aotClassClassPointerInitialized; + TR_Array *> _monitorAutos; TR::list _monitorAutoSymRefsInCompiledMethod; diff --git a/runtime/compiler/optimizer/InlinerTempForJ9.cpp b/runtime/compiler/optimizer/InlinerTempForJ9.cpp index 9883e682c5b..501230475e3 100644 --- a/runtime/compiler/optimizer/InlinerTempForJ9.cpp +++ b/runtime/compiler/optimizer/InlinerTempForJ9.cpp @@ -1224,7 +1224,7 @@ TR_J9InlinerPolicy::createUnsafePutWithOffset(TR::ResolvedMethodSymbol *calleeSy traceMsg(comp(),"Setting node %p as an unsafe static wrtbar\n",indirectAccessTreeTop->getNode()); indirectAccessTreeTop->getNode()->setIsUnsafeStaticWrtBar(true); } - TR_OpaqueClassBlock *javaLangClass = comp()->fe()->getClassFromSignature("Ljava/lang/Class;",17, comp()->getCurrentMethod(),true); + TR_OpaqueClassBlock *javaLangClass = comp()->getClassClassPointer(/* isVettedForAOT = */ true); // If we are not able to get javaLangClass it is still inefficient to put direct Access far // So in that case we will generate lowTagCmpTest to branch to indirect access if true bool needNotLowTagged = javaLangClass != NULL || conversionNeeded ;