Path: blob/master/runtime/compiler/control/MethodToBeCompiled.cpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122#include "control/MethodToBeCompiled.hpp"23#include "infra/MonitorTable.hpp"24#include "control/OptimizationPlan.hpp"25#include "control/CompilationRuntime.hpp"26#include "ilgen/IlGeneratorMethodDetails_inlines.hpp"27#include "j9.h"28#if defined(J9VM_OPT_JITSERVER)29#include "control/CompilationThread.hpp"30#include "net/ServerStream.hpp"31#endif /* defined(J9VM_OPT_JITSERVER) */3233int16_t TR_MethodToBeCompiled::_globalIndex = 0;3435TR_MethodToBeCompiled *TR_MethodToBeCompiled::allocate(J9JITConfig *jitConfig)36{37PORT_ACCESS_FROM_JITCONFIG(jitConfig);38TR_MethodToBeCompiled *entry = (TR_MethodToBeCompiled*)39j9mem_allocate_memory(sizeof(TR_MethodToBeCompiled), J9MEM_CATEGORY_JIT);40if (entry == NULL) // Memory Allocation Failure.41return NULL;4243entry->_index = _globalIndex++;44sprintf(entry->_monitorName, "JIT-QueueSlotMonitor-%d", (int32_t)entry->_index);45entry->_monitor = TR::Monitor::create(entry->_monitorName);46if (!entry->_monitor)47{48j9mem_free_memory(entry);49return NULL;50}51return entry;52}5354void TR_MethodToBeCompiled::initialize(TR::IlGeneratorMethodDetails & details, void *oldStartPC, CompilationPriority p, TR_OptimizationPlan *optimizationPlan)55{56_methodDetails = TR::IlGeneratorMethodDetails::clone(_methodDetailsStorage, details);57_optimizationPlan = optimizationPlan;58_next = NULL;59_oldStartPC = oldStartPC;60_newStartPC = NULL;61_priority = p;62_numThreadsWaiting = 0;63_compErrCode = compilationOK;64_compilationAttemptsLeft = (TR::Options::canJITCompile()) ? MAX_COMPILE_ATTEMPTS : 1;65_unloadedMethod = false;66_doAotLoad = false;67_useAotCompilation = false;68_doNotUseAotCodeFromSharedCache = false;69_tryCompilingAgain = false;70_compInfoPT = NULL;71_aotCodeToBeRelocated = NULL;72if (_optimizationPlan)73_optimizationPlan->setIsAotLoad(false);74_async = false;75_reqFromSecondaryQueue = TR_MethodToBeCompiled::REASON_NONE;76_reqFromJProfilingQueue = false;77_changedFromAsyncToSync = false;78_entryShouldBeDeallocated = false;79_hasIncrementedNumCompThreadsCompilingHotterMethods = false;80_weight = 0;81_jitStateWhenQueued = UNDEFINED_STATE;82_entryIsCountedAsInvRequest = false;83_GCRrequest = false;8485_methodIsInSharedCache = TR_maybe;86#if defined(J9VM_OPT_JITSERVER)87_remoteCompReq = false;88_stream = NULL;89_origOptLevel = unknownHotness;90_shouldUpgradeOutOfProcessCompilation = false;91_doNotLoadFromJITServerAOTCache = false;92#endif /* defined(J9VM_OPT_JITSERVER) */9394TR_ASSERT_FATAL(_freeTag & ENTRY_IN_POOL_FREE, "initializing an entry which is not free");9596_freeTag = ENTRY_INITIALIZED;97}9899void100TR_MethodToBeCompiled::shutdown()101{102TR::MonitorTable *table = TR::MonitorTable::get();103if (!table) return;104table->removeAndDestroy(_monitor);105_monitor = NULL;106_freeTag |= ENTRY_DEALLOCATED;107}108109void TR_MethodToBeCompiled::acquireSlotMonitor(J9VMThread *vmThread)110{111getMonitor()->enter();112// Must have the compilationMonitor in hand to be able to call this method113//fprintf(stderr, "Thread %p has acquired slot monitor\n", vmThread);114}115116void TR_MethodToBeCompiled::releaseSlotMonitor(J9VMThread *vmThread)117{118// Must have the compilationMonitor in hand to be able to call this method119//fprintf(stderr, "Thread %p will release slot monitor\n", vmThread);120getMonitor()->exit();121}122123bool124TR_MethodToBeCompiled::isCompiled() const125{126return TR::CompilationInfo::isCompiled(getMethodDetails().getMethod());127}128129bool130TR_MethodToBeCompiled::isJNINative() const131{132return TR::CompilationInfo::isJNINative(getMethodDetails().getMethod());133}134135void136TR_MethodToBeCompiled::setAotCodeToBeRelocated(const void *m)137{138_aotCodeToBeRelocated = m;139_optimizationPlan->setIsAotLoad(m!=0);140}141142#if defined(J9VM_OPT_JITSERVER)143uint64_t144TR_MethodToBeCompiled::getClientUID() const145{146return _stream->getClientId();147}148#endif /* defined(J9VM_OPT_JITSERVER) */149150151