Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/control/MethodToBeCompiled.cpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
#include "control/MethodToBeCompiled.hpp"
24
#include "infra/MonitorTable.hpp"
25
#include "control/OptimizationPlan.hpp"
26
#include "control/CompilationRuntime.hpp"
27
#include "ilgen/IlGeneratorMethodDetails_inlines.hpp"
28
#include "j9.h"
29
#if defined(J9VM_OPT_JITSERVER)
30
#include "control/CompilationThread.hpp"
31
#include "net/ServerStream.hpp"
32
#endif /* defined(J9VM_OPT_JITSERVER) */
33
34
int16_t TR_MethodToBeCompiled::_globalIndex = 0;
35
36
TR_MethodToBeCompiled *TR_MethodToBeCompiled::allocate(J9JITConfig *jitConfig)
37
{
38
PORT_ACCESS_FROM_JITCONFIG(jitConfig);
39
TR_MethodToBeCompiled *entry = (TR_MethodToBeCompiled*)
40
j9mem_allocate_memory(sizeof(TR_MethodToBeCompiled), J9MEM_CATEGORY_JIT);
41
if (entry == NULL) // Memory Allocation Failure.
42
return NULL;
43
44
entry->_index = _globalIndex++;
45
sprintf(entry->_monitorName, "JIT-QueueSlotMonitor-%d", (int32_t)entry->_index);
46
entry->_monitor = TR::Monitor::create(entry->_monitorName);
47
if (!entry->_monitor)
48
{
49
j9mem_free_memory(entry);
50
return NULL;
51
}
52
return entry;
53
}
54
55
void TR_MethodToBeCompiled::initialize(TR::IlGeneratorMethodDetails & details, void *oldStartPC, CompilationPriority p, TR_OptimizationPlan *optimizationPlan)
56
{
57
_methodDetails = TR::IlGeneratorMethodDetails::clone(_methodDetailsStorage, details);
58
_optimizationPlan = optimizationPlan;
59
_next = NULL;
60
_oldStartPC = oldStartPC;
61
_newStartPC = NULL;
62
_priority = p;
63
_numThreadsWaiting = 0;
64
_compErrCode = compilationOK;
65
_compilationAttemptsLeft = (TR::Options::canJITCompile()) ? MAX_COMPILE_ATTEMPTS : 1;
66
_unloadedMethod = false;
67
_doAotLoad = false;
68
_useAotCompilation = false;
69
_doNotUseAotCodeFromSharedCache = false;
70
_tryCompilingAgain = false;
71
_compInfoPT = NULL;
72
_aotCodeToBeRelocated = NULL;
73
if (_optimizationPlan)
74
_optimizationPlan->setIsAotLoad(false);
75
_async = false;
76
_reqFromSecondaryQueue = TR_MethodToBeCompiled::REASON_NONE;
77
_reqFromJProfilingQueue = false;
78
_changedFromAsyncToSync = false;
79
_entryShouldBeDeallocated = false;
80
_hasIncrementedNumCompThreadsCompilingHotterMethods = false;
81
_weight = 0;
82
_jitStateWhenQueued = UNDEFINED_STATE;
83
_entryIsCountedAsInvRequest = false;
84
_GCRrequest = false;
85
86
_methodIsInSharedCache = TR_maybe;
87
#if defined(J9VM_OPT_JITSERVER)
88
_remoteCompReq = false;
89
_stream = NULL;
90
_origOptLevel = unknownHotness;
91
_shouldUpgradeOutOfProcessCompilation = false;
92
_doNotLoadFromJITServerAOTCache = false;
93
#endif /* defined(J9VM_OPT_JITSERVER) */
94
95
TR_ASSERT_FATAL(_freeTag & ENTRY_IN_POOL_FREE, "initializing an entry which is not free");
96
97
_freeTag = ENTRY_INITIALIZED;
98
}
99
100
void
101
TR_MethodToBeCompiled::shutdown()
102
{
103
TR::MonitorTable *table = TR::MonitorTable::get();
104
if (!table) return;
105
table->removeAndDestroy(_monitor);
106
_monitor = NULL;
107
_freeTag |= ENTRY_DEALLOCATED;
108
}
109
110
void TR_MethodToBeCompiled::acquireSlotMonitor(J9VMThread *vmThread)
111
{
112
getMonitor()->enter();
113
// Must have the compilationMonitor in hand to be able to call this method
114
//fprintf(stderr, "Thread %p has acquired slot monitor\n", vmThread);
115
}
116
117
void TR_MethodToBeCompiled::releaseSlotMonitor(J9VMThread *vmThread)
118
{
119
// Must have the compilationMonitor in hand to be able to call this method
120
//fprintf(stderr, "Thread %p will release slot monitor\n", vmThread);
121
getMonitor()->exit();
122
}
123
124
bool
125
TR_MethodToBeCompiled::isCompiled() const
126
{
127
return TR::CompilationInfo::isCompiled(getMethodDetails().getMethod());
128
}
129
130
bool
131
TR_MethodToBeCompiled::isJNINative() const
132
{
133
return TR::CompilationInfo::isJNINative(getMethodDetails().getMethod());
134
}
135
136
void
137
TR_MethodToBeCompiled::setAotCodeToBeRelocated(const void *m)
138
{
139
_aotCodeToBeRelocated = m;
140
_optimizationPlan->setIsAotLoad(m!=0);
141
}
142
143
#if defined(J9VM_OPT_JITSERVER)
144
uint64_t
145
TR_MethodToBeCompiled::getClientUID() const
146
{
147
return _stream->getClientId();
148
}
149
#endif /* defined(J9VM_OPT_JITSERVER) */
150
151