Mercurial > hg > graal-jvmci-8
annotate src/share/vm/runtime/thread.cpp @ 16006:66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 03 Jun 2014 11:51:27 +0200 |
parents | a20be10ad437 |
children | e9998e2be7f5 |
rev | line source |
---|---|
0 | 1 /* |
14909 | 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1320
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1320
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1320
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoader.hpp" | |
27 #include "classfile/javaClasses.hpp" | |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "classfile/vmSymbols.hpp" | |
30 #include "code/scopeDesc.hpp" | |
31 #include "compiler/compileBroker.hpp" | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
32 #ifdef GRAAL |
3064
8b0236cbed14
Make sure that the compiler is initialized at startup (and not on the first compiled method).
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
2925
diff
changeset
|
33 #include "graal/graalCompiler.hpp" |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4137
diff
changeset
|
34 #endif |
1972 | 35 #include "interpreter/interpreter.hpp" |
36 #include "interpreter/linkResolver.hpp" | |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
37 #include "interpreter/oopMapCache.hpp" |
2126
db2b0f8c1cef
6814943: getcpool001 catches more than one JvmtiThreadState problem
kamg
parents:
2100
diff
changeset
|
38 #include "jvmtifiles/jvmtiEnv.hpp" |
4873
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
39 #include "memory/gcLocker.inline.hpp" |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
40 #include "memory/metaspaceShared.hpp" |
1972 | 41 #include "memory/oopFactory.hpp" |
42 #include "memory/universe.inline.hpp" | |
43 #include "oops/instanceKlass.hpp" | |
44 #include "oops/objArrayOop.hpp" | |
45 #include "oops/oop.inline.hpp" | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
46 #include "oops/symbol.hpp" |
1972 | 47 #include "prims/jvm_misc.hpp" |
48 #include "prims/jvmtiExport.hpp" | |
49 #include "prims/jvmtiThreadState.hpp" | |
50 #include "prims/privilegedStack.hpp" | |
51 #include "runtime/arguments.hpp" | |
52 #include "runtime/biasedLocking.hpp" | |
53 #include "runtime/deoptimization.hpp" | |
54 #include "runtime/fprofiler.hpp" | |
55 #include "runtime/frame.inline.hpp" | |
9430
147162b27799
GRAAL-234 - PTX code loading
Morris Meyer <morris.meyer@oracle.com>
parents:
9088
diff
changeset
|
56 #include "runtime/gpu.hpp" |
1972 | 57 #include "runtime/init.hpp" |
58 #include "runtime/interfaceSupport.hpp" | |
59 #include "runtime/java.hpp" | |
60 #include "runtime/javaCalls.hpp" | |
61 #include "runtime/jniPeriodicChecker.hpp" | |
62 #include "runtime/memprofiler.hpp" | |
63 #include "runtime/mutexLocker.hpp" | |
64 #include "runtime/objectMonitor.hpp" | |
65 #include "runtime/osThread.hpp" | |
66 #include "runtime/safepoint.hpp" | |
67 #include "runtime/sharedRuntime.hpp" | |
68 #include "runtime/statSampler.hpp" | |
69 #include "runtime/stubRoutines.hpp" | |
70 #include "runtime/task.hpp" | |
7180
f34d701e952e
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
7179
diff
changeset
|
71 #include "runtime/thread.inline.hpp" |
1972 | 72 #include "runtime/threadCritical.hpp" |
73 #include "runtime/threadLocalStorage.hpp" | |
74 #include "runtime/vframe.hpp" | |
75 #include "runtime/vframeArray.hpp" | |
76 #include "runtime/vframe_hp.hpp" | |
77 #include "runtime/vmThread.hpp" | |
78 #include "runtime/vm_operations.hpp" | |
79 #include "services/attachListener.hpp" | |
80 #include "services/management.hpp" | |
6197 | 81 #include "services/memTracker.hpp" |
1972 | 82 #include "services/threadService.hpp" |
10405 | 83 #include "trace/tracing.hpp" |
84 #include "trace/traceMacros.hpp" | |
1972 | 85 #include "utilities/defaultStream.hpp" |
86 #include "utilities/dtrace.hpp" | |
87 #include "utilities/events.hpp" | |
88 #include "utilities/preserveException.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
89 #include "utilities/macros.hpp" |
1972 | 90 #ifdef TARGET_OS_FAMILY_linux |
91 # include "os_linux.inline.hpp" | |
92 #endif | |
93 #ifdef TARGET_OS_FAMILY_solaris | |
94 # include "os_solaris.inline.hpp" | |
95 #endif | |
96 #ifdef TARGET_OS_FAMILY_windows | |
97 # include "os_windows.inline.hpp" | |
98 #endif | |
3960 | 99 #ifdef TARGET_OS_FAMILY_bsd |
100 # include "os_bsd.inline.hpp" | |
101 #endif | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
102 #if INCLUDE_ALL_GCS |
1972 | 103 #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" |
104 #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" | |
105 #include "gc_implementation/parallelScavenge/pcTasks.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
106 #endif // INCLUDE_ALL_GCS |
1972 | 107 #ifdef COMPILER1 |
108 #include "c1/c1_Compiler.hpp" | |
109 #endif | |
110 #ifdef COMPILER2 | |
111 #include "opto/c2compiler.hpp" | |
112 #include "opto/idealGraphPrinter.hpp" | |
113 #endif | |
0 | 114 |
115 #ifdef DTRACE_ENABLED | |
116 | |
117 // Only bother with this argument setup if dtrace is available | |
118 | |
14909 | 119 #ifndef USDT2 |
120 HS_DTRACE_PROBE_DECL(hotspot, vm__init__begin); | |
121 HS_DTRACE_PROBE_DECL(hotspot, vm__init__end); | |
122 HS_DTRACE_PROBE_DECL5(hotspot, thread__start, char*, intptr_t, | |
123 intptr_t, intptr_t, bool); | |
124 HS_DTRACE_PROBE_DECL5(hotspot, thread__stop, char*, intptr_t, | |
125 intptr_t, intptr_t, bool); | |
126 | |
127 #define DTRACE_THREAD_PROBE(probe, javathread) \ | |
128 { \ | |
129 ResourceMark rm(this); \ | |
130 int len = 0; \ | |
131 const char* name = (javathread)->get_thread_name(); \ | |
132 len = strlen(name); \ | |
133 HS_DTRACE_PROBE5(hotspot, thread__##probe, \ | |
134 name, len, \ | |
135 java_lang_Thread::thread_id((javathread)->threadObj()), \ | |
136 (javathread)->osthread()->thread_id(), \ | |
137 java_lang_Thread::is_daemon((javathread)->threadObj())); \ | |
138 } | |
139 | |
140 #else /* USDT2 */ | |
141 | |
142 #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_PROBE_START | |
143 #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_PROBE_STOP | |
4006 | 144 |
145 #define DTRACE_THREAD_PROBE(probe, javathread) \ | |
146 { \ | |
147 ResourceMark rm(this); \ | |
148 int len = 0; \ | |
149 const char* name = (javathread)->get_thread_name(); \ | |
150 len = strlen(name); \ | |
151 HOTSPOT_THREAD_PROBE_##probe( /* probe = start, stop */ \ | |
152 (char *) name, len, \ | |
153 java_lang_Thread::thread_id((javathread)->threadObj()), \ | |
154 (uintptr_t) (javathread)->osthread()->thread_id(), \ | |
155 java_lang_Thread::is_daemon((javathread)->threadObj())); \ | |
156 } | |
157 | |
14909 | 158 #endif /* USDT2 */ |
159 | |
0 | 160 #else // ndef DTRACE_ENABLED |
161 | |
162 #define DTRACE_THREAD_PROBE(probe, javathread) | |
163 | |
164 #endif // ndef DTRACE_ENABLED | |
165 | |
6197 | 166 |
0 | 167 // Class hierarchy |
168 // - Thread | |
169 // - VMThread | |
170 // - WatcherThread | |
171 // - ConcurrentMarkSweepThread | |
172 // - JavaThread | |
173 // - CompilerThread | |
174 | |
175 // ======= Thread ======== | |
176 // Support for forcing alignment of thread objects for biased locking | |
6197 | 177 void* Thread::allocate(size_t size, bool throw_excpt, MEMFLAGS flags) { |
0 | 178 if (UseBiasedLocking) { |
179 const int alignment = markOopDesc::biased_lock_alignment; | |
180 size_t aligned_size = size + (alignment - sizeof(intptr_t)); | |
6197 | 181 void* real_malloc_addr = throw_excpt? AllocateHeap(aligned_size, flags, CURRENT_PC) |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6857
diff
changeset
|
182 : AllocateHeap(aligned_size, flags, CURRENT_PC, |
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6857
diff
changeset
|
183 AllocFailStrategy::RETURN_NULL); |
0 | 184 void* aligned_addr = (void*) align_size_up((intptr_t) real_malloc_addr, alignment); |
185 assert(((uintptr_t) aligned_addr + (uintptr_t) size) <= | |
186 ((uintptr_t) real_malloc_addr + (uintptr_t) aligned_size), | |
187 "JavaThread alignment code overflowed allocated storage"); | |
188 if (TraceBiasedLocking) { | |
189 if (aligned_addr != real_malloc_addr) | |
190 tty->print_cr("Aligned thread " INTPTR_FORMAT " to " INTPTR_FORMAT, | |
191 real_malloc_addr, aligned_addr); | |
192 } | |
193 ((Thread*) aligned_addr)->_real_malloc_address = real_malloc_addr; | |
194 return aligned_addr; | |
195 } else { | |
6197 | 196 return throw_excpt? AllocateHeap(size, flags, CURRENT_PC) |
6872
7b5885dadbdc
8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents:
6857
diff
changeset
|
197 : AllocateHeap(size, flags, CURRENT_PC, AllocFailStrategy::RETURN_NULL); |
0 | 198 } |
199 } | |
200 | |
201 void Thread::operator delete(void* p) { | |
202 if (UseBiasedLocking) { | |
203 void* real_malloc_addr = ((Thread*) p)->_real_malloc_address; | |
6197 | 204 FreeHeap(real_malloc_addr, mtThread); |
0 | 205 } else { |
6197 | 206 FreeHeap(p, mtThread); |
0 | 207 } |
208 } | |
209 | |
210 | |
211 // Base class for all threads: VMThread, WatcherThread, ConcurrentMarkSweepThread, | |
212 // JavaThread | |
213 | |
214 | |
215 Thread::Thread() { | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
216 // stack and get_thread |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
217 set_stack_base(NULL); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
218 set_stack_size(0); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
219 set_self_raw_id(0); |
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
220 set_lgrp_id(-1); |
0 | 221 |
222 // allocated data structures | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
223 set_osthread(NULL); |
6197 | 224 set_resource_area(new (mtThread)ResourceArea()); |
11136
dbc0b5dc08f5
7143807: ResourceMark nesting problem in stringStream
fparain
parents:
11096
diff
changeset
|
225 DEBUG_ONLY(_current_resource_mark = NULL;) |
6197 | 226 set_handle_area(new (mtThread) HandleArea(NULL)); |
11027
b9f4c4ec0f50
8008964: NPG: Memory regression: Thread::_metadata_handles uses 1 KB per thread.
iklam
parents:
10405
diff
changeset
|
227 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true)); |
0 | 228 set_active_handles(NULL); |
229 set_free_handle_block(NULL); | |
230 set_last_handle_mark(NULL); | |
231 | |
232 // This initial value ==> never claimed. | |
233 _oops_do_parity = 0; | |
234 | |
235 // the handle mark links itself to last_handle_mark | |
10135 | 236 new HandleMark(this); |
237 | |
0 | 238 // plain initialization |
239 debug_only(_owned_locks = NULL;) | |
240 debug_only(_allow_allocation_count = 0;) | |
241 NOT_PRODUCT(_allow_safepoint_count = 0;) | |
806
821269eca479
6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents:
702
diff
changeset
|
242 NOT_PRODUCT(_skip_gcalot = false;) |
0 | 243 CHECK_UNHANDLED_OOPS_ONLY(_gc_locked_out_count = 0;) |
244 _jvmti_env_iteration_count = 0; | |
2100
b1a2afa37ec4
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis
phh
parents:
2014
diff
changeset
|
245 set_allocated_bytes(0); |
0 | 246 _vm_operation_started_count = 0; |
247 _vm_operation_completed_count = 0; | |
248 _current_pending_monitor = NULL; | |
249 _current_pending_monitor_is_from_java = true; | |
250 _current_waiting_monitor = NULL; | |
251 _num_nested_signal = 0; | |
252 omFreeList = NULL ; | |
253 omFreeCount = 0 ; | |
254 omFreeProvision = 32 ; | |
1587 | 255 omInUseList = NULL ; |
256 omInUseCount = 0 ; | |
0 | 257 |
5928
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
258 #ifdef ASSERT |
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
259 _visited_for_critical_count = false; |
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
260 #endif |
541c4a5e7b88
7150390: JFR test crashed on assert(_jni_lock_count == count) failed: must be equal
never
parents:
4932
diff
changeset
|
261 |
0 | 262 _SR_lock = new Monitor(Mutex::suspend_resume, "SR_lock", true); |
263 _suspend_flags = 0; | |
264 | |
265 // thread-specific hashCode stream generator state - Marsaglia shift-xor form | |
266 _hashStateX = os::random() ; | |
267 _hashStateY = 842502087 ; | |
268 _hashStateZ = 0x8767 ; // (int)(3579807591LL & 0xffff) ; | |
269 _hashStateW = 273326509 ; | |
270 | |
271 _OnTrap = 0 ; | |
272 _schedctl = NULL ; | |
273 _Stalled = 0 ; | |
274 _TypeTag = 0x2BAD ; | |
275 | |
276 // Many of the following fields are effectively final - immutable | |
277 // Note that nascent threads can't use the Native Monitor-Mutex | |
278 // construct until the _MutexEvent is initialized ... | |
279 // CONSIDER: instead of using a fixed set of purpose-dedicated ParkEvents | |
280 // we might instead use a stack of ParkEvents that we could provision on-demand. | |
281 // The stack would act as a cache to avoid calls to ParkEvent::Allocate() | |
282 // and ::Release() | |
283 _ParkEvent = ParkEvent::Allocate (this) ; | |
284 _SleepEvent = ParkEvent::Allocate (this) ; | |
285 _MutexEvent = ParkEvent::Allocate (this) ; | |
286 _MuxEvent = ParkEvent::Allocate (this) ; | |
287 | |
288 #ifdef CHECK_UNHANDLED_OOPS | |
289 if (CheckUnhandledOops) { | |
290 _unhandled_oops = new UnhandledOops(this); | |
291 } | |
292 #endif // CHECK_UNHANDLED_OOPS | |
293 #ifdef ASSERT | |
294 if (UseBiasedLocking) { | |
295 assert((((uintptr_t) this) & (markOopDesc::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed"); | |
296 assert(this == _real_malloc_address || | |
297 this == (void*) align_size_up((intptr_t) _real_malloc_address, markOopDesc::biased_lock_alignment), | |
298 "bug in forced alignment of thread objects"); | |
299 } | |
300 #endif /* ASSERT */ | |
301 } | |
302 | |
303 void Thread::initialize_thread_local_storage() { | |
304 // Note: Make sure this method only calls | |
305 // non-blocking operations. Otherwise, it might not work | |
306 // with the thread-startup/safepoint interaction. | |
307 | |
308 // During Java thread startup, safepoint code should allow this | |
309 // method to complete because it may need to allocate memory to | |
310 // store information for the new thread. | |
311 | |
312 // initialize structure dependent on thread local storage | |
313 ThreadLocalStorage::set_thread(this); | |
314 } | |
315 | |
316 void Thread::record_stack_base_and_size() { | |
317 set_stack_base(os::current_stack_base()); | |
318 set_stack_size(os::current_stack_size()); | |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
319 // CR 7190089: on Solaris, primordial thread's stack is adjusted |
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
320 // in initialize_thread(). Without the adjustment, stack size is |
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
321 // incorrect if stack is set to unlimited (ulimit -s unlimited). |
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
322 // So far, only Solaris has real implementation of initialize_thread(). |
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
323 // |
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
324 // set up any platform-specific state. |
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
325 os::initialize_thread(this); |
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
326 |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
327 #if INCLUDE_NMT |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
328 // record thread's native stack, stack grows downward |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
329 address stack_low_addr = stack_base() - stack_size(); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
330 MemTracker::record_thread_stack(stack_low_addr, stack_size(), this, |
6768
716e6ef4482a
7190089: NMT ON: NMT failed assertion on thread's stack base address
zgu
parents:
6745
diff
changeset
|
331 CURRENT_PC); |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
332 #endif // INCLUDE_NMT |
0 | 333 } |
334 | |
335 | |
336 Thread::~Thread() { | |
337 // Reclaim the objectmonitors from the omFreeList of the moribund thread. | |
338 ObjectSynchronizer::omFlush (this) ; | |
339 | |
12205
623d923529df
8021353: Event based tracing is missing thread exit
mgronlun
parents:
12117
diff
changeset
|
340 EVENT_THREAD_DESTRUCT(this); |
623d923529df
8021353: Event based tracing is missing thread exit
mgronlun
parents:
12117
diff
changeset
|
341 |
6745
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
342 // stack_base can be NULL if the thread is never started or exited before |
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
343 // record_stack_base_and_size called. Although, we would like to ensure |
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
344 // that all started threads do call record_stack_base_and_size(), there is |
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
345 // not proper way to enforce that. |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
346 #if INCLUDE_NMT |
6745
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
347 if (_stack_base != NULL) { |
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
348 address low_stack_addr = stack_base() - stack_size(); |
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
349 MemTracker::release_thread_stack(low_stack_addr, stack_size(), this); |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
350 #ifdef ASSERT |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
351 set_stack_base(NULL); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
352 #endif |
6745
6dfc6a541338
7198529: NPG: assert with NMT code in Thread destructor
zgu
parents:
6741
diff
changeset
|
353 } |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
354 #endif // INCLUDE_NMT |
6197 | 355 |
0 | 356 // deallocate data structures |
357 delete resource_area(); | |
358 // since the handle marks are using the handle area, we have to deallocated the root | |
359 // handle mark before deallocating the thread's handle area, | |
360 assert(last_handle_mark() != NULL, "check we have an element"); | |
10135 | 361 delete last_handle_mark(); |
362 assert(last_handle_mark() == NULL, "check we have reached the end"); | |
0 | 363 |
364 // It's possible we can encounter a null _ParkEvent, etc., in stillborn threads. | |
365 // We NULL out the fields for good hygiene. | |
366 ParkEvent::Release (_ParkEvent) ; _ParkEvent = NULL ; | |
367 ParkEvent::Release (_SleepEvent) ; _SleepEvent = NULL ; | |
368 ParkEvent::Release (_MutexEvent) ; _MutexEvent = NULL ; | |
369 ParkEvent::Release (_MuxEvent) ; _MuxEvent = NULL ; | |
370 | |
371 delete handle_area(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
372 delete metadata_handles(); |
0 | 373 |
374 // osthread() can be NULL, if creation of thread failed. | |
375 if (osthread() != NULL) os::free_thread(osthread()); | |
376 | |
377 delete _SR_lock; | |
378 | |
379 // clear thread local storage if the Thread is deleting itself | |
380 if (this == Thread::current()) { | |
381 ThreadLocalStorage::set_thread(NULL); | |
382 } else { | |
383 // In the case where we're not the current thread, invalidate all the | |
384 // caches in case some code tries to get the current thread or the | |
385 // thread that was destroyed, and gets stale information. | |
386 ThreadLocalStorage::invalidate_all(); | |
387 } | |
388 CHECK_UNHANDLED_OOPS_ONLY(if (CheckUnhandledOops) delete unhandled_oops();) | |
389 } | |
390 | |
391 // NOTE: dummy function for assertion purpose. | |
392 void Thread::run() { | |
393 ShouldNotReachHere(); | |
394 } | |
395 | |
396 #ifdef ASSERT | |
397 // Private method to check for dangling thread pointer | |
398 void check_for_dangling_thread_pointer(Thread *thread) { | |
399 assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(), | |
400 "possibility of dangling Thread pointer"); | |
401 } | |
402 #endif | |
403 | |
404 | |
405 #ifndef PRODUCT | |
406 // Tracing method for basic thread operations | |
407 void Thread::trace(const char* msg, const Thread* const thread) { | |
408 if (!TraceThreadEvents) return; | |
409 ResourceMark rm; | |
410 ThreadCritical tc; | |
411 const char *name = "non-Java thread"; | |
412 int prio = -1; | |
413 if (thread->is_Java_thread() | |
414 && !thread->is_Compiler_thread()) { | |
415 // The Threads_lock must be held to get information about | |
416 // this thread but may not be in some situations when | |
417 // tracing thread events. | |
418 bool release_Threads_lock = false; | |
419 if (!Threads_lock->owned_by_self()) { | |
420 Threads_lock->lock(); | |
421 release_Threads_lock = true; | |
422 } | |
423 JavaThread* jt = (JavaThread *)thread; | |
424 name = (char *)jt->get_thread_name(); | |
425 oop thread_oop = jt->threadObj(); | |
426 if (thread_oop != NULL) { | |
427 prio = java_lang_Thread::priority(thread_oop); | |
428 } | |
429 if (release_Threads_lock) { | |
430 Threads_lock->unlock(); | |
431 } | |
432 } | |
433 tty->print_cr("Thread::%s " INTPTR_FORMAT " [%lx] %s (prio: %d)", msg, thread, thread->osthread()->thread_id(), name, prio); | |
434 } | |
435 #endif | |
436 | |
437 | |
438 ThreadPriority Thread::get_priority(const Thread* const thread) { | |
439 trace("get priority", thread); | |
440 ThreadPriority priority; | |
441 // Can return an error! | |
442 (void)os::get_priority(thread, priority); | |
443 assert(MinPriority <= priority && priority <= MaxPriority, "non-Java priority found"); | |
444 return priority; | |
445 } | |
446 | |
447 void Thread::set_priority(Thread* thread, ThreadPriority priority) { | |
448 trace("set priority", thread); | |
449 debug_only(check_for_dangling_thread_pointer(thread);) | |
450 // Can return an error! | |
451 (void)os::set_priority(thread, priority); | |
452 } | |
453 | |
454 | |
455 void Thread::start(Thread* thread) { | |
456 trace("start", thread); | |
457 // Start is different from resume in that its safety is guaranteed by context or | |
458 // being called from a Java method synchronized on the Thread object. | |
459 if (!DisableStartThread) { | |
460 if (thread->is_Java_thread()) { | |
461 // Initialize the thread state to RUNNABLE before starting this thread. | |
462 // Can not set it after the thread started because we do not know the | |
463 // exact thread state at that time. It could be in MONITOR_WAIT or | |
464 // in SLEEPING or some other state. | |
465 java_lang_Thread::set_thread_status(((JavaThread*)thread)->threadObj(), | |
466 java_lang_Thread::RUNNABLE); | |
467 } | |
468 os::start_thread(thread); | |
469 } | |
470 } | |
471 | |
472 // Enqueue a VM_Operation to do the job for us - sometime later | |
473 void Thread::send_async_exception(oop java_thread, oop java_throwable) { | |
474 VM_ThreadStop* vm_stop = new VM_ThreadStop(java_thread, java_throwable); | |
475 VMThread::execute(vm_stop); | |
476 } | |
477 | |
478 | |
479 // | |
480 // Check if an external suspend request has completed (or has been | |
481 // cancelled). Returns true if the thread is externally suspended and | |
482 // false otherwise. | |
483 // | |
484 // The bits parameter returns information about the code path through | |
485 // the routine. Useful for debugging: | |
486 // | |
487 // set in is_ext_suspend_completed(): | |
488 // 0x00000001 - routine was entered | |
489 // 0x00000010 - routine return false at end | |
490 // 0x00000100 - thread exited (return false) | |
491 // 0x00000200 - suspend request cancelled (return false) | |
492 // 0x00000400 - thread suspended (return true) | |
493 // 0x00001000 - thread is in a suspend equivalent state (return true) | |
494 // 0x00002000 - thread is native and walkable (return true) | |
495 // 0x00004000 - thread is native_trans and walkable (needed retry) | |
496 // | |
497 // set in wait_for_ext_suspend_completion(): | |
498 // 0x00010000 - routine was entered | |
499 // 0x00020000 - suspend request cancelled before loop (return false) | |
500 // 0x00040000 - thread suspended before loop (return true) | |
501 // 0x00080000 - suspend request cancelled in loop (return false) | |
502 // 0x00100000 - thread suspended in loop (return true) | |
503 // 0x00200000 - suspend not completed during retry loop (return false) | |
504 // | |
505 | |
506 // Helper class for tracing suspend wait debug bits. | |
507 // | |
508 // 0x00000100 indicates that the target thread exited before it could | |
509 // self-suspend which is not a wait failure. 0x00000200, 0x00020000 and | |
510 // 0x00080000 each indicate a cancelled suspend request so they don't | |
511 // count as wait failures either. | |
512 #define DEBUG_FALSE_BITS (0x00000010 | 0x00200000) | |
513 | |
514 class TraceSuspendDebugBits : public StackObj { | |
515 private: | |
516 JavaThread * jt; | |
517 bool is_wait; | |
518 bool called_by_wait; // meaningful when !is_wait | |
519 uint32_t * bits; | |
520 | |
521 public: | |
522 TraceSuspendDebugBits(JavaThread *_jt, bool _is_wait, bool _called_by_wait, | |
523 uint32_t *_bits) { | |
524 jt = _jt; | |
525 is_wait = _is_wait; | |
526 called_by_wait = _called_by_wait; | |
527 bits = _bits; | |
528 } | |
529 | |
530 ~TraceSuspendDebugBits() { | |
531 if (!is_wait) { | |
532 #if 1 | |
533 // By default, don't trace bits for is_ext_suspend_completed() calls. | |
534 // That trace is very chatty. | |
535 return; | |
536 #else | |
537 if (!called_by_wait) { | |
538 // If tracing for is_ext_suspend_completed() is enabled, then only | |
539 // trace calls to it from wait_for_ext_suspend_completion() | |
540 return; | |
541 } | |
542 #endif | |
543 } | |
544 | |
545 if (AssertOnSuspendWaitFailure || TraceSuspendWaitFailures) { | |
546 if (bits != NULL && (*bits & DEBUG_FALSE_BITS) != 0) { | |
547 MutexLocker ml(Threads_lock); // needed for get_thread_name() | |
548 ResourceMark rm; | |
549 | |
550 tty->print_cr( | |
551 "Failed wait_for_ext_suspend_completion(thread=%s, debug_bits=%x)", | |
552 jt->get_thread_name(), *bits); | |
553 | |
554 guarantee(!AssertOnSuspendWaitFailure, "external suspend wait failed"); | |
555 } | |
556 } | |
557 } | |
558 }; | |
559 #undef DEBUG_FALSE_BITS | |
560 | |
561 | |
562 bool JavaThread::is_ext_suspend_completed(bool called_by_wait, int delay, uint32_t *bits) { | |
563 TraceSuspendDebugBits tsdb(this, false /* !is_wait */, called_by_wait, bits); | |
564 | |
565 bool did_trans_retry = false; // only do thread_in_native_trans retry once | |
566 bool do_trans_retry; // flag to force the retry | |
567 | |
568 *bits |= 0x00000001; | |
569 | |
570 do { | |
571 do_trans_retry = false; | |
572 | |
573 if (is_exiting()) { | |
574 // Thread is in the process of exiting. This is always checked | |
575 // first to reduce the risk of dereferencing a freed JavaThread. | |
576 *bits |= 0x00000100; | |
577 return false; | |
578 } | |
579 | |
580 if (!is_external_suspend()) { | |
581 // Suspend request is cancelled. This is always checked before | |
582 // is_ext_suspended() to reduce the risk of a rogue resume | |
583 // confusing the thread that made the suspend request. | |
584 *bits |= 0x00000200; | |
585 return false; | |
586 } | |
587 | |
588 if (is_ext_suspended()) { | |
589 // thread is suspended | |
590 *bits |= 0x00000400; | |
591 return true; | |
592 } | |
593 | |
594 // Now that we no longer do hard suspends of threads running | |
595 // native code, the target thread can be changing thread state | |
596 // while we are in this routine: | |
597 // | |
598 // _thread_in_native -> _thread_in_native_trans -> _thread_blocked | |
599 // | |
600 // We save a copy of the thread state as observed at this moment | |
601 // and make our decision about suspend completeness based on the | |
602 // copy. This closes the race where the thread state is seen as | |
603 // _thread_in_native_trans in the if-thread_blocked check, but is | |
604 // seen as _thread_blocked in if-thread_in_native_trans check. | |
605 JavaThreadState save_state = thread_state(); | |
606 | |
607 if (save_state == _thread_blocked && is_suspend_equivalent()) { | |
608 // If the thread's state is _thread_blocked and this blocking | |
609 // condition is known to be equivalent to a suspend, then we can | |
610 // consider the thread to be externally suspended. This means that | |
611 // the code that sets _thread_blocked has been modified to do | |
612 // self-suspension if the blocking condition releases. We also | |
613 // used to check for CONDVAR_WAIT here, but that is now covered by | |
614 // the _thread_blocked with self-suspension check. | |
615 // | |
616 // Return true since we wouldn't be here unless there was still an | |
617 // external suspend request. | |
618 *bits |= 0x00001000; | |
619 return true; | |
620 } else if (save_state == _thread_in_native && frame_anchor()->walkable()) { | |
621 // Threads running native code will self-suspend on native==>VM/Java | |
622 // transitions. If its stack is walkable (should always be the case | |
623 // unless this function is called before the actual java_suspend() | |
624 // call), then the wait is done. | |
625 *bits |= 0x00002000; | |
626 return true; | |
627 } else if (!called_by_wait && !did_trans_retry && | |
628 save_state == _thread_in_native_trans && | |
629 frame_anchor()->walkable()) { | |
630 // The thread is transitioning from thread_in_native to another | |
631 // thread state. check_safepoint_and_suspend_for_native_trans() | |
632 // will force the thread to self-suspend. If it hasn't gotten | |
633 // there yet we may have caught the thread in-between the native | |
634 // code check above and the self-suspend. Lucky us. If we were | |
635 // called by wait_for_ext_suspend_completion(), then it | |
636 // will be doing the retries so we don't have to. | |
637 // | |
638 // Since we use the saved thread state in the if-statement above, | |
639 // there is a chance that the thread has already transitioned to | |
640 // _thread_blocked by the time we get here. In that case, we will | |
641 // make a single unnecessary pass through the logic below. This | |
642 // doesn't hurt anything since we still do the trans retry. | |
643 | |
644 *bits |= 0x00004000; | |
645 | |
646 // Once the thread leaves thread_in_native_trans for another | |
647 // thread state, we break out of this retry loop. We shouldn't | |
648 // need this flag to prevent us from getting back here, but | |
649 // sometimes paranoia is good. | |
650 did_trans_retry = true; | |
651 | |
652 // We wait for the thread to transition to a more usable state. | |
653 for (int i = 1; i <= SuspendRetryCount; i++) { | |
654 // We used to do an "os::yield_all(i)" call here with the intention | |
655 // that yielding would increase on each retry. However, the parameter | |
656 // is ignored on Linux which means the yield didn't scale up. Waiting | |
657 // on the SR_lock below provides a much more predictable scale up for | |
658 // the delay. It also provides a simple/direct point to check for any | |
659 // safepoint requests from the VMThread | |
660 | |
661 // temporarily drops SR_lock while doing wait with safepoint check | |
662 // (if we're a JavaThread - the WatcherThread can also call this) | |
663 // and increase delay with each retry | |
664 SR_lock()->wait(!Thread::current()->is_Java_thread(), i * delay); | |
665 | |
666 // check the actual thread state instead of what we saved above | |
667 if (thread_state() != _thread_in_native_trans) { | |
668 // the thread has transitioned to another thread state so | |
669 // try all the checks (except this one) one more time. | |
670 do_trans_retry = true; | |
671 break; | |
672 } | |
673 } // end retry loop | |
674 | |
675 | |
676 } | |
677 } while (do_trans_retry); | |
678 | |
679 *bits |= 0x00000010; | |
680 return false; | |
681 } | |
682 | |
683 // | |
684 // Wait for an external suspend request to complete (or be cancelled). | |
685 // Returns true if the thread is externally suspended and false otherwise. | |
686 // | |
687 bool JavaThread::wait_for_ext_suspend_completion(int retries, int delay, | |
688 uint32_t *bits) { | |
689 TraceSuspendDebugBits tsdb(this, true /* is_wait */, | |
690 false /* !called_by_wait */, bits); | |
691 | |
692 // local flag copies to minimize SR_lock hold time | |
693 bool is_suspended; | |
694 bool pending; | |
695 uint32_t reset_bits; | |
696 | |
697 // set a marker so is_ext_suspend_completed() knows we are the caller | |
698 *bits |= 0x00010000; | |
699 | |
700 // We use reset_bits to reinitialize the bits value at the top of | |
701 // each retry loop. This allows the caller to make use of any | |
702 // unused bits for their own marking purposes. | |
703 reset_bits = *bits; | |
704 | |
705 { | |
706 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
707 is_suspended = is_ext_suspend_completed(true /* called_by_wait */, | |
708 delay, bits); | |
709 pending = is_external_suspend(); | |
710 } | |
711 // must release SR_lock to allow suspension to complete | |
712 | |
713 if (!pending) { | |
714 // A cancelled suspend request is the only false return from | |
715 // is_ext_suspend_completed() that keeps us from entering the | |
716 // retry loop. | |
717 *bits |= 0x00020000; | |
718 return false; | |
719 } | |
720 | |
721 if (is_suspended) { | |
722 *bits |= 0x00040000; | |
723 return true; | |
724 } | |
725 | |
726 for (int i = 1; i <= retries; i++) { | |
727 *bits = reset_bits; // reinit to only track last retry | |
728 | |
729 // We used to do an "os::yield_all(i)" call here with the intention | |
730 // that yielding would increase on each retry. However, the parameter | |
731 // is ignored on Linux which means the yield didn't scale up. Waiting | |
732 // on the SR_lock below provides a much more predictable scale up for | |
733 // the delay. It also provides a simple/direct point to check for any | |
734 // safepoint requests from the VMThread | |
735 | |
736 { | |
737 MutexLocker ml(SR_lock()); | |
738 // wait with safepoint check (if we're a JavaThread - the WatcherThread | |
739 // can also call this) and increase delay with each retry | |
740 SR_lock()->wait(!Thread::current()->is_Java_thread(), i * delay); | |
741 | |
742 is_suspended = is_ext_suspend_completed(true /* called_by_wait */, | |
743 delay, bits); | |
744 | |
745 // It is possible for the external suspend request to be cancelled | |
746 // (by a resume) before the actual suspend operation is completed. | |
747 // Refresh our local copy to see if we still need to wait. | |
748 pending = is_external_suspend(); | |
749 } | |
750 | |
751 if (!pending) { | |
752 // A cancelled suspend request is the only false return from | |
753 // is_ext_suspend_completed() that keeps us from staying in the | |
754 // retry loop. | |
755 *bits |= 0x00080000; | |
756 return false; | |
757 } | |
758 | |
759 if (is_suspended) { | |
760 *bits |= 0x00100000; | |
761 return true; | |
762 } | |
763 } // end retry loop | |
764 | |
765 // thread did not suspend after all our retries | |
766 *bits |= 0x00200000; | |
767 return false; | |
768 } | |
769 | |
770 #ifndef PRODUCT | |
771 void JavaThread::record_jump(address target, address instr, const char* file, int line) { | |
772 | |
773 // This should not need to be atomic as the only way for simultaneous | |
14909 | 774 // updates is via interrupts. Even then this should be rare or non-existant |
0 | 775 // and we don't care that much anyway. |
776 | |
777 int index = _jmp_ring_index; | |
778 _jmp_ring_index = (index + 1 ) & (jump_ring_buffer_size - 1); | |
779 _jmp_ring[index]._target = (intptr_t) target; | |
780 _jmp_ring[index]._instruction = (intptr_t) instr; | |
781 _jmp_ring[index]._file = file; | |
782 _jmp_ring[index]._line = line; | |
783 } | |
784 #endif /* PRODUCT */ | |
785 | |
786 // Called by flat profiler | |
787 // Callers have already called wait_for_ext_suspend_completion | |
788 // The assertion for that is currently too complex to put here: | |
789 bool JavaThread::profile_last_Java_frame(frame* _fr) { | |
790 bool gotframe = false; | |
791 // self suspension saves needed state. | |
792 if (has_last_Java_frame() && _anchor.walkable()) { | |
793 *_fr = pd_last_frame(); | |
794 gotframe = true; | |
795 } | |
796 return gotframe; | |
797 } | |
798 | |
799 void Thread::interrupt(Thread* thread) { | |
800 trace("interrupt", thread); | |
801 debug_only(check_for_dangling_thread_pointer(thread);) | |
802 os::interrupt(thread); | |
803 } | |
804 | |
805 bool Thread::is_interrupted(Thread* thread, bool clear_interrupted) { | |
806 trace("is_interrupted", thread); | |
807 debug_only(check_for_dangling_thread_pointer(thread);) | |
808 // Note: If clear_interrupted==false, this simply fetches and | |
809 // returns the value of the field osthread()->interrupted(). | |
810 return os::is_interrupted(thread, clear_interrupted); | |
811 } | |
812 | |
813 | |
814 // GC Support | |
815 bool Thread::claim_oops_do_par_case(int strong_roots_parity) { | |
816 jint thread_parity = _oops_do_parity; | |
817 if (thread_parity != strong_roots_parity) { | |
818 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
819 if (res == thread_parity) { |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
820 return true; |
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
821 } else { |
0 | 822 guarantee(res == strong_roots_parity, "Or else what?"); |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
823 assert(SharedHeap::heap()->workers()->active_workers() > 0, |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
824 "Should only fail when parallel."); |
0 | 825 return false; |
826 } | |
827 } | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
828 assert(SharedHeap::heap()->workers()->active_workers() > 0, |
0 | 829 "Should only fail when parallel."); |
830 return false; | |
831 } | |
832 | |
14909 | 833 void Thread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
0 | 834 active_handles()->oops_do(f); |
835 // Do oop for ThreadShadow | |
836 f->do_oop((oop*)&_pending_exception); | |
13644
e0102f250d76
Guard processing of _pending_failed_speculation with #ifdef GRAAL in Thread::oops_do
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13641
diff
changeset
|
837 #ifdef GRAAL |
13641
5a9afbf72714
Add a speculation oop for uncommon trap deoptimization. Save it in the SpeculationLog during deoptimization.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13188
diff
changeset
|
838 f->do_oop((oop*)&_pending_failed_speculation); |
13644
e0102f250d76
Guard processing of _pending_failed_speculation with #ifdef GRAAL in Thread::oops_do
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
13641
diff
changeset
|
839 #endif |
0 | 840 handle_area()->oops_do(f); |
841 } | |
842 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
843 void Thread::nmethods_do(CodeBlobClosure* cf) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
844 // no nmethods in a generic thread... |
0 | 845 } |
846 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
847 void Thread::metadata_do(void f(Metadata*)) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
848 if (metadata_handles() != NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
849 for (int i = 0; i< metadata_handles()->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
850 f(metadata_handles()->at(i)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
851 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
852 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
853 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
854 |
0 | 855 void Thread::print_on(outputStream* st) const { |
856 // get_priority assumes osthread initialized | |
857 if (osthread() != NULL) { | |
6766 | 858 int os_prio; |
859 if (os::get_native_priority(this, &os_prio) == OS_OK) { | |
860 st->print("os_prio=%d ", os_prio); | |
861 } | |
862 st->print("tid=" INTPTR_FORMAT " ", this); | |
0 | 863 osthread()->print_on(st); |
864 } | |
865 debug_only(if (WizardMode) print_owned_locks_on(st);) | |
866 } | |
867 | |
868 // Thread::print_on_error() is called by fatal error handler. Don't use | |
869 // any lock or allocate memory. | |
870 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const { | |
871 if (is_VM_thread()) st->print("VMThread"); | |
872 else if (is_Compiler_thread()) st->print("CompilerThread"); | |
873 else if (is_Java_thread()) st->print("JavaThread"); | |
874 else if (is_GC_task_thread()) st->print("GCTaskThread"); | |
875 else if (is_Watcher_thread()) st->print("WatcherThread"); | |
876 else if (is_ConcurrentGC_thread()) st->print("ConcurrentGCThread"); | |
877 else st->print("Thread"); | |
878 | |
879 st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]", | |
880 _stack_base - _stack_size, _stack_base); | |
881 | |
882 if (osthread()) { | |
883 st->print(" [id=%d]", osthread()->thread_id()); | |
884 } | |
885 } | |
886 | |
887 #ifdef ASSERT | |
888 void Thread::print_owned_locks_on(outputStream* st) const { | |
889 Monitor *cur = _owned_locks; | |
890 if (cur == NULL) { | |
891 st->print(" (no locks) "); | |
892 } else { | |
893 st->print_cr(" Locks owned:"); | |
894 while(cur) { | |
895 cur->print_on(st); | |
896 cur = cur->next(); | |
897 } | |
898 } | |
899 } | |
900 | |
901 static int ref_use_count = 0; | |
902 | |
903 bool Thread::owns_locks_but_compiled_lock() const { | |
904 for(Monitor *cur = _owned_locks; cur; cur = cur->next()) { | |
905 if (cur != Compile_lock) return true; | |
906 } | |
907 return false; | |
908 } | |
909 | |
910 | |
911 #endif | |
912 | |
913 #ifndef PRODUCT | |
914 | |
915 // The flag: potential_vm_operation notifies if this particular safepoint state could potential | |
916 // invoke the vm-thread (i.e., and oop allocation). In that case, we also have to make sure that | |
917 // no threads which allow_vm_block's are held | |
918 void Thread::check_for_valid_safepoint_state(bool potential_vm_operation) { | |
919 // Check if current thread is allowed to block at a safepoint | |
920 if (!(_allow_safepoint_count == 0)) | |
921 fatal("Possible safepoint reached by thread that does not allow it"); | |
922 if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) { | |
923 fatal("LEAF method calling lock?"); | |
924 } | |
925 | |
926 #ifdef ASSERT | |
927 if (potential_vm_operation && is_Java_thread() | |
928 && !Universe::is_bootstrapping()) { | |
929 // Make sure we do not hold any locks that the VM thread also uses. | |
930 // This could potentially lead to deadlocks | |
931 for(Monitor *cur = _owned_locks; cur; cur = cur->next()) { | |
932 // Threads_lock is special, since the safepoint synchronization will not start before this is | |
933 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock, | |
934 // since it is used to transfer control between JavaThreads and the VMThread | |
14909 | 935 // Do not *exclude* any locks unless you are absolutly sure it is correct. Ask someone else first! |
0 | 936 if ( (cur->allow_vm_block() && |
937 cur != Threads_lock && | |
14909 | 938 cur != Compile_lock && // Temporary: should not be necessary when we get spearate compilation |
0 | 939 cur != VMOperationRequest_lock && |
940 cur != VMOperationQueue_lock) || | |
941 cur->rank() == Mutex::special) { | |
14726
92aa6797d639
Backed out merge changeset: b51e29501f30
Doug Simon <doug.simon@oracle.com>
parents:
14704
diff
changeset
|
942 warning("Thread holding lock at safepoint that vm can block on: %s", cur->name()); |
0 | 943 } |
944 } | |
945 } | |
946 | |
947 if (GCALotAtAllSafepoints) { | |
948 // We could enter a safepoint here and thus have a gc | |
949 InterfaceSupport::check_gc_alot(); | |
950 } | |
951 #endif | |
952 } | |
953 #endif | |
954 | |
955 bool Thread::is_in_stack(address adr) const { | |
956 assert(Thread::current() == this, "is_in_stack can only be called from current thread"); | |
957 address end = os::current_stack_pointer(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
958 // Allow non Java threads to call this without stack_base |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
959 if (_stack_base == NULL) return true; |
0 | 960 if (stack_base() >= adr && adr >= end) return true; |
961 | |
962 return false; | |
963 } | |
964 | |
965 | |
11146
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
966 bool Thread::is_in_usable_stack(address adr) const { |
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
967 size_t stack_guard_size = os::uses_stack_guard_pages() ? (StackYellowPages + StackRedPages) * os::vm_page_size() : 0; |
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
968 size_t usable_stack_size = _stack_size - stack_guard_size; |
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
969 |
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
970 return ((adr < stack_base()) && (adr >= stack_base() - usable_stack_size)); |
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
971 } |
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
972 |
e619a2766bcc
8016131: nsk/sysdict/vm/stress/chain tests crash the VM in 'entry_frame_is_first()'
rbackman
parents:
11139
diff
changeset
|
973 |
0 | 974 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter |
975 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being | |
976 // used for compilation in the future. If that change is made, the need for these methods | |
977 // should be revisited, and they should be removed if possible. | |
978 | |
979 bool Thread::is_lock_owned(address adr) const { | |
1688
2dfd013a7465
6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents:
1608
diff
changeset
|
980 return on_local_stack(adr); |
0 | 981 } |
982 | |
983 bool Thread::set_as_starting_thread() { | |
984 // NOTE: this must be called inside the main thread. | |
985 return os::create_main_thread((JavaThread*)this); | |
986 } | |
987 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
988 static void initialize_class(Symbol* class_name, TRAPS) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
989 Klass* klass = SystemDictionary::resolve_or_fail(class_name, true, CHECK); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
990 InstanceKlass::cast(klass)->initialize(CHECK); |
0 | 991 } |
992 | |
993 | |
994 // Creates the initial ThreadGroup | |
995 static Handle create_initial_thread_group(TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
996 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ThreadGroup(), true, CHECK_NH); |
0 | 997 instanceKlassHandle klass (THREAD, k); |
998 | |
999 Handle system_instance = klass->allocate_instance_handle(CHECK_NH); | |
1000 { | |
1001 JavaValue result(T_VOID); | |
1002 JavaCalls::call_special(&result, | |
1003 system_instance, | |
1004 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1005 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1006 vmSymbols::void_method_signature(), |
0 | 1007 CHECK_NH); |
1008 } | |
1009 Universe::set_system_thread_group(system_instance()); | |
1010 | |
1011 Handle main_instance = klass->allocate_instance_handle(CHECK_NH); | |
1012 { | |
1013 JavaValue result(T_VOID); | |
1014 Handle string = java_lang_String::create_from_str("main", CHECK_NH); | |
1015 JavaCalls::call_special(&result, | |
1016 main_instance, | |
1017 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1018 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1019 vmSymbols::threadgroup_string_void_signature(), |
0 | 1020 system_instance, |
1021 string, | |
1022 CHECK_NH); | |
1023 } | |
1024 return main_instance; | |
1025 } | |
1026 | |
1027 // Creates the initial Thread | |
1028 static oop create_initial_thread(Handle thread_group, JavaThread* thread, TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
1029 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL); |
0 | 1030 instanceKlassHandle klass (THREAD, k); |
1031 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL); | |
1032 | |
1033 java_lang_Thread::set_thread(thread_oop(), thread); | |
1034 java_lang_Thread::set_priority(thread_oop(), NormPriority); | |
1035 thread->set_threadObj(thread_oop()); | |
1036 | |
1037 Handle string = java_lang_String::create_from_str("main", CHECK_NULL); | |
1038 | |
1039 JavaValue result(T_VOID); | |
1040 JavaCalls::call_special(&result, thread_oop, | |
1041 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1042 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1043 vmSymbols::threadgroup_string_void_signature(), |
0 | 1044 thread_group, |
1045 string, | |
1046 CHECK_NULL); | |
1047 return thread_oop(); | |
1048 } | |
1049 | |
1050 static void call_initializeSystemClass(TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
1051 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK); |
0 | 1052 instanceKlassHandle klass (THREAD, k); |
1053 | |
1054 JavaValue result(T_VOID); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1055 JavaCalls::call_static(&result, klass, vmSymbols::initializeSystemClass_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1056 vmSymbols::void_method_signature(), CHECK); |
0 | 1057 } |
1058 | |
6181 | 1059 char java_runtime_name[128] = ""; |
6921
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1060 char java_runtime_version[128] = ""; |
6181 | 1061 |
1062 // extract the JRE name from sun.misc.Version.java_runtime_name | |
1063 static const char* get_java_runtime_name(TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
1064 Klass* k = SystemDictionary::find(vmSymbols::sun_misc_Version(), |
6181 | 1065 Handle(), Handle(), CHECK_AND_CLEAR_NULL); |
1066 fieldDescriptor fd; | |
1067 bool found = k != NULL && | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
1068 InstanceKlass::cast(k)->find_local_field(vmSymbols::java_runtime_name_name(), |
6181 | 1069 vmSymbols::string_signature(), &fd); |
1070 if (found) { | |
1071 oop name_oop = k->java_mirror()->obj_field(fd.offset()); | |
1072 if (name_oop == NULL) | |
1073 return NULL; | |
1074 const char* name = java_lang_String::as_utf8_string(name_oop, | |
1075 java_runtime_name, | |
1076 sizeof(java_runtime_name)); | |
1077 return name; | |
1078 } else { | |
1079 return NULL; | |
1080 } | |
1081 } | |
1082 | |
6921
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1083 // extract the JRE version from sun.misc.Version.java_runtime_version |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1084 static const char* get_java_runtime_version(TRAPS) { |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1085 Klass* k = SystemDictionary::find(vmSymbols::sun_misc_Version(), |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1086 Handle(), Handle(), CHECK_AND_CLEAR_NULL); |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1087 fieldDescriptor fd; |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1088 bool found = k != NULL && |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1089 InstanceKlass::cast(k)->find_local_field(vmSymbols::java_runtime_version_name(), |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1090 vmSymbols::string_signature(), &fd); |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1091 if (found) { |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1092 oop name_oop = k->java_mirror()->obj_field(fd.offset()); |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1093 if (name_oop == NULL) |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1094 return NULL; |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1095 const char* name = java_lang_String::as_utf8_string(name_oop, |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1096 java_runtime_version, |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1097 sizeof(java_runtime_version)); |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1098 return name; |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1099 } else { |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1100 return NULL; |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1101 } |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1102 } |
a1b8cf9cf970
8002078: hs_err_pid file should report full JDK version string
sla
parents:
6882
diff
changeset
|
1103 |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1104 // General purpose hook into Java code, run once when the VM is initialized. |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1105 // The Java library method itself may be changed independently from the VM. |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1106 static void call_postVMInitHook(TRAPS) { |
13004
292050e5d5ea
8026877: Error in opening JAR file when invalid jar specified with -Xbootclasspath/a on OpenJDK build
dholmes
parents:
12880
diff
changeset
|
1107 Klass* k = SystemDictionary::resolve_or_null(vmSymbols::sun_misc_PostVMInitHook(), THREAD); |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1108 instanceKlassHandle klass (THREAD, k); |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1109 if (klass.not_null()) { |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1110 JavaValue result(T_VOID); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1111 JavaCalls::call_static(&result, klass, vmSymbols::run_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1112 vmSymbols::void_method_signature(), |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1113 CHECK); |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1114 } |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1115 } |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
1116 |
0 | 1117 static void reset_vm_info_property(TRAPS) { |
1118 // the vm info string | |
1119 ResourceMark rm(THREAD); | |
1120 const char *vm_info = VM_Version::vm_info_string(); | |
1121 | |
1122 // java.lang.System class | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
1123 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK); |
0 | 1124 instanceKlassHandle klass (THREAD, k); |
1125 | |
1126 // setProperty arguments | |
1127 Handle key_str = java_lang_String::create_from_str("java.vm.info", CHECK); | |
1128 Handle value_str = java_lang_String::create_from_str(vm_info, CHECK); | |
1129 | |
1130 // return value | |
1131 JavaValue r(T_OBJECT); | |
1132 | |
1133 // public static String setProperty(String key, String value); | |
1134 JavaCalls::call_static(&r, | |
1135 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1136 vmSymbols::setProperty_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1137 vmSymbols::string_string_string_signature(), |
0 | 1138 key_str, |
1139 value_str, | |
1140 CHECK); | |
1141 } | |
1142 | |
1143 | |
1144 void JavaThread::allocate_threadObj(Handle thread_group, char* thread_name, bool daemon, TRAPS) { | |
1145 assert(thread_group.not_null(), "thread group should be specified"); | |
1146 assert(threadObj() == NULL, "should only create Java thread object once"); | |
1147 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
1148 Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK); |
0 | 1149 instanceKlassHandle klass (THREAD, k); |
1150 instanceHandle thread_oop = klass->allocate_instance_handle(CHECK); | |
1151 | |
1152 java_lang_Thread::set_thread(thread_oop(), this); | |
1153 java_lang_Thread::set_priority(thread_oop(), NormPriority); | |
1154 set_threadObj(thread_oop()); | |
1155 | |
1156 JavaValue result(T_VOID); | |
1157 if (thread_name != NULL) { | |
1158 Handle name = java_lang_String::create_from_str(thread_name, CHECK); | |
1159 // Thread gets assigned specified name and null target | |
1160 JavaCalls::call_special(&result, | |
1161 thread_oop, | |
1162 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1163 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1164 vmSymbols::threadgroup_string_void_signature(), |
0 | 1165 thread_group, // Argument 1 |
1166 name, // Argument 2 | |
1167 THREAD); | |
1168 } else { | |
1169 // Thread gets assigned name "Thread-nnn" and null target | |
1170 // (java.lang.Thread doesn't have a constructor taking only a ThreadGroup argument) | |
1171 JavaCalls::call_special(&result, | |
1172 thread_oop, | |
1173 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1174 vmSymbols::object_initializer_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1175 vmSymbols::threadgroup_runnable_void_signature(), |
0 | 1176 thread_group, // Argument 1 |
1177 Handle(), // Argument 2 | |
1178 THREAD); | |
1179 } | |
1180 | |
1181 | |
1182 if (daemon) { | |
1183 java_lang_Thread::set_daemon(thread_oop()); | |
1184 } | |
1185 | |
1186 if (HAS_PENDING_EXCEPTION) { | |
1187 return; | |
1188 } | |
1189 | |
1142 | 1190 KlassHandle group(this, SystemDictionary::ThreadGroup_klass()); |
0 | 1191 Handle threadObj(this, this->threadObj()); |
1192 | |
1193 JavaCalls::call_special(&result, | |
1194 thread_group, | |
1195 group, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1196 vmSymbols::add_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1197 vmSymbols::thread_void_signature(), |
0 | 1198 threadObj, // Arg 1 |
1199 THREAD); | |
1200 | |
1201 | |
1202 } | |
1203 | |
1204 // NamedThread -- non-JavaThread subclasses with multiple | |
1205 // uniquely named instances should derive from this. | |
1206 NamedThread::NamedThread() : Thread() { | |
1207 _name = NULL; | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
1208 _processed_thread = NULL; |
0 | 1209 } |
1210 | |
1211 NamedThread::~NamedThread() { | |
1212 if (_name != NULL) { | |
6197 | 1213 FREE_C_HEAP_ARRAY(char, _name, mtThread); |
0 | 1214 _name = NULL; |
1215 } | |
1216 } | |
1217 | |
1218 void NamedThread::set_name(const char* format, ...) { | |
1219 guarantee(_name == NULL, "Only get to set name once."); | |
6197 | 1220 _name = NEW_C_HEAP_ARRAY(char, max_name_len, mtThread); |
0 | 1221 guarantee(_name != NULL, "alloc failure"); |
1222 va_list ap; | |
1223 va_start(ap, format); | |
1224 jio_vsnprintf(_name, max_name_len, format, ap); | |
1225 va_end(ap); | |
1226 } | |
1227 | |
1228 // ======= WatcherThread ======== | |
1229 | |
1230 // The watcher thread exists to simulate timer interrupts. It should | |
1231 // be replaced by an abstraction over whatever native support for | |
1232 // timer interrupts exists on the platform. | |
1233 | |
1234 WatcherThread* WatcherThread::_watcher_thread = NULL; | |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1235 bool WatcherThread::_startable = false; |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1236 volatile bool WatcherThread::_should_terminate = false; |
0 | 1237 |
11151 | 1238 WatcherThread::WatcherThread() : Thread(), _crash_protection(NULL) { |
0 | 1239 assert(watcher_thread() == NULL, "we can only allocate one WatcherThread"); |
1240 if (os::create_thread(this, os::watcher_thread)) { | |
1241 _watcher_thread = this; | |
1242 | |
1243 // Set the watcher thread to the highest OS priority which should not be | |
1244 // used, unless a Java thread with priority java.lang.Thread.MAX_PRIORITY | |
1245 // is created. The only normal thread using this priority is the reference | |
1246 // handler thread, which runs for very short intervals only. | |
1247 // If the VMThread's priority is not lower than the WatcherThread profiling | |
1248 // will be inaccurate. | |
1249 os::set_priority(this, MaxPriority); | |
1250 if (!DisableStartThread) { | |
1251 os::start_thread(this); | |
1252 } | |
1253 } | |
1254 } | |
1255 | |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1256 int WatcherThread::sleep() const { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1257 MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1258 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1259 // remaining will be zero if there are no tasks, |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1260 // causing the WatcherThread to sleep until a task is |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1261 // enrolled |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1262 int remaining = PeriodicTask::time_to_wait(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1263 int time_slept = 0; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1264 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1265 // we expect this to timeout - we only ever get unparked when |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1266 // we should terminate or when a new task has been enrolled |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1267 OSThreadWaitState osts(this->osthread(), false /* not Object.wait() */); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1268 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1269 jlong time_before_loop = os::javaTimeNanos(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1270 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1271 for (;;) { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1272 bool timedout = PeriodicTask_lock->wait(Mutex::_no_safepoint_check_flag, remaining); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1273 jlong now = os::javaTimeNanos(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1274 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1275 if (remaining == 0) { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1276 // if we didn't have any tasks we could have waited for a long time |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1277 // consider the time_slept zero and reset time_before_loop |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1278 time_slept = 0; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1279 time_before_loop = now; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1280 } else { |
14909 | 1281 // need to recalulate since we might have new tasks in _tasks |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1282 time_slept = (int) ((now - time_before_loop) / 1000000); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1283 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1284 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1285 // Change to task list or spurious wakeup of some kind |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1286 if (timedout || _should_terminate) { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1287 break; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1288 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1289 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1290 remaining = PeriodicTask::time_to_wait(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1291 if (remaining == 0) { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1292 // Last task was just disenrolled so loop around and wait until |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1293 // another task gets enrolled |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1294 continue; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1295 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1296 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1297 remaining -= time_slept; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1298 if (remaining <= 0) |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1299 break; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1300 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1301 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1302 return time_slept; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1303 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1304 |
0 | 1305 void WatcherThread::run() { |
1306 assert(this == watcher_thread(), "just checking"); | |
1307 | |
1308 this->record_stack_base_and_size(); | |
1309 this->initialize_thread_local_storage(); | |
1310 this->set_active_handles(JNIHandleBlock::allocate_block()); | |
1311 while(!_should_terminate) { | |
1312 assert(watcher_thread() == Thread::current(), "thread consistency check"); | |
1313 assert(watcher_thread() == this, "thread consistency check"); | |
1314 | |
1315 // Calculate how long it'll be until the next PeriodicTask work | |
1316 // should be done, and sleep that amount of time. | |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1317 int time_waited = sleep(); |
0 | 1318 |
1319 if (is_error_reported()) { | |
1320 // A fatal error has happened, the error handler(VMError::report_and_die) | |
1321 // should abort JVM after creating an error log file. However in some | |
1322 // rare cases, the error handler itself might deadlock. Here we try to | |
1323 // kill JVM if the fatal error handler fails to abort in 2 minutes. | |
1324 // | |
1325 // This code is in WatcherThread because WatcherThread wakes up | |
1326 // periodically so the fatal error handler doesn't need to do anything; | |
1327 // also because the WatcherThread is less likely to crash than other | |
1328 // threads. | |
1329 | |
1330 for (;;) { | |
1331 if (!ShowMessageBoxOnError | |
1332 && (OnError == NULL || OnError[0] == '\0') | |
1333 && Arguments::abort_hook() == NULL) { | |
1334 os::sleep(this, 2 * 60 * 1000, false); | |
1335 fdStream err(defaultStream::output_fd()); | |
1336 err.print_raw_cr("# [ timer expired, abort... ]"); | |
1337 // skip atexit/vm_exit/vm_abort hooks | |
1338 os::die(); | |
1339 } | |
1340 | |
1341 // Wake up 5 seconds later, the fatal handler may reset OnError or | |
1342 // ShowMessageBoxOnError when it is ready to abort. | |
1343 os::sleep(this, 5 * 1000, false); | |
1344 } | |
1345 } | |
1346 | |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1347 PeriodicTask::real_time_tick(time_waited); |
0 | 1348 } |
1349 | |
1350 // Signal that it is terminated | |
1351 { | |
1352 MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag); | |
1353 _watcher_thread = NULL; | |
1354 Terminator_lock->notify(); | |
1355 } | |
1356 | |
1357 // Thread destructor usually does this.. | |
1358 ThreadLocalStorage::set_thread(NULL); | |
1359 } | |
1360 | |
1361 void WatcherThread::start() { | |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1362 assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required"); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1363 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1364 if (watcher_thread() == NULL && _startable) { |
0 | 1365 _should_terminate = false; |
1366 // Create the single instance of WatcherThread | |
1367 new WatcherThread(); | |
1368 } | |
1369 } | |
1370 | |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1371 void WatcherThread::make_startable() { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1372 assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required"); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1373 _startable = true; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1374 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1375 |
0 | 1376 void WatcherThread::stop() { |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1377 { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1378 MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1379 _should_terminate = true; |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1380 OrderAccess::fence(); // ensure WatcherThread sees update in main loop |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1381 |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1382 WatcherThread* watcher = watcher_thread(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1383 if (watcher != NULL) |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1384 watcher->unpark(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1385 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1386 |
0 | 1387 // it is ok to take late safepoints here, if needed |
1388 MutexLocker mu(Terminator_lock); | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1389 |
0 | 1390 while(watcher_thread() != NULL) { |
1391 // This wait should make safepoint checks, wait without a timeout, | |
1392 // and wait as a suspend-equivalent condition. | |
1393 // | |
1394 // Note: If the FlatProfiler is running, then this thread is waiting | |
1395 // for the WatcherThread to terminate and the WatcherThread, via the | |
1396 // FlatProfiler task, is waiting for the external suspend request on | |
1397 // this thread to complete. wait_for_ext_suspend_completion() will | |
1398 // eventually timeout, but that takes time. Making this wait a | |
1399 // suspend-equivalent condition solves that timeout problem. | |
1400 // | |
1401 Terminator_lock->wait(!Mutex::_no_safepoint_check_flag, 0, | |
1402 Mutex::_as_suspend_equivalent_flag); | |
1403 } | |
1404 } | |
1405 | |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1406 void WatcherThread::unpark() { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1407 MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ? NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1408 PeriodicTask_lock->notify(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1409 } |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
1410 |
0 | 1411 void WatcherThread::print_on(outputStream* st) const { |
1412 st->print("\"%s\" ", name()); | |
1413 Thread::print_on(st); | |
1414 st->cr(); | |
1415 } | |
1416 | |
1417 // ======= JavaThread ======== | |
1418 | |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1419 #ifdef GRAAL |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1420 |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1421 jlong* JavaThread::_graal_old_thread_counters; |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1422 |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1423 bool graal_counters_include(oop threadObj) { |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1424 return !GraalCountersExcludeCompiler || threadObj == NULL || threadObj->klass() != SystemDictionary::CompilerThread_klass(); |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1425 } |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1426 |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1427 void JavaThread::collect_counters(typeArrayOop array) { |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1428 if (GraalCounterSize > 0) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1429 MutexLocker tl(Threads_lock); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1430 for (int i = 0; i < array->length(); i++) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1431 array->long_at_put(i, _graal_old_thread_counters[i]); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1432 } |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1433 for (JavaThread* tp = Threads::first(); tp != NULL; tp = tp->next()) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1434 if (graal_counters_include(tp->threadObj())) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1435 for (int i = 0; i < array->length(); i++) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1436 array->long_at_put(i, array->long_at(i) + tp->_graal_counters[i]); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1437 } |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1438 } |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1439 } |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1440 } |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1441 } |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1442 |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1443 #endif // GRAAL |
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1444 |
0 | 1445 // A JavaThread is a normal Java thread |
1446 | |
1447 void JavaThread::initialize() { | |
1448 // Initialize fields | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1449 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1450 // Set the claimed par_id to -1 (ie not claiming any par_ids) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1451 set_claimed_par_id(-1); |
3555
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3464
diff
changeset
|
1452 |
22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents:
3464
diff
changeset
|
1453 _buffer_blob = NULL; |
0 | 1454 set_saved_exception_pc(NULL); |
1455 set_threadObj(NULL); | |
1456 _anchor.clear(); | |
1457 set_entry_point(NULL); | |
1458 set_jni_functions(jni_functions()); | |
1459 set_callee_target(NULL); | |
1460 set_vm_result(NULL); | |
1461 set_vm_result_2(NULL); | |
1462 set_vframe_array_head(NULL); | |
1463 set_vframe_array_last(NULL); | |
1464 set_deferred_locals(NULL); | |
1465 set_deopt_mark(NULL); | |
1814
fd5d4527cdf5
6986270: guarantee(*bcp != Bytecodes::_monitorenter || exec_mode != Deoptimization::Unpack_exception) fails
iveresov
parents:
1731
diff
changeset
|
1466 set_deopt_nmethod(NULL); |
0 | 1467 clear_must_deopt_id(); |
1468 set_monitor_chunks(NULL); | |
1469 set_next(NULL); | |
14768
3e9a960f0da1
HSAIL: preliminary deopt support
Doug Simon <doug.simon@oracle.com>
parents:
14726
diff
changeset
|
1470 set_gpu_exception_bci(0); |
3e9a960f0da1
HSAIL: preliminary deopt support
Doug Simon <doug.simon@oracle.com>
parents:
14726
diff
changeset
|
1471 set_gpu_exception_method(NULL); |
0 | 1472 set_thread_state(_thread_new); |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
1473 #if INCLUDE_NMT |
6197 | 1474 set_recorder(NULL); |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
1475 #endif |
0 | 1476 _terminated = _not_terminated; |
1477 _privileged_stack_top = NULL; | |
1478 _array_for_gc = NULL; | |
1479 _suspend_equivalent = false; | |
1480 _in_deopt_handler = 0; | |
1481 _doing_unsafe_access = false; | |
1482 _stack_guard_state = stack_guard_unused; | |
5747
120820e30baa
added basic high-level interpreter support to HotSpot
Christian Haeubl <haeubl@ssw.jku.at>
parents:
5111
diff
changeset
|
1483 #ifdef GRAAL |
4993
897b7d18bebc
added RiCompiledMethod.execute and the required VM infrastructure
Lukas Stadler <lukas.stadler@jku.at>
parents:
4981
diff
changeset
|
1484 _graal_alternate_call_target = NULL; |
13089
77fbf02f701c
re-enabled protection against recursive Graal compilation requests with Graal specific _graal_compiling field in JavaThread
Doug Simon <doug.simon@oracle.com>
parents:
13086
diff
changeset
|
1485 _graal_implicit_exception_pc = NULL; |
16006
66a9286203a2
decoupled Graal runtime initialization and Graal compilation queue initialization
Doug Simon <doug.simon@oracle.com>
parents:
15463
diff
changeset
|
1486 _graal_can_schedule_compilation = true; |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1487 if (GraalCounterSize > 0) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1488 _graal_counters = NEW_C_HEAP_ARRAY(jlong, GraalCounterSize, mtInternal); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1489 memset(_graal_counters, 0, sizeof(jlong) * GraalCounterSize); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1490 } else { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1491 _graal_counters = NULL; |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1492 } |
11893
ec267141f753
more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents:
11852
diff
changeset
|
1493 #endif // GRAAL |
12316
190899198332
7195622: CheckUnhandledOops has limited usefulness now
hseigel
parents:
12253
diff
changeset
|
1494 (void)const_cast<oop&>(_exception_oop = NULL); |
0 | 1495 _exception_pc = 0; |
1496 _exception_handler_pc = 0; | |
1903 | 1497 _is_method_handle_return = 0; |
0 | 1498 _jvmti_thread_state= NULL; |
1213
6deeaebad47a
6902182: 4/4 Starting with jdwp agent should not incur performance penalty
dcubed
parents:
1166
diff
changeset
|
1499 _should_post_on_exceptions_flag = JNI_FALSE; |
0 | 1500 _jvmti_get_loaded_classes_closure = NULL; |
1501 _interp_only_mode = 0; | |
1502 _special_runtime_exit_condition = _no_async_condition; | |
1503 _pending_async_exception = NULL; | |
1504 _thread_stat = NULL; | |
1505 _thread_stat = new ThreadStatistics(); | |
1506 _blocked_on_compilation = false; | |
1507 _jni_active_critical = 0; | |
1508 _do_not_unlock_if_synchronized = false; | |
1509 _cached_monitor_info = NULL; | |
1510 _parker = Parker::Allocate(this) ; | |
3696
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
1511 _scanned_nmethod = NULL; |
0 | 1512 |
1513 #ifndef PRODUCT | |
1514 _jmp_ring_index = 0; | |
1515 for (int ji = 0 ; ji < jump_ring_buffer_size ; ji++ ) { | |
1516 record_jump(NULL, NULL, NULL, 0); | |
1517 } | |
1518 #endif /* PRODUCT */ | |
1519 | |
1520 set_thread_profiler(NULL); | |
1521 if (FlatProfiler::is_active()) { | |
1522 // This is where we would decide to either give each thread it's own profiler | |
1523 // or use one global one from FlatProfiler, | |
1524 // or up to some count of the number of profiled threads, etc. | |
1525 ThreadProfiler* pp = new ThreadProfiler(); | |
1526 pp->engage(); | |
1527 set_thread_profiler(pp); | |
1528 } | |
1529 | |
1530 // Setup safepoint state info for this thread | |
1531 ThreadSafepointState::create(this); | |
1532 | |
1533 debug_only(_java_call_counter = 0); | |
1534 | |
1535 // JVMTI PopFrame support | |
1536 _popframe_condition = popframe_inactive; | |
1537 _popframe_preserved_args = NULL; | |
1538 _popframe_preserved_args_size = 0; | |
1539 | |
1540 pd_initialize(); | |
1541 } | |
1542 | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1543 #if INCLUDE_ALL_GCS |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1544 SATBMarkQueueSet JavaThread::_satb_mark_queue_set; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1545 DirtyCardQueueSet JavaThread::_dirty_card_queue_set; |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1546 #endif // INCLUDE_ALL_GCS |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1547 |
4006 | 1548 JavaThread::JavaThread(bool is_attaching_via_jni) : |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1549 Thread() |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1550 #if INCLUDE_ALL_GCS |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1551 , _satb_mark_queue(&_satb_mark_queue_set), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1552 _dirty_card_queue(&_dirty_card_queue_set) |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1553 #endif // INCLUDE_ALL_GCS |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1554 { |
0 | 1555 initialize(); |
4006 | 1556 if (is_attaching_via_jni) { |
1557 _jni_attach_state = _attaching_via_jni; | |
1558 } else { | |
1559 _jni_attach_state = _not_attaching_via_jni; | |
1560 } | |
8011
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1561 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor"); |
6197 | 1562 _safepoint_visible = false; |
0 | 1563 } |
1564 | |
1565 bool JavaThread::reguard_stack(address cur_sp) { | |
1566 if (_stack_guard_state != stack_guard_yellow_disabled) { | |
1567 return true; // Stack already guarded or guard pages not needed. | |
1568 } | |
1569 | |
1570 if (register_stack_overflow()) { | |
1571 // For those architectures which have separate register and | |
1572 // memory stacks, we must check the register stack to see if | |
1573 // it has overflowed. | |
1574 return false; | |
1575 } | |
1576 | |
1577 // Java code never executes within the yellow zone: the latter is only | |
1578 // there to provoke an exception during stack banging. If java code | |
1579 // is executing there, either StackShadowPages should be larger, or | |
1580 // some exception code in c1, c2 or the interpreter isn't unwinding | |
1581 // when it should. | |
1582 guarantee(cur_sp > stack_yellow_zone_base(), "not enough space to reguard - increase StackShadowPages"); | |
1583 | |
1584 enable_stack_yellow_zone(); | |
1585 return true; | |
1586 } | |
1587 | |
1588 bool JavaThread::reguard_stack(void) { | |
1589 return reguard_stack(os::current_stack_pointer()); | |
1590 } | |
1591 | |
1592 | |
1593 void JavaThread::block_if_vm_exited() { | |
1594 if (_terminated == _vm_exited) { | |
1595 // _vm_exited is set at safepoint, and Threads_lock is never released | |
1596 // we will block here forever | |
1597 Threads_lock->lock_without_safepoint_check(); | |
1598 ShouldNotReachHere(); | |
1599 } | |
1600 } | |
1601 | |
1602 | |
1603 // Remove this ifdef when C1 is ported to the compiler interface. | |
1604 static void compiler_thread_entry(JavaThread* thread, TRAPS); | |
1605 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1606 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) : |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1607 Thread() |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1608 #if INCLUDE_ALL_GCS |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1609 , _satb_mark_queue(&_satb_mark_queue_set), |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1610 _dirty_card_queue(&_dirty_card_queue_set) |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1611 #endif // INCLUDE_ALL_GCS |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
1612 { |
0 | 1613 if (TraceThreadEvents) { |
1614 tty->print_cr("creating thread %p", this); | |
1615 } | |
1616 initialize(); | |
4006 | 1617 _jni_attach_state = _not_attaching_via_jni; |
0 | 1618 set_entry_point(entry_point); |
1619 // Create the native thread itself. | |
1620 // %note runtime_23 | |
1621 os::ThreadType thr_type = os::java_thread; | |
1622 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread : | |
1623 os::java_thread; | |
1624 os::create_thread(this, thr_type, stack_sz); | |
6197 | 1625 _safepoint_visible = false; |
0 | 1626 // The _osthread may be NULL here because we ran out of memory (too many threads active). |
1627 // We need to throw and OutOfMemoryError - however we cannot do this here because the caller | |
1628 // may hold a lock and all locks must be unlocked before throwing the exception (throwing | |
1629 // the exception consists of creating the exception object & initializing it, initialization | |
1630 // will leave the VM via a JavaCall and then all locks must be unlocked). | |
1631 // | |
1632 // The thread is still suspended when we reach here. Thread must be explicit started | |
1633 // by creator! Furthermore, the thread must also explicitly be added to the Threads list | |
1634 // by calling Threads:add. The reason why this is not done here, is because the thread | |
1635 // object must be fully initialized (take a look at JVM_Start) | |
1636 } | |
1637 | |
1638 JavaThread::~JavaThread() { | |
1639 if (TraceThreadEvents) { | |
1640 tty->print_cr("terminate thread %p", this); | |
1641 } | |
1642 | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
1643 // By now, this thread should already be invisible to safepoint, |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
1644 // and its per-thread recorder also collected. |
6197 | 1645 assert(!is_safepoint_visible(), "wrong state"); |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
1646 #if INCLUDE_NMT |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
1647 assert(get_recorder() == NULL, "Already collected"); |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
1648 #endif // INCLUDE_NMT |
6197 | 1649 |
0 | 1650 // JSR166 -- return the parker to the free list |
1651 Parker::Release(_parker); | |
1652 _parker = NULL ; | |
1653 | |
1654 // Free any remaining previous UnrollBlock | |
1655 vframeArray* old_array = vframe_array_last(); | |
1656 | |
1657 if (old_array != NULL) { | |
1658 Deoptimization::UnrollBlock* old_info = old_array->unroll_block(); | |
1659 old_array->set_unroll_block(NULL); | |
1660 delete old_info; | |
1661 delete old_array; | |
1662 } | |
1663 | |
1664 GrowableArray<jvmtiDeferredLocalVariableSet*>* deferred = deferred_locals(); | |
1665 if (deferred != NULL) { | |
1666 // This can only happen if thread is destroyed before deoptimization occurs. | |
1667 assert(deferred->length() != 0, "empty array!"); | |
1668 do { | |
1669 jvmtiDeferredLocalVariableSet* dlv = deferred->at(0); | |
1670 deferred->remove_at(0); | |
1671 // individual jvmtiDeferredLocalVariableSet are CHeapObj's | |
1672 delete dlv; | |
1673 } while (deferred->length() != 0); | |
1674 delete deferred; | |
1675 } | |
1676 | |
1677 // All Java related clean up happens in exit | |
1678 ThreadSafepointState::destroy(this); | |
1679 if (_thread_profiler != NULL) delete _thread_profiler; | |
1680 if (_thread_stat != NULL) delete _thread_stat; | |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1681 |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1682 #ifdef GRAAL |
15352
b68a693a7ad4
fix BenchmarkCounters memory leak
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14909
diff
changeset
|
1683 if (GraalCounterSize > 0) { |
b68a693a7ad4
fix BenchmarkCounters memory leak
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14909
diff
changeset
|
1684 if (graal_counters_include(threadObj())) { |
b68a693a7ad4
fix BenchmarkCounters memory leak
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14909
diff
changeset
|
1685 for (int i = 0; i < GraalCounterSize; i++) { |
b68a693a7ad4
fix BenchmarkCounters memory leak
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14909
diff
changeset
|
1686 _graal_old_thread_counters[i] += _graal_counters[i]; |
b68a693a7ad4
fix BenchmarkCounters memory leak
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14909
diff
changeset
|
1687 } |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1688 } |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1689 FREE_C_HEAP_ARRAY(jlong, _graal_counters, mtInternal); |
11852
d7964e96b0b0
move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
11173
diff
changeset
|
1690 } |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
1691 #endif // GRAAL |
0 | 1692 } |
1693 | |
1694 | |
1695 // The first routine called by a new Java thread | |
1696 void JavaThread::run() { | |
1697 // initialize thread-local alloc buffer related fields | |
1698 this->initialize_tlab(); | |
1699 | |
14909 | 1700 // used to test validitity of stack trace backs |
0 | 1701 this->record_base_of_stack_pointer(); |
1702 | |
1703 // Record real stack base and size. | |
1704 this->record_stack_base_and_size(); | |
1705 | |
1706 // Initialize thread local storage; set before calling MutexLocker | |
1707 this->initialize_thread_local_storage(); | |
1708 | |
1709 this->create_stack_guard_pages(); | |
1710 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1711 this->cache_global_variables(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
1712 |
0 | 1713 // Thread is now sufficient initialized to be handled by the safepoint code as being |
1714 // in the VM. Change thread state from _thread_new to _thread_in_vm | |
1715 ThreadStateTransition::transition_and_fence(this, _thread_new, _thread_in_vm); | |
1716 | |
1717 assert(JavaThread::current() == this, "sanity check"); | |
1718 assert(!Thread::current()->owns_locks(), "sanity check"); | |
1719 | |
1720 DTRACE_THREAD_PROBE(start, this); | |
1721 | |
1722 // This operation might block. We call that after all safepoint checks for a new thread has | |
1723 // been completed. | |
1724 this->set_active_handles(JNIHandleBlock::allocate_block()); | |
1725 | |
1726 if (JvmtiExport::should_post_thread_life()) { | |
1727 JvmtiExport::post_thread_start(this); | |
1728 } | |
1729 | |
10405 | 1730 EventThreadStart event; |
1731 if (event.should_commit()) { | |
1732 event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj())); | |
1733 event.commit(); | |
1734 } | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1735 |
0 | 1736 // We call another function to do the rest so we are sure that the stack addresses used |
1737 // from there will be lower than the stack base just computed | |
1738 thread_main_inner(); | |
1739 | |
1740 // Note, thread is no longer valid at this point! | |
1741 } | |
1742 | |
1743 | |
1744 void JavaThread::thread_main_inner() { | |
1745 assert(JavaThread::current() == this, "sanity check"); | |
1746 assert(this->threadObj() != NULL, "just checking"); | |
1747 | |
2162
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1748 // Execute thread entry point unless this thread has a pending exception |
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1749 // or has been stopped before starting. |
0 | 1750 // Note: Due to JVM_StopThread we can have pending exceptions already! |
2162
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1751 if (!this->has_pending_exception() && |
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1752 !java_lang_Thread::is_stillborn(this->threadObj())) { |
4006 | 1753 { |
1754 ResourceMark rm(this); | |
1755 this->set_native_thread_name(this->get_thread_name()); | |
1756 } | |
0 | 1757 HandleMark hm(this); |
1758 this->entry_point()(this, this); | |
1759 } | |
1760 | |
1761 DTRACE_THREAD_PROBE(stop, this); | |
1762 | |
1763 this->exit(false); | |
1764 delete this; | |
1765 } | |
1766 | |
1767 | |
1768 static void ensure_join(JavaThread* thread) { | |
1769 // We do not need to grap the Threads_lock, since we are operating on ourself. | |
1770 Handle threadObj(thread, thread->threadObj()); | |
1771 assert(threadObj.not_null(), "java thread object must exist"); | |
1772 ObjectLocker lock(threadObj, thread); | |
1773 // Ignore pending exception (ThreadDeath), since we are exiting anyway | |
1774 thread->clear_pending_exception(); | |
1775 // Thread is exiting. So set thread_status field in java.lang.Thread class to TERMINATED. | |
1776 java_lang_Thread::set_thread_status(threadObj(), java_lang_Thread::TERMINATED); | |
2162
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1777 // Clear the native thread instance - this makes isAlive return false and allows the join() |
ccfcb502af3f
6566340: Restore use of stillborn flag to signify a thread that was stopped before it started
dholmes
parents:
2129
diff
changeset
|
1778 // to complete once we've done the notify_all below |
0 | 1779 java_lang_Thread::set_thread(threadObj(), NULL); |
1780 lock.notify_all(thread); | |
1781 // Ignore pending exception (ThreadDeath), since we are exiting anyway | |
1782 thread->clear_pending_exception(); | |
1783 } | |
1784 | |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1785 |
0 | 1786 // For any new cleanup additions, please check to see if they need to be applied to |
1787 // cleanup_failed_attach_current_thread as well. | |
1788 void JavaThread::exit(bool destroy_vm, ExitType exit_type) { | |
1789 assert(this == JavaThread::current(), "thread consistency check"); | |
1790 | |
1791 HandleMark hm(this); | |
1792 Handle uncaught_exception(this, this->pending_exception()); | |
1793 this->clear_pending_exception(); | |
1794 Handle threadObj(this, this->threadObj()); | |
1795 assert(threadObj.not_null(), "Java thread object should be created"); | |
1796 | |
1797 if (get_thread_profiler() != NULL) { | |
1798 get_thread_profiler()->disengage(); | |
1799 ResourceMark rm; | |
1800 get_thread_profiler()->print(get_thread_name()); | |
1801 } | |
1802 | |
1803 | |
1804 // FIXIT: This code should be moved into else part, when reliable 1.2/1.3 check is in place | |
1805 { | |
1806 EXCEPTION_MARK; | |
1807 | |
1808 CLEAR_PENDING_EXCEPTION; | |
1809 } | |
1810 // FIXIT: The is_null check is only so it works better on JDK1.2 VM's. This | |
1811 // has to be fixed by a runtime query method | |
1812 if (!destroy_vm || JDK_Version::is_jdk12x_version()) { | |
1813 // JSR-166: change call from from ThreadGroup.uncaughtException to | |
1814 // java.lang.Thread.dispatchUncaughtException | |
1815 if (uncaught_exception.not_null()) { | |
1816 Handle group(this, java_lang_Thread::threadGroup(threadObj())); | |
1817 { | |
1818 EXCEPTION_MARK; | |
1819 // Check if the method Thread.dispatchUncaughtException() exists. If so | |
1820 // call it. Otherwise we have an older library without the JSR-166 changes, | |
1821 // so call ThreadGroup.uncaughtException() | |
1822 KlassHandle recvrKlass(THREAD, threadObj->klass()); | |
1823 CallInfo callinfo; | |
1142 | 1824 KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass()); |
0 | 1825 LinkResolver::resolve_virtual_call(callinfo, threadObj, recvrKlass, thread_klass, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1826 vmSymbols::dispatchUncaughtException_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1827 vmSymbols::throwable_void_signature(), |
0 | 1828 KlassHandle(), false, false, THREAD); |
1829 CLEAR_PENDING_EXCEPTION; | |
1830 methodHandle method = callinfo.selected_method(); | |
1831 if (method.not_null()) { | |
1832 JavaValue result(T_VOID); | |
1833 JavaCalls::call_virtual(&result, | |
1834 threadObj, thread_klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1835 vmSymbols::dispatchUncaughtException_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1836 vmSymbols::throwable_void_signature(), |
0 | 1837 uncaught_exception, |
1838 THREAD); | |
1839 } else { | |
1142 | 1840 KlassHandle thread_group(THREAD, SystemDictionary::ThreadGroup_klass()); |
0 | 1841 JavaValue result(T_VOID); |
1842 JavaCalls::call_virtual(&result, | |
1843 group, thread_group, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1844 vmSymbols::uncaughtException_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1845 vmSymbols::thread_throwable_void_signature(), |
0 | 1846 threadObj, // Arg 1 |
1847 uncaught_exception, // Arg 2 | |
1848 THREAD); | |
1849 } | |
2200
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1850 if (HAS_PENDING_EXCEPTION) { |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1851 ResourceMark rm(this); |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1852 jio_fprintf(defaultStream::error_stream(), |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1853 "\nException: %s thrown from the UncaughtExceptionHandler" |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1854 " in thread \"%s\"\n", |
6983 | 1855 pending_exception()->klass()->external_name(), |
2200
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1856 get_thread_name()); |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1857 CLEAR_PENDING_EXCEPTION; |
fb539912d338
6472925: OutOfMemoryError fails to generate stack trace as it now ought
coleenp
parents:
2177
diff
changeset
|
1858 } |
0 | 1859 } |
1860 } | |
1861 | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1862 // Called before the java thread exit since we want to read info |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1863 // from java_lang_Thread object |
10405 | 1864 EventThreadEnd event; |
1865 if (event.should_commit()) { | |
1866 event.set_javalangthread(java_lang_Thread::thread_id(this->threadObj())); | |
1867 event.commit(); | |
1868 } | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1869 |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1870 // Call after last event on thread |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1871 EVENT_THREAD_EXIT(this); |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
1872 |
0 | 1873 // Call Thread.exit(). We try 3 times in case we got another Thread.stop during |
1874 // the execution of the method. If that is not enough, then we don't really care. Thread.stop | |
1875 // is deprecated anyhow. | |
12880
469216acdb28
8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents:
12316
diff
changeset
|
1876 if (!is_Compiler_thread()) { |
469216acdb28
8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents:
12316
diff
changeset
|
1877 int count = 3; |
0 | 1878 while (java_lang_Thread::threadGroup(threadObj()) != NULL && (count-- > 0)) { |
1879 EXCEPTION_MARK; | |
1880 JavaValue result(T_VOID); | |
1142 | 1881 KlassHandle thread_klass(THREAD, SystemDictionary::Thread_klass()); |
0 | 1882 JavaCalls::call_virtual(&result, |
1883 threadObj, thread_klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1884 vmSymbols::exit_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
1885 vmSymbols::void_method_signature(), |
0 | 1886 THREAD); |
1887 CLEAR_PENDING_EXCEPTION; | |
1888 } | |
1889 } | |
1890 // notify JVMTI | |
1891 if (JvmtiExport::should_post_thread_life()) { | |
1892 JvmtiExport::post_thread_end(this); | |
1893 } | |
1894 | |
1895 // We have notified the agents that we are exiting, before we go on, | |
1896 // we must check for a pending external suspend request and honor it | |
1897 // in order to not surprise the thread that made the suspend request. | |
1898 while (true) { | |
1899 { | |
1900 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
1901 if (!is_external_suspend()) { | |
1902 set_terminated(_thread_exiting); | |
1903 ThreadService::current_thread_exiting(this); | |
1904 break; | |
1905 } | |
1906 // Implied else: | |
1907 // Things get a little tricky here. We have a pending external | |
1908 // suspend request, but we are holding the SR_lock so we | |
1909 // can't just self-suspend. So we temporarily drop the lock | |
1910 // and then self-suspend. | |
1911 } | |
1912 | |
1913 ThreadBlockInVM tbivm(this); | |
1914 java_suspend_self(); | |
1915 | |
1916 // We're done with this suspend request, but we have to loop around | |
1917 // and check again. Eventually we will get SR_lock without a pending | |
1918 // external suspend request and will be able to mark ourselves as | |
1919 // exiting. | |
1920 } | |
1921 // no more external suspends are allowed at this point | |
1922 } else { | |
1923 // before_exit() has already posted JVMTI THREAD_END events | |
1924 } | |
1925 | |
1926 // Notify waiters on thread object. This has to be done after exit() is called | |
1927 // on the thread (if the thread is the last thread in a daemon ThreadGroup the | |
1928 // group should have the destroyed bit set before waiters are notified). | |
1929 ensure_join(this); | |
1930 assert(!this->has_pending_exception(), "ensure_join should have cleared"); | |
1931 | |
1932 // 6282335 JNI DetachCurrentThread spec states that all Java monitors | |
1933 // held by this thread must be released. A detach operation must only | |
1934 // get here if there are no Java frames on the stack. Therefore, any | |
1935 // owned monitors at this point MUST be JNI-acquired monitors which are | |
1936 // pre-inflated and in the monitor cache. | |
1937 // | |
1938 // ensure_join() ignores IllegalThreadStateExceptions, and so does this. | |
1939 if (exit_type == jni_detach && JNIDetachReleasesMonitors) { | |
1940 assert(!this->has_last_Java_frame(), "detaching with Java frames?"); | |
1941 ObjectSynchronizer::release_monitors_owned_by_thread(this); | |
1942 assert(!this->has_pending_exception(), "release_monitors should have cleared"); | |
1943 } | |
1944 | |
1945 // These things needs to be done while we are still a Java Thread. Make sure that thread | |
1946 // is in a consistent state, in case GC happens | |
1947 assert(_privileged_stack_top == NULL, "must be NULL when we get here"); | |
1948 | |
1949 if (active_handles() != NULL) { | |
1950 JNIHandleBlock* block = active_handles(); | |
1951 set_active_handles(NULL); | |
1952 JNIHandleBlock::release_block(block); | |
1953 } | |
1954 | |
1955 if (free_handle_block() != NULL) { | |
1956 JNIHandleBlock* block = free_handle_block(); | |
1957 set_free_handle_block(NULL); | |
1958 JNIHandleBlock::release_block(block); | |
1959 } | |
1960 | |
1961 // These have to be removed while this is still a valid thread. | |
1962 remove_stack_guard_pages(); | |
1963 | |
1964 if (UseTLAB) { | |
1965 tlab().make_parsable(true); // retire TLAB | |
1966 } | |
1967 | |
2126
db2b0f8c1cef
6814943: getcpool001 catches more than one JvmtiThreadState problem
kamg
parents:
2100
diff
changeset
|
1968 if (JvmtiEnv::environments_might_exist()) { |
49
31000d79ec71
6453355: 4/4 new No_Safepoint_Verifier uses fail during GC
dcubed
parents:
0
diff
changeset
|
1969 JvmtiExport::cleanup_thread(this); |
31000d79ec71
6453355: 4/4 new No_Safepoint_Verifier uses fail during GC
dcubed
parents:
0
diff
changeset
|
1970 } |
31000d79ec71
6453355: 4/4 new No_Safepoint_Verifier uses fail during GC
dcubed
parents:
0
diff
changeset
|
1971 |
8011
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1972 // We must flush any deferred card marks before removing a thread from |
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1973 // the list of active threads. |
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1974 Universe::heap()->flush_deferred_store_barrier(this); |
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1975 assert(deferred_card_mark().is_empty(), "Should have been flushed"); |
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1976 |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1977 #if INCLUDE_ALL_GCS |
8011
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1978 // We must flush the G1-related buffers before removing a thread |
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1979 // from the list of active threads. We must do this after any deferred |
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1980 // card marks have been flushed (above) so that any entries that are |
06fd03af6ce4
8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
johnc
parents:
7615
diff
changeset
|
1981 // added to the thread's dirty card queue as a result are not lost. |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1982 if (UseG1GC) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1983 flush_barrier_queues(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1984 } |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1985 #endif // INCLUDE_ALL_GCS |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1986 |
0 | 1987 // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread |
1988 Threads::remove(this); | |
1989 } | |
1990 | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
1991 #if INCLUDE_ALL_GCS |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1992 // Flush G1-related queues. |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1993 void JavaThread::flush_barrier_queues() { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1994 satb_mark_queue().flush(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1995 dirty_card_queue().flush(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
1996 } |
1842
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1997 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1998 void JavaThread::initialize_queues() { |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
1999 assert(!SafepointSynchronize::is_at_safepoint(), |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2000 "we should not be at a safepoint"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2001 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2002 ObjPtrQueue& satb_queue = satb_mark_queue(); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2003 SATBMarkQueueSet& satb_queue_set = satb_mark_queue_set(); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2004 // The SATB queue should have been constructed with its active |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2005 // field set to false. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2006 assert(!satb_queue.is_active(), "SATB queue should not be active"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2007 assert(satb_queue.is_empty(), "SATB queue should be empty"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2008 // If we are creating the thread during a marking cycle, we should |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2009 // set the active field of the SATB queue to true. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2010 if (satb_queue_set.is_active()) { |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2011 satb_queue.set_active(true); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2012 } |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2013 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2014 DirtyCardQueue& dirty_queue = dirty_card_queue(); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2015 // The dirty card queue should have been constructed with its |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2016 // active field set to true. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2017 assert(dirty_queue.is_active(), "dirty card queue should be active"); |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
2018 } |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
2019 #endif // INCLUDE_ALL_GCS |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2020 |
0 | 2021 void JavaThread::cleanup_failed_attach_current_thread() { |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2022 if (get_thread_profiler() != NULL) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2023 get_thread_profiler()->disengage(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2024 ResourceMark rm; |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2025 get_thread_profiler()->print(get_thread_name()); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2026 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2027 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2028 if (active_handles() != NULL) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2029 JNIHandleBlock* block = active_handles(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2030 set_active_handles(NULL); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2031 JNIHandleBlock::release_block(block); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2032 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2033 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2034 if (free_handle_block() != NULL) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2035 JNIHandleBlock* block = free_handle_block(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2036 set_free_handle_block(NULL); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2037 JNIHandleBlock::release_block(block); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2038 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2039 |
1290
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1213
diff
changeset
|
2040 // These have to be removed while this is still a valid thread. |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1213
diff
changeset
|
2041 remove_stack_guard_pages(); |
c8a467bf56ad
6914050: jvm assertion "guard pages must be in use" in -Xcomp mode
coleenp
parents:
1213
diff
changeset
|
2042 |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2043 if (UseTLAB) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2044 tlab().make_parsable(true); // retire TLAB, if any |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2045 } |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2046 |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
2047 #if INCLUDE_ALL_GCS |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2048 if (UseG1GC) { |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2049 flush_barrier_queues(); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2050 } |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
2051 #endif // INCLUDE_ALL_GCS |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2052 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2053 Threads::remove(this); |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2054 delete this; |
0 | 2055 } |
2056 | |
2057 | |
441
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2058 |
da9cb4e97a5f
6770608: G1: Mutator thread can flush barrier and satb queues during safepoint
iveresov
parents:
383
diff
changeset
|
2059 |
0 | 2060 JavaThread* JavaThread::active() { |
2061 Thread* thread = ThreadLocalStorage::thread(); | |
2062 assert(thread != NULL, "just checking"); | |
2063 if (thread->is_Java_thread()) { | |
2064 return (JavaThread*) thread; | |
2065 } else { | |
2066 assert(thread->is_VM_thread(), "this must be a vm thread"); | |
2067 VM_Operation* op = ((VMThread*) thread)->vm_operation(); | |
2068 JavaThread *ret=op == NULL ? NULL : (JavaThread *)op->calling_thread(); | |
2069 assert(ret->is_Java_thread(), "must be a Java thread"); | |
2070 return ret; | |
2071 } | |
2072 } | |
2073 | |
2074 bool JavaThread::is_lock_owned(address adr) const { | |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
2075 if (Thread::is_lock_owned(adr)) return true; |
0 | 2076 |
2077 for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) { | |
2078 if (chunk->contains(adr)) return true; | |
2079 } | |
2080 | |
2081 return false; | |
2082 } | |
2083 | |
2084 | |
2085 void JavaThread::add_monitor_chunk(MonitorChunk* chunk) { | |
2086 chunk->set_next(monitor_chunks()); | |
2087 set_monitor_chunks(chunk); | |
2088 } | |
2089 | |
2090 void JavaThread::remove_monitor_chunk(MonitorChunk* chunk) { | |
2091 guarantee(monitor_chunks() != NULL, "must be non empty"); | |
2092 if (monitor_chunks() == chunk) { | |
2093 set_monitor_chunks(chunk->next()); | |
2094 } else { | |
2095 MonitorChunk* prev = monitor_chunks(); | |
2096 while (prev->next() != chunk) prev = prev->next(); | |
2097 prev->set_next(chunk->next()); | |
2098 } | |
2099 } | |
2100 | |
2101 // JVM support. | |
2102 | |
2103 // Note: this function shouldn't block if it's called in | |
2104 // _thread_in_native_trans state (such as from | |
2105 // check_special_condition_for_native_trans()). | |
2106 void JavaThread::check_and_handle_async_exceptions(bool check_unsafe_error) { | |
2107 | |
2108 if (has_last_Java_frame() && has_async_condition()) { | |
2109 // If we are at a polling page safepoint (not a poll return) | |
2110 // then we must defer async exception because live registers | |
2111 // will be clobbered by the exception path. Poll return is | |
2112 // ok because the call we a returning from already collides | |
2113 // with exception handling registers and so there is no issue. | |
2114 // (The exception handling path kills call result registers but | |
2115 // this is ok since the exception kills the result anyway). | |
2116 | |
2117 if (is_at_poll_safepoint()) { | |
2118 // if the code we are returning to has deoptimized we must defer | |
2119 // the exception otherwise live registers get clobbered on the | |
2120 // exception path before deoptimization is able to retrieve them. | |
2121 // | |
2122 RegisterMap map(this, false); | |
2123 frame caller_fr = last_frame().sender(&map); | |
2124 assert(caller_fr.is_compiled_frame(), "what?"); | |
2125 if (caller_fr.is_deoptimized_frame()) { | |
2126 if (TraceExceptions) { | |
2127 ResourceMark rm; | |
2128 tty->print_cr("deferred async exception at compiled safepoint"); | |
2129 } | |
2130 return; | |
2131 } | |
2132 } | |
2133 } | |
2134 | |
2135 JavaThread::AsyncRequests condition = clear_special_runtime_exit_condition(); | |
2136 if (condition == _no_async_condition) { | |
2137 // Conditions have changed since has_special_runtime_exit_condition() | |
2138 // was called: | |
2139 // - if we were here only because of an external suspend request, | |
2140 // then that was taken care of above (or cancelled) so we are done | |
2141 // - if we were here because of another async request, then it has | |
2142 // been cleared between the has_special_runtime_exit_condition() | |
2143 // and now so again we are done | |
2144 return; | |
2145 } | |
2146 | |
2147 // Check for pending async. exception | |
2148 if (_pending_async_exception != NULL) { | |
2149 // Only overwrite an already pending exception, if it is not a threadDeath. | |
1142 | 2150 if (!has_pending_exception() || !pending_exception()->is_a(SystemDictionary::ThreadDeath_klass())) { |
0 | 2151 |
2152 // We cannot call Exceptions::_throw(...) here because we cannot block | |
2153 set_pending_exception(_pending_async_exception, __FILE__, __LINE__); | |
2154 | |
2155 if (TraceExceptions) { | |
2156 ResourceMark rm; | |
2157 tty->print("Async. exception installed at runtime exit (" INTPTR_FORMAT ")", this); | |
2158 if (has_last_Java_frame() ) { | |
2159 frame f = last_frame(); | |
2160 tty->print(" (pc: " INTPTR_FORMAT " sp: " INTPTR_FORMAT " )", f.pc(), f.sp()); | |
2161 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2162 tty->print_cr(" of type: %s", InstanceKlass::cast(_pending_async_exception->klass())->external_name()); |
0 | 2163 } |
2164 _pending_async_exception = NULL; | |
2165 clear_has_async_exception(); | |
2166 } | |
2167 } | |
2168 | |
2169 if (check_unsafe_error && | |
2170 condition == _async_unsafe_access_error && !has_pending_exception()) { | |
2171 condition = _no_async_condition; // done | |
2172 switch (thread_state()) { | |
2173 case _thread_in_vm: | |
2174 { | |
2175 JavaThread* THREAD = this; | |
2176 THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in an unsafe memory access operation"); | |
2177 } | |
2178 case _thread_in_native: | |
2179 { | |
2180 ThreadInVMfromNative tiv(this); | |
2181 JavaThread* THREAD = this; | |
2182 THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in an unsafe memory access operation"); | |
2183 } | |
2184 case _thread_in_Java: | |
2185 { | |
2186 ThreadInVMfromJava tiv(this); | |
2187 JavaThread* THREAD = this; | |
2188 THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in a recent unsafe memory access operation in compiled Java code"); | |
2189 } | |
2190 default: | |
2191 ShouldNotReachHere(); | |
2192 } | |
2193 } | |
2194 | |
2195 assert(condition == _no_async_condition || has_pending_exception() || | |
2196 (!check_unsafe_error && condition == _async_unsafe_access_error), | |
2197 "must have handled the async condition, if no exception"); | |
2198 } | |
2199 | |
2200 void JavaThread::handle_special_runtime_exit_condition(bool check_asyncs) { | |
2201 // | |
2202 // Check for pending external suspend. Internal suspend requests do | |
2203 // not use handle_special_runtime_exit_condition(). | |
2204 // If JNIEnv proxies are allowed, don't self-suspend if the target | |
2205 // thread is not the current thread. In older versions of jdbx, jdbx | |
2206 // threads could call into the VM with another thread's JNIEnv so we | |
2207 // can be here operating on behalf of a suspended thread (4432884). | |
2208 bool do_self_suspend = is_external_suspend_with_lock(); | |
2209 if (do_self_suspend && (!AllowJNIEnvProxy || this == JavaThread::current())) { | |
2210 // | |
2211 // Because thread is external suspended the safepoint code will count | |
2212 // thread as at a safepoint. This can be odd because we can be here | |
2213 // as _thread_in_Java which would normally transition to _thread_blocked | |
2214 // at a safepoint. We would like to mark the thread as _thread_blocked | |
2215 // before calling java_suspend_self like all other callers of it but | |
2216 // we must then observe proper safepoint protocol. (We can't leave | |
2217 // _thread_blocked with a safepoint in progress). However we can be | |
2218 // here as _thread_in_native_trans so we can't use a normal transition | |
2219 // constructor/destructor pair because they assert on that type of | |
2220 // transition. We could do something like: | |
2221 // | |
2222 // JavaThreadState state = thread_state(); | |
2223 // set_thread_state(_thread_in_vm); | |
2224 // { | |
2225 // ThreadBlockInVM tbivm(this); | |
2226 // java_suspend_self() | |
2227 // } | |
2228 // set_thread_state(_thread_in_vm_trans); | |
2229 // if (safepoint) block; | |
2230 // set_thread_state(state); | |
2231 // | |
2232 // but that is pretty messy. Instead we just go with the way the | |
2233 // code has worked before and note that this is the only path to | |
2234 // java_suspend_self that doesn't put the thread in _thread_blocked | |
2235 // mode. | |
2236 | |
2237 frame_anchor()->make_walkable(this); | |
2238 java_suspend_self(); | |
2239 | |
2240 // We might be here for reasons in addition to the self-suspend request | |
2241 // so check for other async requests. | |
2242 } | |
2243 | |
2244 if (check_asyncs) { | |
2245 check_and_handle_async_exceptions(); | |
2246 } | |
2247 } | |
2248 | |
2249 void JavaThread::send_thread_stop(oop java_throwable) { | |
2250 assert(Thread::current()->is_VM_thread(), "should be in the vm thread"); | |
2251 assert(Threads_lock->is_locked(), "Threads_lock should be locked by safepoint code"); | |
2252 assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped"); | |
2253 | |
2254 // Do not throw asynchronous exceptions against the compiler thread | |
2255 // (the compiler thread should not be a Java thread -- fix in 1.4.2) | |
15463
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
2256 if (!can_call_java()) return; |
0 | 2257 |
2258 { | |
2259 // Actually throw the Throwable against the target Thread - however | |
2260 // only if there is no thread death exception installed already. | |
1142 | 2261 if (_pending_async_exception == NULL || !_pending_async_exception->is_a(SystemDictionary::ThreadDeath_klass())) { |
0 | 2262 // If the topmost frame is a runtime stub, then we are calling into |
2263 // OptoRuntime from compiled code. Some runtime stubs (new, monitor_exit..) | |
2264 // must deoptimize the caller before continuing, as the compiled exception handler table | |
2265 // may not be valid | |
2266 if (has_last_Java_frame()) { | |
2267 frame f = last_frame(); | |
2268 if (f.is_runtime_frame() || f.is_safepoint_blob_frame()) { | |
2269 // BiasedLocking needs an updated RegisterMap for the revoke monitors pass | |
2270 RegisterMap reg_map(this, UseBiasedLocking); | |
2271 frame compiled_frame = f.sender(®_map); | |
7428
2d6c433b1f38
8004741: Missing compiled exception handle table entry for multidimensional array allocation
kvn
parents:
7206
diff
changeset
|
2272 if (!StressCompiledExceptionHandlers && compiled_frame.can_be_deoptimized()) { |
0 | 2273 Deoptimization::deoptimize(this, compiled_frame, ®_map); |
2274 } | |
2275 } | |
2276 } | |
2277 | |
2278 // Set async. pending exception in thread. | |
2279 set_pending_async_exception(java_throwable); | |
2280 | |
2281 if (TraceExceptions) { | |
2282 ResourceMark rm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2283 tty->print_cr("Pending Async. exception installed of type: %s", InstanceKlass::cast(_pending_async_exception->klass())->external_name()); |
0 | 2284 } |
2285 // for AbortVMOnException flag | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2286 NOT_PRODUCT(Exceptions::debug_check_abort(InstanceKlass::cast(_pending_async_exception->klass())->external_name())); |
0 | 2287 } |
2288 } | |
2289 | |
2290 | |
2291 // Interrupt thread so it will wake up from a potential wait() | |
2292 Thread::interrupt(this); | |
2293 } | |
2294 | |
2295 // External suspension mechanism. | |
2296 // | |
2297 // Tell the VM to suspend a thread when ever it knows that it does not hold on | |
2298 // to any VM_locks and it is at a transition | |
2299 // Self-suspension will happen on the transition out of the vm. | |
2300 // Catch "this" coming in from JNIEnv pointers when the thread has been freed | |
2301 // | |
2302 // Guarantees on return: | |
2303 // + Target thread will not execute any new bytecode (that's why we need to | |
2304 // force a safepoint) | |
2305 // + Target thread will not enter any new monitors | |
2306 // | |
2307 void JavaThread::java_suspend() { | |
2308 { MutexLocker mu(Threads_lock); | |
2309 if (!Threads::includes(this) || is_exiting() || this->threadObj() == NULL) { | |
2310 return; | |
2311 } | |
2312 } | |
2313 | |
2314 { MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
2315 if (!is_external_suspend()) { | |
2316 // a racing resume has cancelled us; bail out now | |
2317 return; | |
2318 } | |
2319 | |
2320 // suspend is done | |
2321 uint32_t debug_bits = 0; | |
2322 // Warning: is_ext_suspend_completed() may temporarily drop the | |
2323 // SR_lock to allow the thread to reach a stable thread state if | |
2324 // it is currently in a transient thread state. | |
2325 if (is_ext_suspend_completed(false /* !called_by_wait */, | |
2326 SuspendRetryDelay, &debug_bits) ) { | |
2327 return; | |
2328 } | |
2329 } | |
2330 | |
2331 VM_ForceSafepoint vm_suspend; | |
2332 VMThread::execute(&vm_suspend); | |
2333 } | |
2334 | |
2335 // Part II of external suspension. | |
2336 // A JavaThread self suspends when it detects a pending external suspend | |
2337 // request. This is usually on transitions. It is also done in places | |
2338 // where continuing to the next transition would surprise the caller, | |
2339 // e.g., monitor entry. | |
2340 // | |
2341 // Returns the number of times that the thread self-suspended. | |
2342 // | |
2343 // Note: DO NOT call java_suspend_self() when you just want to block current | |
2344 // thread. java_suspend_self() is the second stage of cooperative | |
2345 // suspension for external suspend requests and should only be used | |
2346 // to complete an external suspend request. | |
2347 // | |
2348 int JavaThread::java_suspend_self() { | |
2349 int ret = 0; | |
2350 | |
2351 // we are in the process of exiting so don't suspend | |
2352 if (is_exiting()) { | |
2353 clear_external_suspend(); | |
2354 return ret; | |
2355 } | |
2356 | |
2357 assert(_anchor.walkable() || | |
2358 (is_Java_thread() && !((JavaThread*)this)->has_last_Java_frame()), | |
2359 "must have walkable stack"); | |
2360 | |
2361 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
2362 | |
979 | 2363 assert(!this->is_ext_suspended(), |
0 | 2364 "a thread trying to self-suspend should not already be suspended"); |
2365 | |
2366 if (this->is_suspend_equivalent()) { | |
2367 // If we are self-suspending as a result of the lifting of a | |
2368 // suspend equivalent condition, then the suspend_equivalent | |
2369 // flag is not cleared until we set the ext_suspended flag so | |
2370 // that wait_for_ext_suspend_completion() returns consistent | |
2371 // results. | |
2372 this->clear_suspend_equivalent(); | |
2373 } | |
2374 | |
2375 // A racing resume may have cancelled us before we grabbed SR_lock | |
2376 // above. Or another external suspend request could be waiting for us | |
2377 // by the time we return from SR_lock()->wait(). The thread | |
2378 // that requested the suspension may already be trying to walk our | |
2379 // stack and if we return now, we can change the stack out from under | |
2380 // it. This would be a "bad thing (TM)" and cause the stack walker | |
2381 // to crash. We stay self-suspended until there are no more pending | |
2382 // external suspend requests. | |
2383 while (is_external_suspend()) { | |
2384 ret++; | |
2385 this->set_ext_suspended(); | |
2386 | |
2387 // _ext_suspended flag is cleared by java_resume() | |
2388 while (is_ext_suspended()) { | |
2389 this->SR_lock()->wait(Mutex::_no_safepoint_check_flag); | |
2390 } | |
2391 } | |
2392 | |
2393 return ret; | |
2394 } | |
2395 | |
2396 #ifdef ASSERT | |
2397 // verify the JavaThread has not yet been published in the Threads::list, and | |
2398 // hence doesn't need protection from concurrent access at this stage | |
2399 void JavaThread::verify_not_published() { | |
2400 if (!Threads_lock->owned_by_self()) { | |
2401 MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag); | |
2402 assert( !Threads::includes(this), | |
2403 "java thread shouldn't have been published yet!"); | |
2404 } | |
2405 else { | |
2406 assert( !Threads::includes(this), | |
2407 "java thread shouldn't have been published yet!"); | |
2408 } | |
2409 } | |
2410 #endif | |
2411 | |
2412 // Slow path when the native==>VM/Java barriers detect a safepoint is in | |
2413 // progress or when _suspend_flags is non-zero. | |
2414 // Current thread needs to self-suspend if there is a suspend request and/or | |
2415 // block if a safepoint is in progress. | |
2416 // Async exception ISN'T checked. | |
2417 // Note only the ThreadInVMfromNative transition can call this function | |
2418 // directly and when thread state is _thread_in_native_trans | |
2419 void JavaThread::check_safepoint_and_suspend_for_native_trans(JavaThread *thread) { | |
2420 assert(thread->thread_state() == _thread_in_native_trans, "wrong state"); | |
2421 | |
2422 JavaThread *curJT = JavaThread::current(); | |
2423 bool do_self_suspend = thread->is_external_suspend(); | |
2424 | |
2425 assert(!curJT->has_last_Java_frame() || curJT->frame_anchor()->walkable(), "Unwalkable stack in native->vm transition"); | |
2426 | |
2427 // If JNIEnv proxies are allowed, don't self-suspend if the target | |
2428 // thread is not the current thread. In older versions of jdbx, jdbx | |
2429 // threads could call into the VM with another thread's JNIEnv so we | |
2430 // can be here operating on behalf of a suspended thread (4432884). | |
2431 if (do_self_suspend && (!AllowJNIEnvProxy || curJT == thread)) { | |
2432 JavaThreadState state = thread->thread_state(); | |
2433 | |
2434 // We mark this thread_blocked state as a suspend-equivalent so | |
2435 // that a caller to is_ext_suspend_completed() won't be confused. | |
2436 // The suspend-equivalent state is cleared by java_suspend_self(). | |
2437 thread->set_suspend_equivalent(); | |
2438 | |
2439 // If the safepoint code sees the _thread_in_native_trans state, it will | |
2440 // wait until the thread changes to other thread state. There is no | |
2441 // guarantee on how soon we can obtain the SR_lock and complete the | |
2442 // self-suspend request. It would be a bad idea to let safepoint wait for | |
2443 // too long. Temporarily change the state to _thread_blocked to | |
2444 // let the VM thread know that this thread is ready for GC. The problem | |
2445 // of changing thread state is that safepoint could happen just after | |
2446 // java_suspend_self() returns after being resumed, and VM thread will | |
2447 // see the _thread_blocked state. We must check for safepoint | |
2448 // after restoring the state and make sure we won't leave while a safepoint | |
2449 // is in progress. | |
2450 thread->set_thread_state(_thread_blocked); | |
2451 thread->java_suspend_self(); | |
2452 thread->set_thread_state(state); | |
2453 // Make sure new state is seen by VM thread | |
2454 if (os::is_MP()) { | |
2455 if (UseMembar) { | |
2456 // Force a fence between the write above and read below | |
2457 OrderAccess::fence(); | |
2458 } else { | |
2459 // Must use this rather than serialization page in particular on Windows | |
2460 InterfaceSupport::serialize_memory(thread); | |
2461 } | |
2462 } | |
2463 } | |
2464 | |
2465 if (SafepointSynchronize::do_call_back()) { | |
2466 // If we are safepointing, then block the caller which may not be | |
2467 // the same as the target thread (see above). | |
2468 SafepointSynchronize::block(curJT); | |
2469 } | |
2470 | |
2471 if (thread->is_deopt_suspend()) { | |
2472 thread->clear_deopt_suspend(); | |
2473 RegisterMap map(thread, false); | |
2474 frame f = thread->last_frame(); | |
2475 while ( f.id() != thread->must_deopt_id() && ! f.is_first_frame()) { | |
2476 f = f.sender(&map); | |
2477 } | |
2478 if (f.id() == thread->must_deopt_id()) { | |
2479 thread->clear_must_deopt_id(); | |
1727
da877bdc9000
6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents:
1689
diff
changeset
|
2480 f.deoptimize(thread); |
0 | 2481 } else { |
2482 fatal("missed deoptimization!"); | |
2483 } | |
2484 } | |
2485 } | |
2486 | |
2487 // Slow path when the native==>VM/Java barriers detect a safepoint is in | |
2488 // progress or when _suspend_flags is non-zero. | |
2489 // Current thread needs to self-suspend if there is a suspend request and/or | |
2490 // block if a safepoint is in progress. | |
2491 // Also check for pending async exception (not including unsafe access error). | |
2492 // Note only the native==>VM/Java barriers can call this function and when | |
2493 // thread state is _thread_in_native_trans. | |
2494 void JavaThread::check_special_condition_for_native_trans(JavaThread *thread) { | |
2495 check_safepoint_and_suspend_for_native_trans(thread); | |
2496 | |
2497 if (thread->has_async_exception()) { | |
2498 // We are in _thread_in_native_trans state, don't handle unsafe | |
2499 // access error since that may block. | |
2500 thread->check_and_handle_async_exceptions(false); | |
2501 } | |
2502 } | |
2503 | |
4873
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2504 // This is a variant of the normal |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2505 // check_special_condition_for_native_trans with slightly different |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2506 // semantics for use by critical native wrappers. It does all the |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2507 // normal checks but also performs the transition back into |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2508 // thread_in_Java state. This is required so that critical natives |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2509 // can potentially block and perform a GC if they are the last thread |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2510 // exiting the GC_locker. |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2511 void JavaThread::check_special_condition_for_native_trans_and_transition(JavaThread *thread) { |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2512 check_special_condition_for_native_trans(thread); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2513 |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2514 // Finish the transition |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2515 thread->set_thread_state(_thread_in_Java); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2516 |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2517 if (thread->do_critical_native_unlock()) { |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2518 ThreadInVMfromJavaNoAsyncException tiv(thread); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2519 GC_locker::unlock_critical(thread); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2520 thread->clear_critical_native_unlock(); |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2521 } |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2522 } |
0382d2b469b2
7013347: allow crypto functions to be called inline to enhance performance
never
parents:
4872
diff
changeset
|
2523 |
0 | 2524 // We need to guarantee the Threads_lock here, since resumes are not |
2525 // allowed during safepoint synchronization | |
2526 // Can only resume from an external suspension | |
2527 void JavaThread::java_resume() { | |
2528 assert_locked_or_safepoint(Threads_lock); | |
2529 | |
2530 // Sanity check: thread is gone, has started exiting or the thread | |
2531 // was not externally suspended. | |
2532 if (!Threads::includes(this) || is_exiting() || !is_external_suspend()) { | |
2533 return; | |
2534 } | |
2535 | |
2536 MutexLockerEx ml(SR_lock(), Mutex::_no_safepoint_check_flag); | |
2537 | |
2538 clear_external_suspend(); | |
2539 | |
2540 if (is_ext_suspended()) { | |
2541 clear_ext_suspended(); | |
2542 SR_lock()->notify_all(); | |
2543 } | |
2544 } | |
2545 | |
2546 void JavaThread::create_stack_guard_pages() { | |
2547 if (! os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) return; | |
2548 address low_addr = stack_base() - stack_size(); | |
2549 size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size(); | |
2550 | |
2551 int allocate = os::allocate_stack_guard_pages(); | |
2552 // warning("Guarding at " PTR_FORMAT " for len " SIZE_FORMAT "\n", low_addr, len); | |
2553 | |
1320
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1290
diff
changeset
|
2554 if (allocate && !os::create_stack_guard_pages((char *) low_addr, len)) { |
0 | 2555 warning("Attempt to allocate stack guard pages failed."); |
2556 return; | |
2557 } | |
2558 | |
2559 if (os::guard_memory((char *) low_addr, len)) { | |
2560 _stack_guard_state = stack_guard_enabled; | |
2561 } else { | |
2562 warning("Attempt to protect stack guard pages failed."); | |
2563 if (os::uncommit_memory((char *) low_addr, len)) { | |
2564 warning("Attempt to deallocate stack guard pages failed."); | |
2565 } | |
2566 } | |
2567 } | |
2568 | |
2569 void JavaThread::remove_stack_guard_pages() { | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
2570 assert(Thread::current() == this, "from different thread"); |
0 | 2571 if (_stack_guard_state == stack_guard_unused) return; |
2572 address low_addr = stack_base() - stack_size(); | |
2573 size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size(); | |
2574 | |
2575 if (os::allocate_stack_guard_pages()) { | |
1320
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1290
diff
changeset
|
2576 if (os::remove_stack_guard_pages((char *) low_addr, len)) { |
0 | 2577 _stack_guard_state = stack_guard_unused; |
2578 } else { | |
2579 warning("Attempt to deallocate stack guard pages failed."); | |
2580 } | |
2581 } else { | |
2582 if (_stack_guard_state == stack_guard_unused) return; | |
2583 if (os::unguard_memory((char *) low_addr, len)) { | |
2584 _stack_guard_state = stack_guard_unused; | |
2585 } else { | |
2586 warning("Attempt to unprotect stack guard pages failed."); | |
2587 } | |
2588 } | |
2589 } | |
2590 | |
2591 void JavaThread::enable_stack_yellow_zone() { | |
2592 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2593 assert(_stack_guard_state != stack_guard_enabled, "already enabled"); | |
2594 | |
2595 // The base notation is from the stacks point of view, growing downward. | |
2596 // We need to adjust it to work correctly with guard_memory() | |
2597 address base = stack_yellow_zone_base() - stack_yellow_zone_size(); | |
2598 | |
2599 guarantee(base < stack_base(),"Error calculating stack yellow zone"); | |
2600 guarantee(base < os::current_stack_pointer(),"Error calculating stack yellow zone"); | |
2601 | |
2602 if (os::guard_memory((char *) base, stack_yellow_zone_size())) { | |
2603 _stack_guard_state = stack_guard_enabled; | |
2604 } else { | |
2605 warning("Attempt to guard stack yellow zone failed."); | |
2606 } | |
2607 enable_register_stack_guard(); | |
2608 } | |
2609 | |
2610 void JavaThread::disable_stack_yellow_zone() { | |
2611 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2612 assert(_stack_guard_state != stack_guard_yellow_disabled, "already disabled"); | |
2613 | |
2614 // Simply return if called for a thread that does not use guard pages. | |
2615 if (_stack_guard_state == stack_guard_unused) return; | |
2616 | |
2617 // The base notation is from the stacks point of view, growing downward. | |
2618 // We need to adjust it to work correctly with guard_memory() | |
2619 address base = stack_yellow_zone_base() - stack_yellow_zone_size(); | |
2620 | |
2621 if (os::unguard_memory((char *)base, stack_yellow_zone_size())) { | |
2622 _stack_guard_state = stack_guard_yellow_disabled; | |
2623 } else { | |
2624 warning("Attempt to unguard stack yellow zone failed."); | |
2625 } | |
2626 disable_register_stack_guard(); | |
2627 } | |
2628 | |
2629 void JavaThread::enable_stack_red_zone() { | |
2630 // The base notation is from the stacks point of view, growing downward. | |
2631 // We need to adjust it to work correctly with guard_memory() | |
2632 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2633 address base = stack_red_zone_base() - stack_red_zone_size(); | |
2634 | |
2635 guarantee(base < stack_base(),"Error calculating stack red zone"); | |
2636 guarantee(base < os::current_stack_pointer(),"Error calculating stack red zone"); | |
2637 | |
2638 if(!os::guard_memory((char *) base, stack_red_zone_size())) { | |
2639 warning("Attempt to guard stack red zone failed."); | |
2640 } | |
2641 } | |
2642 | |
2643 void JavaThread::disable_stack_red_zone() { | |
2644 // The base notation is from the stacks point of view, growing downward. | |
2645 // We need to adjust it to work correctly with guard_memory() | |
2646 assert(_stack_guard_state != stack_guard_unused, "must be using guard pages."); | |
2647 address base = stack_red_zone_base() - stack_red_zone_size(); | |
2648 if (!os::unguard_memory((char *)base, stack_red_zone_size())) { | |
2649 warning("Attempt to unguard stack red zone failed."); | |
2650 } | |
2651 } | |
2652 | |
2653 void JavaThread::frames_do(void f(frame*, const RegisterMap* map)) { | |
2654 // ignore is there is no stack | |
2655 if (!has_last_Java_frame()) return; | |
2656 // traverse the stack frames. Starts from top frame. | |
2657 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
2658 frame* fr = fst.current(); | |
2659 f(fr, fst.register_map()); | |
2660 } | |
2661 } | |
2662 | |
2663 | |
2664 #ifndef PRODUCT | |
2665 // Deoptimization | |
2666 // Function for testing deoptimization | |
2667 void JavaThread::deoptimize() { | |
2668 // BiasedLocking needs an updated RegisterMap for the revoke monitors pass | |
2669 StackFrameStream fst(this, UseBiasedLocking); | |
2670 bool deopt = false; // Dump stack only if a deopt actually happens. | |
2671 bool only_at = strlen(DeoptimizeOnlyAt) > 0; | |
2672 // Iterate over all frames in the thread and deoptimize | |
2673 for(; !fst.is_done(); fst.next()) { | |
2674 if(fst.current()->can_be_deoptimized()) { | |
2675 | |
2676 if (only_at) { | |
2677 // Deoptimize only at particular bcis. DeoptimizeOnlyAt | |
2678 // consists of comma or carriage return separated numbers so | |
2679 // search for the current bci in that string. | |
2680 address pc = fst.current()->pc(); | |
2681 nmethod* nm = (nmethod*) fst.current()->cb(); | |
2682 ScopeDesc* sd = nm->scope_desc_at( pc); | |
2683 char buffer[8]; | |
2684 jio_snprintf(buffer, sizeof(buffer), "%d", sd->bci()); | |
2685 size_t len = strlen(buffer); | |
2686 const char * found = strstr(DeoptimizeOnlyAt, buffer); | |
2687 while (found != NULL) { | |
2688 if ((found[len] == ',' || found[len] == '\n' || found[len] == '\0') && | |
2689 (found == DeoptimizeOnlyAt || found[-1] == ',' || found[-1] == '\n')) { | |
2690 // Check that the bci found is bracketed by terminators. | |
2691 break; | |
2692 } | |
2693 found = strstr(found + 1, buffer); | |
2694 } | |
2695 if (!found) { | |
2696 continue; | |
2697 } | |
2698 } | |
2699 | |
2700 if (DebugDeoptimization && !deopt) { | |
2701 deopt = true; // One-time only print before deopt | |
2702 tty->print_cr("[BEFORE Deoptimization]"); | |
2703 trace_frames(); | |
2704 trace_stack(); | |
2705 } | |
2706 Deoptimization::deoptimize(this, *fst.current(), fst.register_map()); | |
2707 } | |
2708 } | |
2709 | |
2710 if (DebugDeoptimization && deopt) { | |
2711 tty->print_cr("[AFTER Deoptimization]"); | |
2712 trace_frames(); | |
2713 } | |
2714 } | |
2715 | |
2716 | |
2717 // Make zombies | |
2718 void JavaThread::make_zombies() { | |
2719 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
2720 if (fst.current()->can_be_deoptimized()) { | |
2721 // it is a Java nmethod | |
2722 nmethod* nm = CodeCache::find_nmethod(fst.current()->pc()); | |
2723 nm->make_not_entrant(); | |
2724 } | |
2725 } | |
2726 } | |
2727 #endif // PRODUCT | |
2728 | |
2729 | |
2730 void JavaThread::deoptimized_wrt_marked_nmethods() { | |
2731 if (!has_last_Java_frame()) return; | |
2732 // BiasedLocking needs an updated RegisterMap for the revoke monitors pass | |
2733 StackFrameStream fst(this, UseBiasedLocking); | |
2734 for(; !fst.is_done(); fst.next()) { | |
2735 if (fst.current()->should_be_deoptimized()) { | |
6843 | 2736 if (LogCompilation && xtty != NULL) { |
2737 nmethod* nm = fst.current()->cb()->as_nmethod_or_null(); | |
2738 xtty->elem("deoptimized thread='" UINTX_FORMAT "' compile_id='%d'", | |
2739 this->name(), nm != NULL ? nm->compile_id() : -1); | |
2740 } | |
2741 | |
0 | 2742 Deoptimization::deoptimize(this, *fst.current(), fst.register_map()); |
2743 } | |
2744 } | |
2745 } | |
2746 | |
2747 | |
2748 // GC support | |
2749 static void frame_gc_epilogue(frame* f, const RegisterMap* map) { f->gc_epilogue(); } | |
2750 | |
2751 void JavaThread::gc_epilogue() { | |
2752 frames_do(frame_gc_epilogue); | |
2753 } | |
2754 | |
2755 | |
2756 static void frame_gc_prologue(frame* f, const RegisterMap* map) { f->gc_prologue(); } | |
2757 | |
2758 void JavaThread::gc_prologue() { | |
2759 frames_do(frame_gc_prologue); | |
2760 } | |
2761 | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2762 // If the caller is a NamedThread, then remember, in the current scope, |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2763 // the given JavaThread in its _processed_thread field. |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2764 class RememberProcessedThread: public StackObj { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2765 NamedThread* _cur_thr; |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2766 public: |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2767 RememberProcessedThread(JavaThread* jthr) { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2768 Thread* thread = Thread::current(); |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2769 if (thread->is_Named_thread()) { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2770 _cur_thr = (NamedThread *)thread; |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2771 _cur_thr->set_processed_thread(jthr); |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2772 } else { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2773 _cur_thr = NULL; |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2774 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2775 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2776 |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2777 ~RememberProcessedThread() { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2778 if (_cur_thr) { |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2779 _cur_thr->set_processed_thread(NULL); |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2780 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2781 } |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2782 }; |
0 | 2783 |
14909 | 2784 void JavaThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
1166 | 2785 // Verify that the deferred card marks have been flushed. |
2786 assert(deferred_card_mark().is_empty(), "Should be empty during GC"); | |
1027
39b01ab7035a
6888898: CMS: ReduceInitialCardMarks unsafe in the presence of cms precleaning
ysr
parents:
997
diff
changeset
|
2787 |
0 | 2788 // The ThreadProfiler oops_do is done from FlatProfiler::oops_do |
2789 // since there may be more than one thread using each ThreadProfiler. | |
2790 | |
2791 // Traverse the GCHandles | |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
2792 Thread::oops_do(f, cld_f, cf); |
0 | 2793 |
2794 assert( (!has_last_Java_frame() && java_call_counter() == 0) || | |
2795 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!"); | |
2796 | |
2797 if (has_last_Java_frame()) { | |
1119
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2798 // Record JavaThread to GC thread |
547f81740344
6361589: Print out stack trace for target thread of GC crash
minqi
parents:
1115
diff
changeset
|
2799 RememberProcessedThread rpt(this); |
0 | 2800 |
2801 // Traverse the privileged stack | |
2802 if (_privileged_stack_top != NULL) { | |
2803 _privileged_stack_top->oops_do(f); | |
2804 } | |
2805 | |
2806 // traverse the registered growable array | |
2807 if (_array_for_gc != NULL) { | |
2808 for (int index = 0; index < _array_for_gc->length(); index++) { | |
2809 f->do_oop(_array_for_gc->adr_at(index)); | |
2810 } | |
2811 } | |
2812 | |
2813 // Traverse the monitor chunks | |
2814 for (MonitorChunk* chunk = monitor_chunks(); chunk != NULL; chunk = chunk->next()) { | |
2815 chunk->oops_do(f); | |
2816 } | |
2817 | |
2818 // Traverse the execution stack | |
2819 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
2820 fst.current()->oops_do(f, cld_f, cf, fst.register_map()); |
0 | 2821 } |
2822 } | |
2823 | |
2824 // callee_target is never live across a gc point so NULL it here should | |
2825 // it still contain a methdOop. | |
2826 | |
2827 set_callee_target(NULL); | |
2828 | |
2829 assert(vframe_array_head() == NULL, "deopt in progress at a safepoint!"); | |
2830 // If we have deferred set_locals there might be oops waiting to be | |
2831 // written | |
2832 GrowableArray<jvmtiDeferredLocalVariableSet*>* list = deferred_locals(); | |
2833 if (list != NULL) { | |
2834 for (int i = 0; i < list->length(); i++) { | |
2835 list->at(i)->oops_do(f); | |
2836 } | |
2837 } | |
2838 | |
2839 // Traverse instance variables at the end since the GC may be moving things | |
2840 // around using this function | |
2841 f->do_oop((oop*) &_threadObj); | |
2842 f->do_oop((oop*) &_vm_result); | |
2843 f->do_oop((oop*) &_exception_oop); | |
2844 f->do_oop((oop*) &_pending_async_exception); | |
2845 | |
2846 if (jvmti_thread_state() != NULL) { | |
2847 jvmti_thread_state()->oops_do(f); | |
2848 } | |
3696
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2849 |
dc7902820c9b
Make NMethodSweeper work on any JavaThread
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents:
3650
diff
changeset
|
2850 if (_scanned_nmethod != NULL && cf != NULL) { |
7212
291ffc492eb6
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
Doug Simon <doug.simon@oracle.com>
diff
changeset
|
2851 // Safepoints can occur when the sweeper is scanning an nmethod so |
291ffc492eb6
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
Doug Simon <doug.simon@oracle.com>
diff
changeset
|
2852 // process it here to make sure it isn't unloaded in the middle of |
291ffc492eb6
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
Doug Simon <doug.simon@oracle.com>
diff
changeset
|
2853 // a scan. |
291ffc492eb6
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
Doug Simon <doug.simon@oracle.com>
diff
changeset
|
2854 cf->do_code_blob(_scanned_nmethod); |
291ffc492eb6
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
Doug Simon <doug.simon@oracle.com>
diff
changeset
|
2855 } |
0 | 2856 } |
2857 | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2858 void JavaThread::nmethods_do(CodeBlobClosure* cf) { |
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2859 Thread::nmethods_do(cf); // (super method is a no-op) |
0 | 2860 |
2861 assert( (!has_last_Java_frame() && java_call_counter() == 0) || | |
2862 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!"); | |
2863 | |
2864 if (has_last_Java_frame()) { | |
2865 // Traverse the execution stack | |
2866 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
2867 fst.current()->nmethods_do(cf); |
0 | 2868 } |
2869 } | |
2870 } | |
2871 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2872 void JavaThread::metadata_do(void f(Metadata*)) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2873 Thread::metadata_do(f); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2874 if (has_last_Java_frame()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2875 // Traverse the execution stack to call f() on the methods in the stack |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2876 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2877 fst.current()->metadata_do(f); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2878 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2879 } else if (is_Compiler_thread()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2880 // need to walk ciMetadata in current compile tasks to keep alive. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2881 CompilerThread* ct = (CompilerThread*)this; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2882 if (ct->env() != NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2883 ct->env()->metadata_do(f); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2884 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2885 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2886 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
2887 |
0 | 2888 // Printing |
2889 const char* _get_thread_state_name(JavaThreadState _thread_state) { | |
2890 switch (_thread_state) { | |
2891 case _thread_uninitialized: return "_thread_uninitialized"; | |
2892 case _thread_new: return "_thread_new"; | |
2893 case _thread_new_trans: return "_thread_new_trans"; | |
2894 case _thread_in_native: return "_thread_in_native"; | |
2895 case _thread_in_native_trans: return "_thread_in_native_trans"; | |
2896 case _thread_in_vm: return "_thread_in_vm"; | |
2897 case _thread_in_vm_trans: return "_thread_in_vm_trans"; | |
2898 case _thread_in_Java: return "_thread_in_Java"; | |
2899 case _thread_in_Java_trans: return "_thread_in_Java_trans"; | |
2900 case _thread_blocked: return "_thread_blocked"; | |
2901 case _thread_blocked_trans: return "_thread_blocked_trans"; | |
2902 default: return "unknown thread state"; | |
2903 } | |
2904 } | |
2905 | |
2906 #ifndef PRODUCT | |
2907 void JavaThread::print_thread_state_on(outputStream *st) const { | |
2908 st->print_cr(" JavaThread state: %s", _get_thread_state_name(_thread_state)); | |
2909 }; | |
2910 void JavaThread::print_thread_state() const { | |
2911 print_thread_state_on(tty); | |
2912 }; | |
2913 #endif // PRODUCT | |
2914 | |
2915 // Called by Threads::print() for VM_PrintThreads operation | |
2916 void JavaThread::print_on(outputStream *st) const { | |
2917 st->print("\"%s\" ", get_thread_name()); | |
2918 oop thread_oop = threadObj(); | |
6766 | 2919 if (thread_oop != NULL) { |
2920 st->print("#" INT64_FORMAT " ", java_lang_Thread::thread_id(thread_oop)); | |
2921 if (java_lang_Thread::is_daemon(thread_oop)) st->print("daemon "); | |
2922 st->print("prio=%d ", java_lang_Thread::priority(thread_oop)); | |
2923 } | |
0 | 2924 Thread::print_on(st); |
2925 // print guess for valid stack memory region (assume 4K pages); helps lock debugging | |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
2926 st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12)); |
0 | 2927 if (thread_oop != NULL && JDK_Version::is_gte_jdk15x_version()) { |
2928 st->print_cr(" java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop)); | |
2929 } | |
2930 #ifndef PRODUCT | |
2931 print_thread_state_on(st); | |
2932 _safepoint_state->print_on(st); | |
2933 #endif // PRODUCT | |
2934 } | |
2935 | |
2936 // Called by fatal error handler. The difference between this and | |
2937 // JavaThread::print() is that we can't grab lock or allocate memory. | |
2938 void JavaThread::print_on_error(outputStream* st, char *buf, int buflen) const { | |
2939 st->print("JavaThread \"%s\"", get_thread_name_string(buf, buflen)); | |
2940 oop thread_obj = threadObj(); | |
2941 if (thread_obj != NULL) { | |
2942 if (java_lang_Thread::is_daemon(thread_obj)) st->print(" daemon"); | |
2943 } | |
2944 st->print(" ["); | |
2945 st->print("%s", _get_thread_state_name(_thread_state)); | |
2946 if (osthread()) { | |
2947 st->print(", id=%d", osthread()->thread_id()); | |
2948 } | |
2949 st->print(", stack(" PTR_FORMAT "," PTR_FORMAT ")", | |
2950 _stack_base - _stack_size, _stack_base); | |
2951 st->print("]"); | |
2952 return; | |
2953 } | |
2954 | |
2955 // Verification | |
2956 | |
2957 static void frame_verify(frame* f, const RegisterMap *map) { f->verify(map); } | |
2958 | |
2959 void JavaThread::verify() { | |
2960 // Verify oops in the thread. | |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
2961 oops_do(&VerifyOopClosure::verify_oop, NULL, NULL); |
0 | 2962 |
2963 // Verify the stack frames. | |
2964 frames_do(frame_verify); | |
2965 } | |
2966 | |
2967 // CR 6300358 (sub-CR 2137150) | |
2968 // Most callers of this method assume that it can't return NULL but a | |
2969 // thread may not have a name whilst it is in the process of attaching to | |
2970 // the VM - see CR 6412693, and there are places where a JavaThread can be | |
2971 // seen prior to having it's threadObj set (eg JNI attaching threads and | |
2972 // if vm exit occurs during initialization). These cases can all be accounted | |
2973 // for such that this method never returns NULL. | |
2974 const char* JavaThread::get_thread_name() const { | |
2975 #ifdef ASSERT | |
2976 // early safepoints can hit while current thread does not yet have TLS | |
2977 if (!SafepointSynchronize::is_at_safepoint()) { | |
2978 Thread *cur = Thread::current(); | |
2979 if (!(cur->is_Java_thread() && cur == this)) { | |
2980 // Current JavaThreads are allowed to get their own name without | |
2981 // the Threads_lock. | |
2982 assert_locked_or_safepoint(Threads_lock); | |
2983 } | |
2984 } | |
2985 #endif // ASSERT | |
2986 return get_thread_name_string(); | |
2987 } | |
2988 | |
2989 // Returns a non-NULL representation of this thread's name, or a suitable | |
2990 // descriptive string if there is no set name | |
2991 const char* JavaThread::get_thread_name_string(char* buf, int buflen) const { | |
2992 const char* name_str; | |
2993 oop thread_obj = threadObj(); | |
2994 if (thread_obj != NULL) { | |
2995 typeArrayOop name = java_lang_Thread::name(thread_obj); | |
2996 if (name != NULL) { | |
2997 if (buf == NULL) { | |
2998 name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
2999 } | |
3000 else { | |
3001 name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen); | |
3002 } | |
3003 } | |
4006 | 3004 else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306 |
0 | 3005 name_str = "<no-name - thread is attaching>"; |
3006 } | |
3007 else { | |
3008 name_str = Thread::name(); | |
3009 } | |
3010 } | |
3011 else { | |
3012 name_str = Thread::name(); | |
3013 } | |
3014 assert(name_str != NULL, "unexpected NULL thread name"); | |
3015 return name_str; | |
3016 } | |
3017 | |
3018 | |
3019 const char* JavaThread::get_threadgroup_name() const { | |
3020 debug_only(if (JavaThread::current() != this) assert_locked_or_safepoint(Threads_lock);) | |
3021 oop thread_obj = threadObj(); | |
3022 if (thread_obj != NULL) { | |
3023 oop thread_group = java_lang_Thread::threadGroup(thread_obj); | |
3024 if (thread_group != NULL) { | |
3025 typeArrayOop name = java_lang_ThreadGroup::name(thread_group); | |
3026 // ThreadGroup.name can be null | |
3027 if (name != NULL) { | |
3028 const char* str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
3029 return str; | |
3030 } | |
3031 } | |
3032 } | |
3033 return NULL; | |
3034 } | |
3035 | |
3036 const char* JavaThread::get_parent_name() const { | |
3037 debug_only(if (JavaThread::current() != this) assert_locked_or_safepoint(Threads_lock);) | |
3038 oop thread_obj = threadObj(); | |
3039 if (thread_obj != NULL) { | |
3040 oop thread_group = java_lang_Thread::threadGroup(thread_obj); | |
3041 if (thread_group != NULL) { | |
3042 oop parent = java_lang_ThreadGroup::parent(thread_group); | |
3043 if (parent != NULL) { | |
3044 typeArrayOop name = java_lang_ThreadGroup::name(parent); | |
3045 // ThreadGroup.name can be null | |
3046 if (name != NULL) { | |
3047 const char* str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); | |
3048 return str; | |
3049 } | |
3050 } | |
3051 } | |
3052 } | |
3053 return NULL; | |
3054 } | |
3055 | |
3056 ThreadPriority JavaThread::java_priority() const { | |
3057 oop thr_oop = threadObj(); | |
3058 if (thr_oop == NULL) return NormPriority; // Bootstrapping | |
3059 ThreadPriority priority = java_lang_Thread::priority(thr_oop); | |
3060 assert(MinPriority <= priority && priority <= MaxPriority, "sanity check"); | |
3061 return priority; | |
3062 } | |
3063 | |
3064 void JavaThread::prepare(jobject jni_thread, ThreadPriority prio) { | |
3065 | |
3066 assert(Threads_lock->owner() == Thread::current(), "must have threads lock"); | |
3067 // Link Java Thread object <-> C++ Thread | |
3068 | |
3069 // Get the C++ thread object (an oop) from the JNI handle (a jthread) | |
3070 // and put it into a new Handle. The Handle "thread_oop" can then | |
3071 // be used to pass the C++ thread object to other methods. | |
3072 | |
3073 // Set the Java level thread object (jthread) field of the | |
3074 // new thread (a JavaThread *) to C++ thread object using the | |
3075 // "thread_oop" handle. | |
3076 | |
3077 // Set the thread field (a JavaThread *) of the | |
3078 // oop representing the java_lang_Thread to the new thread (a JavaThread *). | |
3079 | |
3080 Handle thread_oop(Thread::current(), | |
3081 JNIHandles::resolve_non_null(jni_thread)); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3082 assert(InstanceKlass::cast(thread_oop->klass())->is_linked(), |
0 | 3083 "must be initialized"); |
3084 set_threadObj(thread_oop()); | |
3085 java_lang_Thread::set_thread(thread_oop(), this); | |
3086 | |
3087 if (prio == NoPriority) { | |
3088 prio = java_lang_Thread::priority(thread_oop()); | |
3089 assert(prio != NoPriority, "A valid priority should be present"); | |
3090 } | |
3091 | |
3092 // Push the Java priority down to the native thread; needs Threads_lock | |
3093 Thread::set_priority(this, prio); | |
3094 | |
3095 // Add the new thread to the Threads list and set it in motion. | |
3096 // We must have threads lock in order to call Threads::add. | |
3097 // It is crucial that we do not block before the thread is | |
3098 // added to the Threads list for if a GC happens, then the java_thread oop | |
3099 // will not be visited by GC. | |
3100 Threads::add(this); | |
3101 } | |
3102 | |
3103 oop JavaThread::current_park_blocker() { | |
3104 // Support for JSR-166 locks | |
3105 oop thread_oop = threadObj(); | |
242 | 3106 if (thread_oop != NULL && |
3107 JDK_Version::current().supports_thread_park_blocker()) { | |
0 | 3108 return java_lang_Thread::park_blocker(thread_oop); |
3109 } | |
3110 return NULL; | |
3111 } | |
3112 | |
3113 | |
3114 void JavaThread::print_stack_on(outputStream* st) { | |
3115 if (!has_last_Java_frame()) return; | |
3116 ResourceMark rm; | |
3117 HandleMark hm; | |
3118 | |
3119 RegisterMap reg_map(this); | |
3120 vframe* start_vf = last_java_vframe(®_map); | |
3121 int count = 0; | |
3122 for (vframe* f = start_vf; f; f = f->sender() ) { | |
3123 if (f->is_java_frame()) { | |
3124 javaVFrame* jvf = javaVFrame::cast(f); | |
3125 java_lang_Throwable::print_stack_element(st, jvf->method(), jvf->bci()); | |
3126 | |
3127 // Print out lock information | |
3128 if (JavaMonitorsInStackTrace) { | |
3129 jvf->print_lock_info_on(st, count); | |
3130 } | |
3131 } else { | |
3132 // Ignore non-Java frames | |
3133 } | |
3134 | |
3135 // Bail-out case for too deep stacks | |
3136 count++; | |
3137 if (MaxJavaStackTraceDepth == count) return; | |
3138 } | |
3139 } | |
3140 | |
3141 | |
3142 // JVMTI PopFrame support | |
3143 void JavaThread::popframe_preserve_args(ByteSize size_in_bytes, void* start) { | |
3144 assert(_popframe_preserved_args == NULL, "should not wipe out old PopFrame preserved arguments"); | |
3145 if (in_bytes(size_in_bytes) != 0) { | |
6197 | 3146 _popframe_preserved_args = NEW_C_HEAP_ARRAY(char, in_bytes(size_in_bytes), mtThread); |
0 | 3147 _popframe_preserved_args_size = in_bytes(size_in_bytes); |
1603
d93949c5bdcc
6730276: JDI_REGRESSION tests fail with "Error: count must be non-zero" error on x86
kvn
parents:
1584
diff
changeset
|
3148 Copy::conjoint_jbytes(start, _popframe_preserved_args, _popframe_preserved_args_size); |
0 | 3149 } |
3150 } | |
3151 | |
3152 void* JavaThread::popframe_preserved_args() { | |
3153 return _popframe_preserved_args; | |
3154 } | |
3155 | |
3156 ByteSize JavaThread::popframe_preserved_args_size() { | |
3157 return in_ByteSize(_popframe_preserved_args_size); | |
3158 } | |
3159 | |
3160 WordSize JavaThread::popframe_preserved_args_size_in_words() { | |
3161 int sz = in_bytes(popframe_preserved_args_size()); | |
3162 assert(sz % wordSize == 0, "argument size must be multiple of wordSize"); | |
3163 return in_WordSize(sz / wordSize); | |
3164 } | |
3165 | |
3166 void JavaThread::popframe_free_preserved_args() { | |
3167 assert(_popframe_preserved_args != NULL, "should not free PopFrame preserved arguments twice"); | |
6197 | 3168 FREE_C_HEAP_ARRAY(char, (char*) _popframe_preserved_args, mtThread); |
0 | 3169 _popframe_preserved_args = NULL; |
3170 _popframe_preserved_args_size = 0; | |
3171 } | |
3172 | |
3173 #ifndef PRODUCT | |
3174 | |
3175 void JavaThread::trace_frames() { | |
3176 tty->print_cr("[Describe stack]"); | |
3177 int frame_no = 1; | |
3178 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { | |
3179 tty->print(" %d. ", frame_no++); | |
3180 fst.current()->print_value_on(tty,this); | |
3181 tty->cr(); | |
3182 } | |
3183 } | |
3184 | |
3908
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3185 class PrintAndVerifyOopClosure: public OopClosure { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3186 protected: |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3187 template <class T> inline void do_oop_work(T* p) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3188 oop obj = oopDesc::load_decode_heap_oop(p); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3189 if (obj == NULL) return; |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3190 tty->print(INTPTR_FORMAT ": ", p); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3191 if (obj->is_oop_or_null()) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3192 if (obj->is_objArray()) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3193 tty->print_cr("valid objArray: " INTPTR_FORMAT, (oopDesc*) obj); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3194 } else { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3195 obj->print(); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3196 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3197 } else { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3198 tty->print_cr("invalid oop: " INTPTR_FORMAT, (oopDesc*) obj); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3199 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3200 tty->cr(); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3201 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3202 public: |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3203 virtual void do_oop(oop* p) { do_oop_work(p); } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3204 virtual void do_oop(narrowOop* p) { do_oop_work(p); } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3205 }; |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3206 |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3207 |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3208 static void oops_print(frame* f, const RegisterMap *map) { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3209 PrintAndVerifyOopClosure print; |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3210 f->print_value(); |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
3211 f->oops_do(&print, NULL, NULL, (RegisterMap*)map); |
3908
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3212 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3213 |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3214 // Print our all the locations that contain oops and whether they are |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3215 // valid or not. This useful when trying to find the oldest frame |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3216 // where an oop has gone bad since the frame walk is from youngest to |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3217 // oldest. |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3218 void JavaThread::trace_oops() { |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3219 tty->print_cr("[Trace oops]"); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3220 frames_do(oops_print); |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3221 } |
7588156f5cf9
7051798: SA-JDI: NPE in Frame.addressOfStackSlot(Frame.java:244)
never
parents:
3899
diff
changeset
|
3222 |
0 | 3223 |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3384
diff
changeset
|
3224 #ifdef ASSERT |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3225 // Print or validate the layout of stack frames |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3226 void JavaThread::print_frame_layout(int depth, bool validate_only) { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3227 ResourceMark rm; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3228 PRESERVE_EXCEPTION_MARK; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3229 FrameValues values; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3230 int frame_no = 0; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3231 for(StackFrameStream fst(this, false); !fst.is_done(); fst.next()) { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3232 fst.current()->describe(values, ++frame_no); |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3233 if (depth == frame_no) break; |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3234 } |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3235 if (validate_only) { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3236 values.validate(); |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3237 } else { |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3238 tty->print_cr("[Describe stack layout]"); |
4042
b20d64f83668
7090904: JSR 292: JRuby junit test crashes in PSScavengeRootsClosure::do_oop
twisti
parents:
4007
diff
changeset
|
3239 values.print(this); |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3240 } |
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3241 } |
3388
a80577f854f9
7045513: JSR 292 inlining causes crashes in methodHandleWalk.cpp
never
parents:
3384
diff
changeset
|
3242 #endif |
3336
2e038ad0c1d0
7009361: JSR 292 Invalid value on stack on solaris-sparc with -Xcomp
never
parents:
2416
diff
changeset
|
3243 |
0 | 3244 void JavaThread::trace_stack_from(vframe* start_vf) { |
3245 ResourceMark rm; | |
3246 int vframe_no = 1; | |
3247 for (vframe* f = start_vf; f; f = f->sender() ) { | |
3248 if (f->is_java_frame()) { | |
3249 javaVFrame::cast(f)->print_activation(vframe_no++); | |
3250 } else { | |
3251 f->print(); | |
3252 } | |
3253 if (vframe_no > StackPrintLimit) { | |
3254 tty->print_cr("...<more frames>..."); | |
3255 return; | |
3256 } | |
3257 } | |
3258 } | |
3259 | |
3260 | |
3261 void JavaThread::trace_stack() { | |
3262 if (!has_last_Java_frame()) return; | |
3263 ResourceMark rm; | |
3264 HandleMark hm; | |
3265 RegisterMap reg_map(this); | |
3266 trace_stack_from(last_java_vframe(®_map)); | |
3267 } | |
3268 | |
3269 | |
3270 #endif // PRODUCT | |
3271 | |
3272 | |
3273 javaVFrame* JavaThread::last_java_vframe(RegisterMap *reg_map) { | |
3274 assert(reg_map != NULL, "a map must be given"); | |
3275 frame f = last_frame(); | |
3276 for (vframe* vf = vframe::new_vframe(&f, reg_map, this); vf; vf = vf->sender() ) { | |
3277 if (vf->is_java_frame()) return javaVFrame::cast(vf); | |
3278 } | |
3279 return NULL; | |
3280 } | |
3281 | |
3282 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3283 Klass* JavaThread::security_get_caller_class(int depth) { |
0 | 3284 vframeStream vfst(this); |
3285 vfst.security_get_caller_frame(depth); | |
3286 if (!vfst.at_end()) { | |
3287 return vfst.method()->method_holder(); | |
3288 } | |
3289 return NULL; | |
3290 } | |
3291 | |
3292 static void compiler_thread_entry(JavaThread* thread, TRAPS) { | |
3293 assert(thread->is_Compiler_thread(), "must be compiler thread"); | |
3294 CompileBroker::compiler_thread_loop(); | |
3295 } | |
3296 | |
3297 // Create a CompilerThread | |
3298 CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters) | |
3299 : JavaThread(&compiler_thread_entry) { | |
3300 _env = NULL; | |
3301 _log = NULL; | |
3302 _task = NULL; | |
3303 _queue = queue; | |
3304 _counters = counters; | |
1584 | 3305 _buffer_blob = NULL; |
3384
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3306 _scanned_nmethod = NULL; |
12880
469216acdb28
8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents:
12316
diff
changeset
|
3307 _compiler = NULL; |
0 | 3308 |
3309 #ifndef PRODUCT | |
3310 _ideal_graph_printer = NULL; | |
3311 #endif | |
3312 } | |
3313 | |
15463
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
3314 #ifdef COMPILERGRAAL |
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
3315 bool CompilerThread::can_call_java() const { |
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
3316 return _compiler != NULL && _compiler->is_graal(); |
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
3317 } |
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
3318 #endif |
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
3319 |
14909 | 3320 void CompilerThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
3321 JavaThread::oops_do(f, cld_f, cf); |
3384
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3322 if (_scanned_nmethod != NULL && cf != NULL) { |
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3323 // Safepoints can occur when the sweeper is scanning an nmethod so |
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3324 // process it here to make sure it isn't unloaded in the middle of |
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3325 // a scan. |
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3326 cf->do_code_blob(_scanned_nmethod); |
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3327 } |
f52ed367b66d
6996747: SIGSEGV in nmethod::cleanup_inline_caches / CompiledIC::verify
never
parents:
3336
diff
changeset
|
3328 } |
0 | 3329 |
12880
469216acdb28
8023014: CodeSweeperSweepNoFlushTest.java fails with HS crash
anoll
parents:
12316
diff
changeset
|
3330 |
0 | 3331 // ======= Threads ======== |
3332 | |
3333 // The Threads class links together all active threads, and provides | |
3334 // operations over all threads. It is protected by its own Mutex | |
3335 // lock, which is also used in other contexts to protect thread | |
3336 // operations from having the thread being operated on from exiting | |
3337 // and going away unexpectedly (e.g., safepoint synchronization) | |
3338 | |
3339 JavaThread* Threads::_thread_list = NULL; | |
3340 int Threads::_number_of_threads = 0; | |
3341 int Threads::_number_of_non_daemon_threads = 0; | |
3342 int Threads::_return_code = 0; | |
3343 size_t JavaThread::_stack_size_at_create = 0; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3344 #ifdef ASSERT |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3345 bool Threads::_vm_complete = false; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3346 #endif |
0 | 3347 |
3348 // All JavaThreads | |
3349 #define ALL_JAVA_THREADS(X) for (JavaThread* X = _thread_list; X; X = X->next()) | |
3350 | |
3351 // All JavaThreads + all non-JavaThreads (i.e., every thread in the system) | |
3352 void Threads::threads_do(ThreadClosure* tc) { | |
3353 assert_locked_or_safepoint(Threads_lock); | |
3354 // ALL_JAVA_THREADS iterates through all JavaThreads | |
3355 ALL_JAVA_THREADS(p) { | |
3356 tc->do_thread(p); | |
3357 } | |
3358 // Someday we could have a table or list of all non-JavaThreads. | |
3359 // For now, just manually iterate through them. | |
3360 tc->do_thread(VMThread::vm_thread()); | |
3361 Universe::heap()->gc_threads_do(tc); | |
323
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3362 WatcherThread *wt = WatcherThread::watcher_thread(); |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3363 // Strictly speaking, the following NULL check isn't sufficient to make sure |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3364 // the data for WatcherThread is still valid upon being examined. However, |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3365 // considering that WatchThread terminates when the VM is on the way to |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3366 // exit at safepoint, the chance of the above is extremely small. The right |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3367 // way to prevent termination of WatcherThread would be to acquire |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3368 // Terminator_lock, but we can't do that without violating the lock rank |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3369 // checking in some cases. |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3370 if (wt != NULL) |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3371 tc->do_thread(wt); |
b33eef719520
6740526: sun/management/HotspotThreadMBean/GetInternalThreads.java test failed
xlu
parents:
286
diff
changeset
|
3372 |
0 | 3373 // If CompilerThreads ever become non-JavaThreads, add them here |
3374 } | |
3375 | |
3376 jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { | |
3377 | |
242 | 3378 extern void JDK_Version_init(); |
3379 | |
0 | 3380 // Check version |
3381 if (!is_supported_jni_version(args->version)) return JNI_EVERSION; | |
3382 | |
3383 // Initialize the output stream module | |
3384 ostream_init(); | |
3385 | |
3386 // Process java launcher properties. | |
3387 Arguments::process_sun_java_launcher_properties(args); | |
3388 | |
3389 // Initialize the os module before using TLS | |
3390 os::init(); | |
3391 | |
3392 // Initialize system properties. | |
3393 Arguments::init_system_properties(); | |
3394 | |
14909 | 3395 // So that JDK version can be used as a discrimintor when parsing arguments |
242 | 3396 JDK_Version_init(); |
3397 | |
1864
dfb38ea7da17
6988363: Rebrand vm vendor property settings (jdk7 only)
zgu
parents:
1731
diff
changeset
|
3398 // Update/Initialize System properties after JDK version number is known |
dfb38ea7da17
6988363: Rebrand vm vendor property settings (jdk7 only)
zgu
parents:
1731
diff
changeset
|
3399 Arguments::init_version_specific_system_properties(); |
dfb38ea7da17
6988363: Rebrand vm vendor property settings (jdk7 only)
zgu
parents:
1731
diff
changeset
|
3400 |
0 | 3401 // Parse arguments |
3402 jint parse_result = Arguments::parse(args); | |
3403 if (parse_result != JNI_OK) return parse_result; | |
3404 | |
12233
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12173
diff
changeset
|
3405 os::init_before_ergo(); |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12173
diff
changeset
|
3406 |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12173
diff
changeset
|
3407 jint ergo_result = Arguments::apply_ergo(); |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12173
diff
changeset
|
3408 if (ergo_result != JNI_OK) return ergo_result; |
40136aa2cdb1
8010722: assert: failed: heap size is too big for compressed oops
tschatzl
parents:
12173
diff
changeset
|
3409 |
0 | 3410 if (PauseAtStartup) { |
3411 os::pause(); | |
3412 } | |
3413 | |
14909 | 3414 #ifndef USDT2 |
3415 HS_DTRACE_PROBE(hotspot, vm__init__begin); | |
3416 #else /* USDT2 */ | |
4006 | 3417 HOTSPOT_VM_INIT_BEGIN(); |
14909 | 3418 #endif /* USDT2 */ |
0 | 3419 |
3420 // Record VM creation timing statistics | |
3421 TraceVmCreationTime create_vm_timer; | |
3422 create_vm_timer.start(); | |
3423 | |
3424 // Timing (must come after argument parsing) | |
3425 TraceTime timer("Create VM", TraceStartupTime); | |
3426 | |
3427 // Initialize the os module after parsing the args | |
3428 jint os_init_2_result = os::init_2(); | |
3429 if (os_init_2_result != JNI_OK) return os_init_2_result; | |
3430 | |
7177
53715fb1597d
7198334: UseNUMA modifies system parameters on non-NUMA system
brutisso
parents:
6985
diff
changeset
|
3431 jint adjust_after_os_result = Arguments::adjust_after_os(); |
53715fb1597d
7198334: UseNUMA modifies system parameters on non-NUMA system
brutisso
parents:
6985
diff
changeset
|
3432 if (adjust_after_os_result != JNI_OK) return adjust_after_os_result; |
53715fb1597d
7198334: UseNUMA modifies system parameters on non-NUMA system
brutisso
parents:
6985
diff
changeset
|
3433 |
14909 | 3434 // intialize TLS |
6197 | 3435 ThreadLocalStorage::init(); |
3436 | |
3437 // Bootstrap native memory tracking, so it can start recording memory | |
3438 // activities before worker thread is started. This is the first phase | |
3439 // of bootstrapping, VM is currently running in single-thread mode. | |
3440 MemTracker::bootstrap_single_thread(); | |
3441 | |
0 | 3442 // Initialize output stream logging |
3443 ostream_init_log(); | |
3444 | |
3445 // Convert -Xrun to -agentlib: if there is no JVM_OnLoad | |
3446 // Must be before create_vm_init_agents() | |
3447 if (Arguments::init_libraries_at_startup()) { | |
3448 convert_vm_init_libraries_to_agents(); | |
3449 } | |
3450 | |
3451 // Launch -agentlib/-agentpath and converted -Xrun agents | |
3452 if (Arguments::init_agents_at_startup()) { | |
3453 create_vm_init_agents(); | |
3454 } | |
3455 | |
3456 // Initialize Threads state | |
3457 _thread_list = NULL; | |
3458 _number_of_threads = 0; | |
3459 _number_of_non_daemon_threads = 0; | |
3460 | |
3461 // Initialize global data structures and create system classes in heap | |
3462 vm_init_globals(); | |
3463 | |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3464 #ifdef GRAAL |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3465 if (GraalCounterSize > 0) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3466 JavaThread::_graal_old_thread_counters = NEW_C_HEAP_ARRAY(jlong, GraalCounterSize, mtInternal); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3467 memset(JavaThread::_graal_old_thread_counters, 0, sizeof(jlong) * GraalCounterSize); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3468 } else { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3469 JavaThread::_graal_old_thread_counters = NULL; |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3470 } |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3471 #endif // GRAAL |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
3472 |
0 | 3473 // Attach the main thread to this os thread |
3474 JavaThread* main_thread = new JavaThread(); | |
3475 main_thread->set_thread_state(_thread_in_vm); | |
3476 // must do this before set_active_handles and initialize_thread_local_storage | |
3477 // Note: on solaris initialize_thread_local_storage() will (indirectly) | |
3478 // change the stack size recorded here to one based on the java thread | |
3479 // stacksize. This adjusted size is what is used to figure the placement | |
3480 // of the guard pages. | |
3481 main_thread->record_stack_base_and_size(); | |
3482 main_thread->initialize_thread_local_storage(); | |
3483 | |
3484 main_thread->set_active_handles(JNIHandleBlock::allocate_block()); | |
3485 | |
3486 if (!main_thread->set_as_starting_thread()) { | |
3487 vm_shutdown_during_initialization( | |
3488 "Failed necessary internal allocation. Out of swap space"); | |
3489 delete main_thread; | |
3490 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again | |
3491 return JNI_ENOMEM; | |
3492 } | |
3493 | |
3494 // Enable guard page *after* os::create_main_thread(), otherwise it would | |
3495 // crash Linux VM, see notes in os_linux.cpp. | |
3496 main_thread->create_stack_guard_pages(); | |
3497 | |
1878 | 3498 // Initialize Java-Level synchronization subsystem |
3499 ObjectMonitor::Initialize() ; | |
0 | 3500 |
6197 | 3501 // Second phase of bootstrapping, VM is about entering multi-thread mode |
3502 MemTracker::bootstrap_multi_thread(); | |
3503 | |
0 | 3504 // Initialize global modules |
3505 jint status = init_globals(); | |
3506 if (status != JNI_OK) { | |
3507 delete main_thread; | |
3508 *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again | |
3509 return status; | |
3510 } | |
3511 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3512 // Should be done after the heap is fully created |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3513 main_thread->cache_global_variables(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3514 |
0 | 3515 HandleMark hm; |
3516 | |
3517 { MutexLocker mu(Threads_lock); | |
3518 Threads::add(main_thread); | |
3519 } | |
3520 | |
3521 // Any JVMTI raw monitors entered in onload will transition into | |
3522 // real raw monitor. VM is setup enough here for raw monitor enter. | |
3523 JvmtiExport::transition_pending_onload_raw_monitors(); | |
3524 | |
6197 | 3525 // Fully start NMT |
3526 MemTracker::start(); | |
3527 | |
0 | 3528 // Create the VMThread |
3529 { TraceTime timer("Start VMThread", TraceStartupTime); | |
3530 VMThread::create(); | |
3531 Thread* vmthread = VMThread::vm_thread(); | |
3532 | |
3533 if (!os::create_thread(vmthread, os::vm_thread)) | |
3534 vm_exit_during_initialization("Cannot create VM thread. Out of system resources."); | |
3535 | |
3536 // Wait for the VM thread to become ready, and VMThread::run to initialize | |
3537 // Monitors can have spurious returns, must always check another state flag | |
3538 { | |
3539 MutexLocker ml(Notify_lock); | |
3540 os::start_thread(vmthread); | |
3541 while (vmthread->active_handles() == NULL) { | |
3542 Notify_lock->wait(); | |
3543 } | |
3544 } | |
3545 } | |
3546 | |
3547 assert (Universe::is_fully_initialized(), "not initialized"); | |
9071
68fe50d4f1d5
8011343: Add new flag for verifying the heap during startup
johnc
parents:
8855
diff
changeset
|
3548 if (VerifyDuringStartup) { |
10186
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
9071
diff
changeset
|
3549 // Make sure we're starting with a clean slate. |
b06ac540229e
8013132: Add a flag to turn off the output of the verbose verification code
stefank
parents:
9071
diff
changeset
|
3550 VM_Verify verify_op; |
9071
68fe50d4f1d5
8011343: Add new flag for verifying the heap during startup
johnc
parents:
8855
diff
changeset
|
3551 VMThread::execute(&verify_op); |
8855
24ef5fb05e0f
8010463: G1: Crashes with -UseTLAB and heap verification
johnc
parents:
8793
diff
changeset
|
3552 } |
24ef5fb05e0f
8010463: G1: Crashes with -UseTLAB and heap verification
johnc
parents:
8793
diff
changeset
|
3553 |
14909 | 3554 EXCEPTION_MARK; |
0 | 3555 |
3556 // At this point, the Universe is initialized, but we have not executed | |
3557 // any byte code. Now is a good time (the only time) to dump out the | |
3558 // internal state of the JVM for sharing. | |
3559 if (DumpSharedSpaces) { | |
14909 | 3560 MetaspaceShared::preload_and_dump(CHECK_0); |
0 | 3561 ShouldNotReachHere(); |
3562 } | |
3563 | |
3564 // Always call even when there are not JVMTI environments yet, since environments | |
3565 // may be attached late and JVMTI must track phases of VM execution | |
3566 JvmtiExport::enter_start_phase(); | |
3567 | |
3568 // Notify JVMTI agents that VM has started (JNI is up) - nop if no agents. | |
3569 JvmtiExport::post_vm_start(); | |
3570 | |
14909 | 3571 { |
3572 TraceTime timer("Initialize java.lang classes", TraceStartupTime); | |
3573 | |
3574 if (EagerXrunInit && Arguments::init_libraries_at_startup()) { | |
3575 create_vm_init_libraries(); | |
3576 } | |
3577 | |
3578 initialize_class(vmSymbols::java_lang_String(), CHECK_0); | |
3579 | |
3580 // Initialize java_lang.System (needed before creating the thread) | |
3581 initialize_class(vmSymbols::java_lang_System(), CHECK_0); | |
3582 initialize_class(vmSymbols::java_lang_ThreadGroup(), CHECK_0); | |
3583 Handle thread_group = create_initial_thread_group(CHECK_0); | |
3584 Universe::set_main_thread_group(thread_group()); | |
3585 initialize_class(vmSymbols::java_lang_Thread(), CHECK_0); | |
3586 oop thread_object = create_initial_thread(thread_group, main_thread, CHECK_0); | |
3587 main_thread->set_threadObj(thread_object); | |
3588 // Set thread status to running since main thread has | |
3589 // been started and running. | |
3590 java_lang_Thread::set_thread_status(thread_object, | |
3591 java_lang_Thread::RUNNABLE); | |
3592 | |
3593 // The VM creates & returns objects of this class. Make sure it's initialized. | |
3594 initialize_class(vmSymbols::java_lang_Class(), CHECK_0); | |
3595 | |
3596 // The VM preresolves methods to these classes. Make sure that they get initialized | |
3597 initialize_class(vmSymbols::java_lang_reflect_Method(), CHECK_0); | |
3598 initialize_class(vmSymbols::java_lang_ref_Finalizer(), CHECK_0); | |
3599 call_initializeSystemClass(CHECK_0); | |
3600 | |
3601 // get the Java runtime name after java.lang.System is initialized | |
3602 JDK_Version::set_runtime_name(get_java_runtime_name(THREAD)); | |
3603 JDK_Version::set_runtime_version(get_java_runtime_version(THREAD)); | |
3604 | |
3605 // an instance of OutOfMemory exception has been allocated earlier | |
3606 initialize_class(vmSymbols::java_lang_OutOfMemoryError(), CHECK_0); | |
3607 initialize_class(vmSymbols::java_lang_NullPointerException(), CHECK_0); | |
3608 initialize_class(vmSymbols::java_lang_ClassCastException(), CHECK_0); | |
3609 initialize_class(vmSymbols::java_lang_ArrayStoreException(), CHECK_0); | |
3610 initialize_class(vmSymbols::java_lang_ArithmeticException(), CHECK_0); | |
3611 initialize_class(vmSymbols::java_lang_StackOverflowError(), CHECK_0); | |
3612 initialize_class(vmSymbols::java_lang_IllegalMonitorStateException(), CHECK_0); | |
3613 initialize_class(vmSymbols::java_lang_IllegalArgumentException(), CHECK_0); | |
3614 } | |
3615 | |
3616 // See : bugid 4211085. | |
3617 // Background : the static initializer of java.lang.Compiler tries to read | |
3618 // property"java.compiler" and read & write property "java.vm.info". | |
3619 // When a security manager is installed through the command line | |
3620 // option "-Djava.security.manager", the above properties are not | |
3621 // readable and the static initializer for java.lang.Compiler fails | |
3622 // resulting in a NoClassDefFoundError. This can happen in any | |
3623 // user code which calls methods in java.lang.Compiler. | |
3624 // Hack : the hack is to pre-load and initialize this class, so that only | |
3625 // system domains are on the stack when the properties are read. | |
3626 // Currently even the AWT code has calls to methods in java.lang.Compiler. | |
3627 // On the classic VM, java.lang.Compiler is loaded very early to load the JIT. | |
3628 // Future Fix : the best fix is to grant everyone permissions to read "java.compiler" and | |
3629 // read and write"java.vm.info" in the default policy file. See bugid 4211383 | |
3630 // Once that is done, we should remove this hack. | |
3631 initialize_class(vmSymbols::java_lang_Compiler(), CHECK_0); | |
3632 | |
3633 // More hackery - the static initializer of java.lang.Compiler adds the string "nojit" to | |
3634 // the java.vm.info property if no jit gets loaded through java.lang.Compiler (the hotspot | |
3635 // compiler does not get loaded through java.lang.Compiler). "java -version" with the | |
3636 // hotspot vm says "nojit" all the time which is confusing. So, we reset it here. | |
3637 // This should also be taken out as soon as 4211383 gets fixed. | |
3638 reset_vm_info_property(CHECK_0); | |
0 | 3639 |
3640 quicken_jni_functions(); | |
3641 | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3642 // Must be run after init_ft which initializes ft_enabled |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3643 if (TRACE_INITIALIZE() != JNI_OK) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3644 vm_exit_during_initialization("Failed to initialize tracing backend"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3645 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4873
diff
changeset
|
3646 |
0 | 3647 // Set flag that basic initialization has completed. Used by exceptions and various |
3648 // debug stuff, that does not work until all basic classes have been initialized. | |
3649 set_init_completed(); | |
3650 | |
14909 | 3651 #ifndef USDT2 |
3652 HS_DTRACE_PROBE(hotspot, vm__init__end); | |
3653 #else /* USDT2 */ | |
4006 | 3654 HOTSPOT_VM_INIT_END(); |
14909 | 3655 #endif /* USDT2 */ |
0 | 3656 |
3657 // record VM initialization completion time | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
3658 #if INCLUDE_MANAGEMENT |
0 | 3659 Management::record_vm_init_completed(); |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
3660 #endif // INCLUDE_MANAGEMENT |
0 | 3661 |
3662 // Compute system loader. Note that this has to occur after set_init_completed, since | |
3663 // valid exceptions may be thrown in the process. | |
3664 // Note that we do not use CHECK_0 here since we are inside an EXCEPTION_MARK and | |
3665 // set_init_completed has just been called, causing exceptions not to be shortcut | |
3666 // anymore. We call vm_exit_during_initialization directly instead. | |
14909 | 3667 SystemDictionary::compute_java_system_loader(THREAD); |
3668 if (HAS_PENDING_EXCEPTION) { | |
3669 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | |
3670 } | |
0 | 3671 |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
3672 #if INCLUDE_ALL_GCS |
0 | 3673 // Support for ConcurrentMarkSweep. This should be cleaned up |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3674 // and better encapsulated. The ugly nested if test would go away |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3675 // once things are properly refactored. XXX YSR |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3676 if (UseConcMarkSweepGC || UseG1GC) { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3677 if (UseConcMarkSweepGC) { |
14909 | 3678 ConcurrentMarkSweepThread::makeSurrogateLockerThread(THREAD); |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
62
diff
changeset
|
3679 } else { |
14909 | 3680 ConcurrentMarkThread::makeSurrogateLockerThread(THREAD); |
3681 } | |
3682 if (HAS_PENDING_EXCEPTION) { | |
3683 vm_exit_during_initialization(Handle(THREAD, PENDING_EXCEPTION)); | |
0 | 3684 } |
3685 } | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
3686 #endif // INCLUDE_ALL_GCS |
0 | 3687 |
3688 // Always call even when there are not JVMTI environments yet, since environments | |
3689 // may be attached late and JVMTI must track phases of VM execution | |
3690 JvmtiExport::enter_live_phase(); | |
3691 | |
3692 // Signal Dispatcher needs to be started before VMInit event is posted | |
3693 os::signal_init(); | |
3694 | |
3695 // Start Attach Listener if +StartAttachListener or it can't be started lazily | |
3696 if (!DisableAttachMechanism) { | |
11139
2e8f19c2feef
7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
allwin
parents:
11136
diff
changeset
|
3697 AttachListener::vm_start(); |
0 | 3698 if (StartAttachListener || AttachListener::init_at_startup()) { |
3699 AttachListener::init(); | |
3700 } | |
3701 } | |
3702 | |
3703 // Launch -Xrun agents | |
3704 // Must be done in the JVMTI live phase so that for backward compatibility the JDWP | |
3705 // back-end can launch with -Xdebug -Xrunjdwp. | |
3706 if (!EagerXrunInit && Arguments::init_libraries_at_startup()) { | |
3707 create_vm_init_libraries(); | |
3708 } | |
3709 | |
6002
df4cd4aac5c1
7160924: jvmti: GetPhase returns incorrect phase before VMInit event is issued
rbackman
parents:
5928
diff
changeset
|
3710 // Notify JVMTI agents that VM initialization is complete - nop if no agents. |
df4cd4aac5c1
7160924: jvmti: GetPhase returns incorrect phase before VMInit event is issued
rbackman
parents:
5928
diff
changeset
|
3711 JvmtiExport::post_vm_initialized(); |
df4cd4aac5c1
7160924: jvmti: GetPhase returns incorrect phase before VMInit event is issued
rbackman
parents:
5928
diff
changeset
|
3712 |
10405 | 3713 if (TRACE_START() != JNI_OK) { |
3714 vm_exit_during_initialization("Failed to start tracing backend."); | |
4800
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
3715 } |
94ec88ca68e2
7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents:
4095
diff
changeset
|
3716 |
3799
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3769
diff
changeset
|
3717 if (CleanChunkPoolAsync) { |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3769
diff
changeset
|
3718 Chunk::start_chunk_pool_cleaner_task(); |
48048b59a551
7061204: clean the chunk table synchronously in embedded builds
jcoomes
parents:
3769
diff
changeset
|
3719 } |
0 | 3720 |
3721 // initialize compiler(s) | |
14124
7ad529321294
make: remove GRAALVM and introduce COMPILERGRAAL. fix client hosted-mode
Bernhard Urban <bernhard.urban@jku.at>
parents:
13819
diff
changeset
|
3722 #if defined(COMPILER1) || defined(COMPILER2) || defined(SHARK) || defined(COMPILERGRAAL) |
0 | 3723 CompileBroker::compilation_init(); |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
3724 #endif |
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
3725 |
12163
74608df95ba3
8022595: JSR292: deadlock during class loading of MethodHandles, MethodHandleImpl & MethodHandleNatives
vlivanov
parents:
11154
diff
changeset
|
3726 if (EnableInvokeDynamic) { |
14909 | 3727 // Pre-initialize some JSR292 core classes to avoid deadlock during class loading. |
3728 // It is done after compilers are initialized, because otherwise compilations of | |
3729 // signature polymorphic MH intrinsics can be missed | |
3730 // (see SystemDictionary::find_method_handle_intrinsic). | |
3731 initialize_class(vmSymbols::java_lang_invoke_MethodHandle(), CHECK_0); | |
3732 initialize_class(vmSymbols::java_lang_invoke_MemberName(), CHECK_0); | |
3733 initialize_class(vmSymbols::java_lang_invoke_MethodHandleNatives(), CHECK_0); | |
12163
74608df95ba3
8022595: JSR292: deadlock during class loading of MethodHandles, MethodHandleImpl & MethodHandleNatives
vlivanov
parents:
11154
diff
changeset
|
3734 } |
74608df95ba3
8022595: JSR292: deadlock during class loading of MethodHandles, MethodHandleImpl & MethodHandleNatives
vlivanov
parents:
11154
diff
changeset
|
3735 |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
3736 #if INCLUDE_MANAGEMENT |
0 | 3737 Management::initialize(THREAD); |
14909 | 3738 #endif // INCLUDE_MANAGEMENT |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
3739 |
0 | 3740 if (HAS_PENDING_EXCEPTION) { |
3741 // management agent fails to start possibly due to | |
3742 // configuration problem and is responsible for printing | |
3743 // stack trace if appropriate. Simply exit VM. | |
3744 vm_exit(1); | |
3745 } | |
3746 | |
3747 if (Arguments::has_profile()) FlatProfiler::engage(main_thread, true); | |
3748 if (MemProfiling) MemProfiler::engage(); | |
3749 StatSampler::engage(); | |
3750 if (CheckJNICalls) JniPeriodicChecker::engage(); | |
3751 | |
3752 BiasedLocking::init(); | |
3753 | |
2129
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3754 if (JDK_Version::current().post_vm_init_hook_enabled()) { |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3755 call_postVMInitHook(THREAD); |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3756 // The Java side of PostVMInitHook.run must deal with all |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3757 // exceptions and provide means of diagnosis. |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3758 if (HAS_PENDING_EXCEPTION) { |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3759 CLEAR_PENDING_EXCEPTION; |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3760 } |
8f8dfba37802
6994753: Implement optional hook to a Java method at VM startup.
kevinw
parents:
2126
diff
changeset
|
3761 } |
0 | 3762 |
6939
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3763 { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3764 MutexLockerEx ml(PeriodicTask_lock, Mutex::_no_safepoint_check_flag); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3765 // Make sure the watcher thread can be started by WatcherThread::start() |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3766 // or by dynamic enrollment. |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3767 WatcherThread::make_startable(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3768 // Start up the WatcherThread if there are any periodic tasks |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3769 // NOTE: All PeriodicTasks should be registered by now. If they |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3770 // aren't, late joiners might appear to start slowly (we might |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3771 // take a while to process their first tick). |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3772 if (PeriodicTask::num_tasks() > 0) { |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3773 WatcherThread::start(); |
c284cf4781f0
7127792: Add the ability to change an existing PeriodicTask's execution interval
rbackman
parents:
6921
diff
changeset
|
3774 } |
0 | 3775 } |
3776 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3777 // Give os specific code one last chance to start |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3778 os::init_3(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1608
diff
changeset
|
3779 |
0 | 3780 create_vm_timer.end(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3781 #ifdef ASSERT |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3782 _vm_complete = true; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3783 #endif |
0 | 3784 return JNI_OK; |
3785 } | |
3786 | |
3787 // type for the Agent_OnLoad and JVM_OnLoad entry points | |
3788 extern "C" { | |
3789 typedef jint (JNICALL *OnLoadEntry_t)(JavaVM *, char *, void *); | |
3790 } | |
3791 // Find a command line agent library and return its entry point for | |
3792 // -agentlib: -agentpath: -Xrun | |
3793 // num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array. | |
3794 static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) { | |
3795 OnLoadEntry_t on_load_entry = NULL; | |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3796 void *library = NULL; |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3797 |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3798 if (!agent->valid()) { |
0 | 3799 char buffer[JVM_MAXPATHLEN]; |
3800 char ebuf[1024]; | |
3801 const char *name = agent->name(); | |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3802 const char *msg = "Could not find agent library "; |
0 | 3803 |
12220 | 3804 // First check to see if agent is statically linked into executable |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3805 if (os::find_builtin_agent(agent, on_load_symbols, num_symbol_entries)) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3806 library = agent->os_lib(); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3807 } else if (agent->is_absolute_path()) { |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
3808 library = os::dll_load(name, ebuf, sizeof ebuf); |
0 | 3809 if (library == NULL) { |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3810 const char *sub_msg = " in absolute path, with error: "; |
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3811 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
6197 | 3812 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread); |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3813 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
0 | 3814 // If we can't find the agent, exit. |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3815 vm_exit_during_initialization(buf, NULL); |
6197 | 3816 FREE_C_HEAP_ARRAY(char, buf, mtThread); |
0 | 3817 } |
3818 } else { | |
3819 // Try to load the agent from the standard dll directory | |
6966
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6921
diff
changeset
|
3820 if (os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6921
diff
changeset
|
3821 name)) { |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6921
diff
changeset
|
3822 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6921
diff
changeset
|
3823 } |
0 | 3824 if (library == NULL) { // Try the local directory |
3825 char ns[1] = {0}; | |
6966
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6921
diff
changeset
|
3826 if (os::dll_build_name(buffer, sizeof(buffer), ns, name)) { |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6921
diff
changeset
|
3827 library = os::dll_load(buffer, ebuf, sizeof ebuf); |
6cb0d32b828b
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
6921
diff
changeset
|
3828 } |
0 | 3829 if (library == NULL) { |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3830 const char *sub_msg = " on the library path, with error: "; |
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3831 size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; |
6197 | 3832 char *buf = NEW_C_HEAP_ARRAY(char, len, mtThread); |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3833 jio_snprintf(buf, len, "%s%s%s%s", msg, name, sub_msg, ebuf); |
0 | 3834 // If we can't find the agent, exit. |
1694
ab3fd720516c
6378314: Bad warning message when agent library not found. local directory is not searched.
rasbold
parents:
1681
diff
changeset
|
3835 vm_exit_during_initialization(buf, NULL); |
6197 | 3836 FREE_C_HEAP_ARRAY(char, buf, mtThread); |
0 | 3837 } |
3838 } | |
3839 } | |
3840 agent->set_os_lib(library); | |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3841 agent->set_valid(); |
0 | 3842 } |
3843 | |
3844 // Find the OnLoad function. | |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3845 on_load_entry = |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3846 CAST_TO_FN_PTR(OnLoadEntry_t, os::find_agent_function(agent, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3847 false, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3848 on_load_symbols, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3849 num_symbol_entries)); |
0 | 3850 return on_load_entry; |
3851 } | |
3852 | |
3853 // Find the JVM_OnLoad entry point | |
3854 static OnLoadEntry_t lookup_jvm_on_load(AgentLibrary* agent) { | |
3855 const char *on_load_symbols[] = JVM_ONLOAD_SYMBOLS; | |
3856 return lookup_on_load(agent, on_load_symbols, sizeof(on_load_symbols) / sizeof(char*)); | |
3857 } | |
3858 | |
3859 // Find the Agent_OnLoad entry point | |
3860 static OnLoadEntry_t lookup_agent_on_load(AgentLibrary* agent) { | |
3861 const char *on_load_symbols[] = AGENT_ONLOAD_SYMBOLS; | |
3862 return lookup_on_load(agent, on_load_symbols, sizeof(on_load_symbols) / sizeof(char*)); | |
3863 } | |
3864 | |
3865 // For backwards compatibility with -Xrun | |
3866 // Convert libraries with no JVM_OnLoad, but which have Agent_OnLoad to be | |
3867 // treated like -agentpath: | |
3868 // Must be called before agent libraries are created | |
3869 void Threads::convert_vm_init_libraries_to_agents() { | |
3870 AgentLibrary* agent; | |
3871 AgentLibrary* next; | |
3872 | |
3873 for (agent = Arguments::libraries(); agent != NULL; agent = next) { | |
3874 next = agent->next(); // cache the next agent now as this agent may get moved off this list | |
3875 OnLoadEntry_t on_load_entry = lookup_jvm_on_load(agent); | |
3876 | |
3877 // If there is an JVM_OnLoad function it will get called later, | |
3878 // otherwise see if there is an Agent_OnLoad | |
3879 if (on_load_entry == NULL) { | |
3880 on_load_entry = lookup_agent_on_load(agent); | |
3881 if (on_load_entry != NULL) { | |
3882 // switch it to the agent list -- so that Agent_OnLoad will be called, | |
3883 // JVM_OnLoad won't be attempted and Agent_OnUnload will | |
3884 Arguments::convert_library_to_agent(agent); | |
3885 } else { | |
3886 vm_exit_during_initialization("Could not find JVM_OnLoad or Agent_OnLoad function in the library", agent->name()); | |
3887 } | |
3888 } | |
3889 } | |
3890 } | |
3891 | |
3892 // Create agents for -agentlib: -agentpath: and converted -Xrun | |
3893 // Invokes Agent_OnLoad | |
3894 // Called very early -- before JavaThreads exist | |
3895 void Threads::create_vm_init_agents() { | |
3896 extern struct JavaVM_ main_vm; | |
3897 AgentLibrary* agent; | |
3898 | |
3899 JvmtiExport::enter_onload_phase(); | |
6854
fb19af007ffc
7189254: Change makefiles for more flexibility to override defaults
jprovino
parents:
6769
diff
changeset
|
3900 |
0 | 3901 for (agent = Arguments::agents(); agent != NULL; agent = agent->next()) { |
3902 OnLoadEntry_t on_load_entry = lookup_agent_on_load(agent); | |
3903 | |
3904 if (on_load_entry != NULL) { | |
3905 // Invoke the Agent_OnLoad function | |
3906 jint err = (*on_load_entry)(&main_vm, agent->options(), NULL); | |
3907 if (err != JNI_OK) { | |
3908 vm_exit_during_initialization("agent library failed to init", agent->name()); | |
3909 } | |
3910 } else { | |
3911 vm_exit_during_initialization("Could not find Agent_OnLoad function in the agent library", agent->name()); | |
3912 } | |
3913 } | |
3914 JvmtiExport::enter_primordial_phase(); | |
3915 } | |
3916 | |
3917 extern "C" { | |
3918 typedef void (JNICALL *Agent_OnUnload_t)(JavaVM *); | |
3919 } | |
3920 | |
3921 void Threads::shutdown_vm_agents() { | |
3922 // Send any Agent_OnUnload notifications | |
3923 const char *on_unload_symbols[] = AGENT_ONUNLOAD_SYMBOLS; | |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3924 size_t num_symbol_entries = ARRAY_SIZE(on_unload_symbols); |
0 | 3925 extern struct JavaVM_ main_vm; |
3926 for (AgentLibrary* agent = Arguments::agents(); agent != NULL; agent = agent->next()) { | |
3927 | |
3928 // Find the Agent_OnUnload function. | |
12117
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3929 Agent_OnUnload_t unload_entry = CAST_TO_FN_PTR(Agent_OnUnload_t, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3930 os::find_agent_function(agent, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3931 false, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3932 on_unload_symbols, |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3933 num_symbol_entries)); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3934 |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3935 // Invoke the Agent_OnUnload function |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3936 if (unload_entry != NULL) { |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3937 JavaThread* thread = JavaThread::current(); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3938 ThreadToNativeFromVM ttn(thread); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3939 HandleMark hm(thread); |
f92b82d454fa
8014135: The JVMTI specification does not conform to recent changes in JNI specification
bpittore
parents:
11154
diff
changeset
|
3940 (*unload_entry)(&main_vm); |
0 | 3941 } |
3942 } | |
3943 } | |
3944 | |
3945 // Called for after the VM is initialized for -Xrun libraries which have not been converted to agent libraries | |
3946 // Invokes JVM_OnLoad | |
3947 void Threads::create_vm_init_libraries() { | |
3948 extern struct JavaVM_ main_vm; | |
3949 AgentLibrary* agent; | |
3950 | |
3951 for (agent = Arguments::libraries(); agent != NULL; agent = agent->next()) { | |
3952 OnLoadEntry_t on_load_entry = lookup_jvm_on_load(agent); | |
3953 | |
3954 if (on_load_entry != NULL) { | |
3955 // Invoke the JVM_OnLoad function | |
3956 JavaThread* thread = JavaThread::current(); | |
3957 ThreadToNativeFromVM ttn(thread); | |
3958 HandleMark hm(thread); | |
3959 jint err = (*on_load_entry)(&main_vm, agent->options(), NULL); | |
3960 if (err != JNI_OK) { | |
3961 vm_exit_during_initialization("-Xrun library failed to init", agent->name()); | |
3962 } | |
3963 } else { | |
3964 vm_exit_during_initialization("Could not find JVM_OnLoad function in -Xrun library", agent->name()); | |
3965 } | |
3966 } | |
3967 } | |
3968 | |
3969 // Last thread running calls java.lang.Shutdown.shutdown() | |
3970 void JavaThread::invoke_shutdown_hooks() { | |
3971 HandleMark hm(this); | |
3972 | |
3973 // We could get here with a pending exception, if so clear it now. | |
3974 if (this->has_pending_exception()) { | |
3975 this->clear_pending_exception(); | |
3976 } | |
3977 | |
3978 EXCEPTION_MARK; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
3979 Klass* k = |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3980 SystemDictionary::resolve_or_null(vmSymbols::java_lang_Shutdown(), |
0 | 3981 THREAD); |
3982 if (k != NULL) { | |
3983 // SystemDictionary::resolve_or_null will return null if there was | |
3984 // an exception. If we cannot load the Shutdown class, just don't | |
3985 // call Shutdown.shutdown() at all. This will mean the shutdown hooks | |
3986 // and finalizers (if runFinalizersOnExit is set) won't be run. | |
3987 // Note that if a shutdown hook was registered or runFinalizersOnExit | |
3988 // was called, the Shutdown class would have already been loaded | |
3989 // (Runtime.addShutdownHook and runFinalizersOnExit will load it). | |
3990 instanceKlassHandle shutdown_klass (THREAD, k); | |
3991 JavaValue result(T_VOID); | |
3992 JavaCalls::call_static(&result, | |
3993 shutdown_klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3994 vmSymbols::shutdown_method_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2162
diff
changeset
|
3995 vmSymbols::void_method_signature(), |
0 | 3996 THREAD); |
3997 } | |
3998 CLEAR_PENDING_EXCEPTION; | |
3999 } | |
4000 | |
4001 // Threads::destroy_vm() is normally called from jni_DestroyJavaVM() when | |
4002 // the program falls off the end of main(). Another VM exit path is through | |
4003 // vm_exit() when the program calls System.exit() to return a value or when | |
4004 // there is a serious error in VM. The two shutdown paths are not exactly | |
4005 // the same, but they share Shutdown.shutdown() at Java level and before_exit() | |
4006 // and VM_Exit op at VM level. | |
4007 // | |
4008 // Shutdown sequence: | |
6197 | 4009 // + Shutdown native memory tracking if it is on |
0 | 4010 // + Wait until we are the last non-daemon thread to execute |
4011 // <-- every thing is still working at this moment --> | |
4012 // + Call java.lang.Shutdown.shutdown(), which will invoke Java level | |
4013 // shutdown hooks, run finalizers if finalization-on-exit | |
4014 // + Call before_exit(), prepare for VM exit | |
4015 // > run VM level shutdown hooks (they are registered through JVM_OnExit(), | |
4016 // currently the only user of this mechanism is File.deleteOnExit()) | |
4017 // > stop flat profiler, StatSampler, watcher thread, CMS threads, | |
4018 // post thread end and vm death events to JVMTI, | |
4019 // stop signal thread | |
4020 // + Call JavaThread::exit(), it will: | |
4021 // > release JNI handle blocks, remove stack guard pages | |
4022 // > remove this thread from Threads list | |
4023 // <-- no more Java code from this thread after this point --> | |
4024 // + Stop VM thread, it will bring the remaining VM to a safepoint and stop | |
4025 // the compiler threads at safepoint | |
4026 // <-- do not use anything that could get blocked by Safepoint --> | |
4027 // + Disable tracing at JNI/JVM barriers | |
4028 // + Set _vm_exited flag for threads that are still running native code | |
4029 // + Delete this thread | |
4030 // + Call exit_globals() | |
4031 // > deletes tty | |
4032 // > deletes PerfMemory resources | |
4033 // + Return to caller | |
4034 | |
4035 bool Threads::destroy_vm() { | |
4036 JavaThread* thread = JavaThread::current(); | |
4037 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4038 #ifdef ASSERT |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4039 _vm_complete = false; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4040 #endif |
0 | 4041 // Wait until we are the last non-daemon thread to execute |
4042 { MutexLocker nu(Threads_lock); | |
4043 while (Threads::number_of_non_daemon_threads() > 1 ) | |
4044 // This wait should make safepoint checks, wait without a timeout, | |
4045 // and wait as a suspend-equivalent condition. | |
4046 // | |
4047 // Note: If the FlatProfiler is running and this thread is waiting | |
4048 // for another non-daemon thread to finish, then the FlatProfiler | |
4049 // is waiting for the external suspend request on this thread to | |
4050 // complete. wait_for_ext_suspend_completion() will eventually | |
4051 // timeout, but that takes time. Making this wait a suspend- | |
4052 // equivalent condition solves that timeout problem. | |
4053 // | |
4054 Threads_lock->wait(!Mutex::_no_safepoint_check_flag, 0, | |
4055 Mutex::_as_suspend_equivalent_flag); | |
4056 } | |
4057 | |
4058 // Hang forever on exit if we are reporting an error. | |
4059 if (ShowMessageBoxOnError && is_error_reported()) { | |
4060 os::infinite_sleep(); | |
4061 } | |
2302
da091bb67459
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
2203
diff
changeset
|
4062 os::wait_for_keypress_at_exit(); |
0 | 4063 |
4064 if (JDK_Version::is_jdk12x_version()) { | |
4065 // We are the last thread running, so check if finalizers should be run. | |
4066 // For 1.3 or later this is done in thread->invoke_shutdown_hooks() | |
4067 HandleMark rm(thread); | |
4068 Universe::run_finalizers_on_exit(); | |
4069 } else { | |
4070 // run Java level shutdown hooks | |
4071 thread->invoke_shutdown_hooks(); | |
4072 } | |
4073 | |
4074 before_exit(thread); | |
4075 | |
4076 thread->exit(true); | |
4077 | |
4078 // Stop VM thread. | |
4079 { | |
4080 // 4945125 The vm thread comes to a safepoint during exit. | |
4081 // GC vm_operations can get caught at the safepoint, and the | |
4082 // heap is unparseable if they are caught. Grab the Heap_lock | |
4083 // to prevent this. The GC vm_operations will not be able to | |
4084 // queue until after the vm thread is dead. | |
3769
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4085 // After this point, we'll never emerge out of the safepoint before |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4086 // the VM exits, so concurrent GC threads do not need to be explicitly |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4087 // stopped; they remain inactive until the process exits. |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4088 // Note: some concurrent G1 threads may be running during a safepoint, |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4089 // but these will not be accessing the heap, just some G1-specific side |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4090 // data structures that are not accessed by any other threads but them |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4091 // after this point in a terminal safepoint. |
ef2d1b8f2dd4
7051430: CMS: ongoing CMS cycle should terminate abruptly to allow prompt JVM termination at exit
ysr
parents:
3388
diff
changeset
|
4092 |
0 | 4093 MutexLocker ml(Heap_lock); |
4094 | |
4095 VMThread::wait_for_vm_thread_exit(); | |
4096 assert(SafepointSynchronize::is_at_safepoint(), "VM thread should exit at Safepoint"); | |
4097 VMThread::destroy(); | |
4098 } | |
4099 | |
4100 // clean up ideal graph printers | |
4101 #if defined(COMPILER2) && !defined(PRODUCT) | |
4102 IdealGraphPrinter::clean_up(); | |
4103 #endif | |
4104 | |
4105 // Now, all Java threads are gone except daemon threads. Daemon threads | |
4106 // running Java code or in VM are stopped by the Safepoint. However, | |
4107 // daemon threads executing native code are still running. But they | |
4108 // will be stopped at native=>Java/VM barriers. Note that we can't | |
4109 // simply kill or suspend them, as it is inherently deadlock-prone. | |
4110 | |
4111 #ifndef PRODUCT | |
4112 // disable function tracing at JNI/JVM barriers | |
4113 TraceJNICalls = false; | |
4114 TraceJVMCalls = false; | |
4115 TraceRuntimeCalls = false; | |
4116 #endif | |
4117 | |
4118 VM_Exit::set_vm_exited(); | |
4119 | |
4120 notify_vm_shutdown(); | |
4121 | |
4122 delete thread; | |
4123 | |
13796
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
4124 #ifdef GRAAL |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
4125 if (GraalCounterSize > 0) { |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
4126 FREE_C_HEAP_ARRAY(jlong, JavaThread::_graal_old_thread_counters, mtInternal); |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
4127 } |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
4128 #endif // GRAAL |
8cd953e97e2d
rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents:
13739
diff
changeset
|
4129 |
0 | 4130 // exit_globals() will delete tty |
4131 exit_globals(); | |
4132 | |
4133 return true; | |
4134 } | |
4135 | |
4136 | |
4137 jboolean Threads::is_supported_jni_version_including_1_1(jint version) { | |
4138 if (version == JNI_VERSION_1_1) return JNI_TRUE; | |
4139 return is_supported_jni_version(version); | |
4140 } | |
4141 | |
4142 | |
4143 jboolean Threads::is_supported_jni_version(jint version) { | |
4144 if (version == JNI_VERSION_1_2) return JNI_TRUE; | |
4145 if (version == JNI_VERSION_1_4) return JNI_TRUE; | |
4146 if (version == JNI_VERSION_1_6) return JNI_TRUE; | |
8793
499ccc15bbc8
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
bpittore
parents:
8673
diff
changeset
|
4147 if (version == JNI_VERSION_1_8) return JNI_TRUE; |
0 | 4148 return JNI_FALSE; |
4149 } | |
4150 | |
4151 | |
4152 void Threads::add(JavaThread* p, bool force_daemon) { | |
4153 // The threads lock must be owned at this point | |
4154 assert_locked_or_safepoint(Threads_lock); | |
1842
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
4155 |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
4156 // See the comment for this method in thread.hpp for its purpose and |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
4157 // why it is called here. |
6e0aac35bfa9
6980838: G1: guarantee(false) failed: thread has an unexpected active value in its SATB queue
tonyp
parents:
1838
diff
changeset
|
4158 p->initialize_queues(); |
0 | 4159 p->set_next(_thread_list); |
4160 _thread_list = p; | |
4161 _number_of_threads++; | |
4162 oop threadObj = p->threadObj(); | |
4163 bool daemon = true; | |
4164 // Bootstrapping problem: threadObj can be null for initial | |
4165 // JavaThread (or for threads attached via JNI) | |
4166 if ((!force_daemon) && (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj))) { | |
4167 _number_of_non_daemon_threads++; | |
4168 daemon = false; | |
4169 } | |
4170 | |
6197 | 4171 p->set_safepoint_visible(true); |
4172 | |
0 | 4173 ThreadService::add_thread(p, daemon); |
4174 | |
4175 // Possible GC point. | |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4800
diff
changeset
|
4176 Events::log(p, "Thread added: " INTPTR_FORMAT, p); |
0 | 4177 } |
4178 | |
4179 void Threads::remove(JavaThread* p) { | |
4180 // Extra scope needed for Thread_lock, so we can check | |
4181 // that we do not remove thread without safepoint code notice | |
4182 { MutexLocker ml(Threads_lock); | |
4183 | |
4184 assert(includes(p), "p must be present"); | |
4185 | |
4186 JavaThread* current = _thread_list; | |
4187 JavaThread* prev = NULL; | |
4188 | |
4189 while (current != p) { | |
4190 prev = current; | |
4191 current = current->next(); | |
4192 } | |
4193 | |
4194 if (prev) { | |
4195 prev->set_next(current->next()); | |
4196 } else { | |
4197 _thread_list = p->next(); | |
4198 } | |
4199 _number_of_threads--; | |
4200 oop threadObj = p->threadObj(); | |
4201 bool daemon = true; | |
4202 if (threadObj == NULL || !java_lang_Thread::is_daemon(threadObj)) { | |
4203 _number_of_non_daemon_threads--; | |
4204 daemon = false; | |
4205 | |
4206 // Only one thread left, do a notify on the Threads_lock so a thread waiting | |
4207 // on destroy_vm will wake up. | |
4208 if (number_of_non_daemon_threads() == 1) | |
4209 Threads_lock->notify_all(); | |
4210 } | |
4211 ThreadService::remove_thread(p, daemon); | |
4212 | |
4213 // Make sure that safepoint code disregard this thread. This is needed since | |
4214 // the thread might mess around with locks after this point. This can cause it | |
4215 // to do callbacks into the safepoint code. However, the safepoint code is not aware | |
4216 // of this thread since it is removed from the queue. | |
4217 p->set_terminated_value(); | |
6197 | 4218 |
4219 // Now, this thread is not visible to safepoint | |
4220 p->set_safepoint_visible(false); | |
6882
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
4221 // once the thread becomes safepoint invisible, we can not use its per-thread |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
4222 // recorder. And Threads::do_threads() no longer walks this thread, so we have |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
4223 // to release its per-thread recorder here. |
716c64bda5ba
7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents:
6872
diff
changeset
|
4224 MemTracker::thread_exiting(p); |
0 | 4225 } // unlock Threads_lock |
4226 | |
4227 // Since Events::log uses a lock, we grab it outside the Threads_lock | |
4872
aa3d708d67c4
7141200: log some interesting information in ring buffers for crashes
never
parents:
4800
diff
changeset
|
4228 Events::log(p, "Thread exited: " INTPTR_FORMAT, p); |
0 | 4229 } |
4230 | |
4231 // Threads_lock must be held when this is called (or must be called during a safepoint) | |
4232 bool Threads::includes(JavaThread* p) { | |
4233 assert(Threads_lock->is_locked(), "sanity check"); | |
4234 ALL_JAVA_THREADS(q) { | |
4235 if (q == p ) { | |
4236 return true; | |
4237 } | |
4238 } | |
4239 return false; | |
4240 } | |
4241 | |
4242 // Operations on the Threads list for GC. These are not explicitly locked, | |
4243 // but the garbage collector must provide a safe context for them to run. | |
4244 // In particular, these things should never be called when the Threads_lock | |
4245 // is held by some other thread. (Note: the Safepoint abstraction also | |
14909 | 4246 // uses the Threads_lock to gurantee this property. It also makes sure that |
0 | 4247 // all threads gets blocked when exiting or starting). |
4248 | |
14909 | 4249 void Threads::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
0 | 4250 ALL_JAVA_THREADS(p) { |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
4251 p->oops_do(f, cld_f, cf); |
0 | 4252 } |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
4253 VMThread::vm_thread()->oops_do(f, cld_f, cf); |
0 | 4254 } |
4255 | |
14909 | 4256 void Threads::possibly_parallel_oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) { |
0 | 4257 // Introduce a mechanism allowing parallel threads to claim threads as |
4258 // root groups. Overhead should be small enough to use all the time, | |
4259 // even in sequential code. | |
4260 SharedHeap* sh = SharedHeap::heap(); | |
4095
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4261 // Cannot yet substitute active_workers for n_par_threads |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4262 // because of G1CollectedHeap::verify() use of |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4263 // SharedHeap::process_strong_roots(). n_par_threads == 0 will |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4264 // turn off parallelism in process_strong_roots while active_workers |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4265 // is being used for parallelism elsewhere. |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4266 bool is_par = sh->n_par_threads() > 0; |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4267 assert(!is_par || |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4268 (SharedHeap::heap()->n_par_threads() == |
bca17e38de00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents:
4042
diff
changeset
|
4269 SharedHeap::heap()->workers()->active_workers()), "Mismatch"); |
0 | 4270 int cp = SharedHeap::heap()->strong_roots_parity(); |
4271 ALL_JAVA_THREADS(p) { | |
4272 if (p->claim_oops_do(is_par, cp)) { | |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
4273 p->oops_do(f, cld_f, cf); |
0 | 4274 } |
4275 } | |
4276 VMThread* vmt = VMThread::vm_thread(); | |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
4277 if (vmt->claim_oops_do(is_par, cp)) { |
7179
d0aa87f04bd5
8003720: NPG: Method in interpreter stack frame can be deallocated
stefank
parents:
7177
diff
changeset
|
4278 vmt->oops_do(f, cld_f, cf); |
3979
4dfb2df418f2
6484982: G1: process references during evacuation pauses
johnc
parents:
3938
diff
changeset
|
4279 } |
0 | 4280 } |
4281 | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
4282 #if INCLUDE_ALL_GCS |
0 | 4283 // Used by ParallelScavenge |
4284 void Threads::create_thread_roots_tasks(GCTaskQueue* q) { | |
4285 ALL_JAVA_THREADS(p) { | |
4286 q->enqueue(new ThreadRootsTask(p)); | |
4287 } | |
4288 q->enqueue(new ThreadRootsTask(VMThread::vm_thread())); | |
4289 } | |
4290 | |
4291 // Used by Parallel Old | |
4292 void Threads::create_thread_roots_marking_tasks(GCTaskQueue* q) { | |
4293 ALL_JAVA_THREADS(p) { | |
4294 q->enqueue(new ThreadRootsMarkingTask(p)); | |
4295 } | |
4296 q->enqueue(new ThreadRootsMarkingTask(VMThread::vm_thread())); | |
4297 } | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
4298 #endif // INCLUDE_ALL_GCS |
0 | 4299 |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4300 void Threads::nmethods_do(CodeBlobClosure* cf) { |
0 | 4301 ALL_JAVA_THREADS(p) { |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4302 p->nmethods_do(cf); |
0 | 4303 } |
989
148e5441d916
6863023: need non-perm oops in code cache for JSR 292
jrose
parents:
844
diff
changeset
|
4304 VMThread::vm_thread()->nmethods_do(cf); |
0 | 4305 } |
4306 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4307 void Threads::metadata_do(void f(Metadata*)) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4308 ALL_JAVA_THREADS(p) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4309 p->metadata_do(f); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4310 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4311 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6198
diff
changeset
|
4312 |
0 | 4313 void Threads::gc_epilogue() { |
4314 ALL_JAVA_THREADS(p) { | |
4315 p->gc_epilogue(); | |
4316 } | |
4317 } | |
4318 | |
4319 void Threads::gc_prologue() { | |
4320 ALL_JAVA_THREADS(p) { | |
4321 p->gc_prologue(); | |
4322 } | |
4323 } | |
4324 | |
4325 void Threads::deoptimized_wrt_marked_nmethods() { | |
4326 ALL_JAVA_THREADS(p) { | |
4327 p->deoptimized_wrt_marked_nmethods(); | |
4328 } | |
4329 } | |
4330 | |
4331 | |
4332 // Get count Java threads that are waiting to enter the specified monitor. | |
4333 GrowableArray<JavaThread*>* Threads::get_pending_threads(int count, | |
4334 address monitor, bool doLock) { | |
4335 assert(doLock || SafepointSynchronize::is_at_safepoint(), | |
4336 "must grab Threads_lock or be at safepoint"); | |
4337 GrowableArray<JavaThread*>* result = new GrowableArray<JavaThread*>(count); | |
4338 | |
4339 int i = 0; | |
4340 { | |
4341 MutexLockerEx ml(doLock ? Threads_lock : NULL); | |
4342 ALL_JAVA_THREADS(p) { | |
15463
a20be10ad437
made Graal work with the HotSpot compiler queue and compiler threads, enabled by -XX:-UseGraalCompilationQueue
Doug Simon <doug.simon@oracle.com>
parents:
15352
diff
changeset
|
4343 if (!p->can_call_java()) continue; |
0 | 4344 |
4345 address pending = (address)p->current_pending_monitor(); | |
4346 if (pending == monitor) { // found a match | |
4347 if (i < count) result->append(p); // save the first count matches | |
4348 i++; | |
4349 } | |
4350 } | |
4351 } | |
4352 return result; | |
4353 } | |
4354 | |
4355 | |
4356 JavaThread *Threads::owning_thread_from_monitor_owner(address owner, bool doLock) { | |
4357 assert(doLock || | |
4358 Threads_lock->owned_by_self() || | |
4359 SafepointSynchronize::is_at_safepoint(), | |
4360 "must grab Threads_lock or be at safepoint"); | |
4361 | |
4362 // NULL owner means not locked so we can skip the search | |
4363 if (owner == NULL) return NULL; | |
4364 | |
4365 { | |
4366 MutexLockerEx ml(doLock ? Threads_lock : NULL); | |
4367 ALL_JAVA_THREADS(p) { | |
4368 // first, see if owner is the address of a Java thread | |
4369 if (owner == (address)p) return p; | |
4370 } | |
4371 } | |
8673
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
8041
diff
changeset
|
4372 // Cannot assert on lack of success here since this function may be |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
8041
diff
changeset
|
4373 // used by code that is trying to report useful problem information |
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
8041
diff
changeset
|
4374 // like deadlock detection. |
0 | 4375 if (UseHeavyMonitors) return NULL; |
4376 | |
4377 // | |
4378 // If we didn't find a matching Java thread and we didn't force use of | |
4379 // heavyweight monitors, then the owner is the stack address of the | |
4380 // Lock Word in the owning Java thread's stack. | |
4381 // | |
4382 JavaThread* the_owner = NULL; | |
4383 { | |
4384 MutexLockerEx ml(doLock ? Threads_lock : NULL); | |
4385 ALL_JAVA_THREADS(q) { | |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
4386 if (q->is_lock_owned(owner)) { |
0 | 4387 the_owner = q; |
702
b9fba36710f2
6699669: Hotspot server leaves synchronized block with monitor in bad state
xlu
parents:
669
diff
changeset
|
4388 break; |
0 | 4389 } |
4390 } | |
4391 } | |
8673
5ee250974db9
8007476: assert(the_owner != NULL) failed: Did not find owning Java thread for lock word address
dcubed
parents:
8041
diff
changeset
|
4392 // cannot assert on lack of success here; see above comment |
0 | 4393 return the_owner; |
4394 } | |
4395 | |
4396 // Threads::print_on() is called at safepoint by VM_PrintThreads operation. | |
4397 void Threads::print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks) { | |
4398 char buf[32]; | |
4399 st->print_cr(os::local_time_string(buf, sizeof(buf))); | |
4400 | |
4401 st->print_cr("Full thread dump %s (%s %s):", | |
4402 Abstract_VM_Version::vm_name(), | |
4403 Abstract_VM_Version::vm_release(), | |
4404 Abstract_VM_Version::vm_info_string() | |
4405 ); | |
4406 st->cr(); | |
4407 | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
4408 #if INCLUDE_ALL_GCS |
0 | 4409 // Dump concurrent locks |
4410 ConcurrentLocksDump concurrent_locks; | |
4411 if (print_concurrent_locks) { | |
4412 concurrent_locks.dump_at_safepoint(); | |
4413 } | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
4414 #endif // INCLUDE_ALL_GCS |
0 | 4415 |
4416 ALL_JAVA_THREADS(p) { | |
4417 ResourceMark rm; | |
4418 p->print_on(st); | |
4419 if (print_stacks) { | |
4420 if (internal_format) { | |
4421 p->trace_stack(); | |
4422 } else { | |
4423 p->print_stack_on(st); | |
4424 } | |
4425 } | |
4426 st->cr(); | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
4427 #if INCLUDE_ALL_GCS |
0 | 4428 if (print_concurrent_locks) { |
4429 concurrent_locks.print_locks_on(p, st); | |
4430 } | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7615
diff
changeset
|
4431 #endif // INCLUDE_ALL_GCS |
0 | 4432 } |
4433 | |
4434 VMThread::vm_thread()->print_on(st); | |
4435 st->cr(); | |
4436 Universe::heap()->print_gc_threads_on(st); | |
4437 WatcherThread* wt = WatcherThread::watcher_thread(); | |
6766 | 4438 if (wt != NULL) { |
4439 wt->print_on(st); | |
4440 st->cr(); | |
4441 } | |
0 | 4442 CompileBroker::print_compiler_threads_on(st); |
4443 st->flush(); | |
4444 } | |
4445 | |
4446 // Threads::print_on_error() is called by fatal error handler. It's possible | |
4447 // that VM is not at safepoint and/or current thread is inside signal handler. | |
4448 // Don't print stack trace, as the stack may not be walkable. Don't allocate | |
4449 // memory (even in resource area), it might deadlock the error handler. | |
4450 void Threads::print_on_error(outputStream* st, Thread* current, char* buf, int buflen) { | |
4451 bool found_current = false; | |
4452 st->print_cr("Java Threads: ( => current thread )"); | |
4453 ALL_JAVA_THREADS(thread) { | |
4454 bool is_current = (current == thread); | |
4455 found_current = found_current || is_current; | |
4456 | |
4457 st->print("%s", is_current ? "=>" : " "); | |
4458 | |
4459 st->print(PTR_FORMAT, thread); | |
4460 st->print(" "); | |
4461 thread->print_on_error(st, buf, buflen); | |
4462 st->cr(); | |
4463 } | |
4464 st->cr(); | |
4465 | |
4466 st->print_cr("Other Threads:"); | |
4467 if (VMThread::vm_thread()) { | |
4468 bool is_current = (current == VMThread::vm_thread()); | |
4469 found_current = found_current || is_current; | |
4470 st->print("%s", current == VMThread::vm_thread() ? "=>" : " "); | |
4471 | |
4472 st->print(PTR_FORMAT, VMThread::vm_thread()); | |
4473 st->print(" "); | |
4474 VMThread::vm_thread()->print_on_error(st, buf, buflen); | |
4475 st->cr(); | |
4476 } | |
4477 WatcherThread* wt = WatcherThread::watcher_thread(); | |
4478 if (wt != NULL) { | |
4479 bool is_current = (current == wt); | |
4480 found_current = found_current || is_current; | |
4481 st->print("%s", is_current ? "=>" : " "); | |
4482 | |
4483 st->print(PTR_FORMAT, wt); | |
4484 st->print(" "); | |
4485 wt->print_on_error(st, buf, buflen); | |
4486 st->cr(); | |
4487 } | |
4488 if (!found_current) { | |
4489 st->cr(); | |
4490 st->print("=>" PTR_FORMAT " (exited) ", current); | |
4491 current->print_on_error(st, buf, buflen); | |
4492 st->cr(); | |
4493 } | |
4494 } | |
4495 | |
1878 | 4496 // Internal SpinLock and Mutex |
4497 // Based on ParkEvent | |
4498 | |
4499 // Ad-hoc mutual exclusion primitives: SpinLock and Mux | |
0 | 4500 // |
1878 | 4501 // We employ SpinLocks _only for low-contention, fixed-length |
4502 // short-duration critical sections where we're concerned | |
4503 // about native mutex_t or HotSpot Mutex:: latency. | |
4504 // The mux construct provides a spin-then-block mutual exclusion | |
4505 // mechanism. | |
4506 // | |
4507 // Testing has shown that contention on the ListLock guarding gFreeList | |
4508 // is common. If we implement ListLock as a simple SpinLock it's common | |
4509 // for the JVM to devolve to yielding with little progress. This is true | |
4510 // despite the fact that the critical sections protected by ListLock are | |
4511 // extremely short. | |
0 | 4512 // |
1878 | 4513 // TODO-FIXME: ListLock should be of type SpinLock. |
4514 // We should make this a 1st-class type, integrated into the lock | |
4515 // hierarchy as leaf-locks. Critically, the SpinLock structure | |
4516 // should have sufficient padding to avoid false-sharing and excessive | |
4517 // cache-coherency traffic. | |
4518 | |
4519 | |
4520 typedef volatile int SpinLockT ; | |
4521 | |
4522 void Thread::SpinAcquire (volatile int * adr, const char * LockName) { | |
4523 if (Atomic::cmpxchg (1, adr, 0) == 0) { | |
4524 return ; // normal fast-path return | |
4525 } | |
4526 | |
4527 // Slow-path : We've encountered contention -- Spin/Yield/Block strategy. | |
4528 TEVENT (SpinAcquire - ctx) ; | |
4529 int ctr = 0 ; | |
4530 int Yields = 0 ; | |
0 | 4531 for (;;) { |
1878 | 4532 while (*adr != 0) { |
4533 ++ctr ; | |
4534 if ((ctr & 0xFFF) == 0 || !os::is_MP()) { | |
4535 if (Yields > 5) { | |
14909 | 4536 // Consider using a simple NakedSleep() instead. |
4537 // Then SpinAcquire could be called by non-JVM threads | |
4538 Thread::current()->_ParkEvent->park(1) ; | |
1878 | 4539 } else { |
4540 os::NakedYield() ; | |
4541 ++Yields ; | |
4542 } | |
4543 } else { | |
4544 SpinPause() ; | |
0 | 4545 } |
1878 | 4546 } |
4547 if (Atomic::cmpxchg (1, adr, 0) == 0) return ; | |
0 | 4548 } |
4549 } | |
4550 | |
1878 | 4551 void Thread::SpinRelease (volatile int * adr) { |
4552 assert (*adr != 0, "invariant") ; | |
4553 OrderAccess::fence() ; // guarantee at least release consistency. | |
4554 // Roach-motel semantics. | |
4555 // It's safe if subsequent LDs and STs float "up" into the critical section, | |
4556 // but prior LDs and STs within the critical section can't be allowed | |
4557 // to reorder or float past the ST that releases the lock. | |
4558 *adr = 0 ; | |
0 | 4559 } |
4560 | |
1878 | 4561 // muxAcquire and muxRelease: |
4562 // | |
4563 // * muxAcquire and muxRelease support a single-word lock-word construct. | |
4564 // The LSB of the word is set IFF the lock is held. | |
4565 // The remainder of the word points to the head of a singly-linked list | |
4566 // of threads blocked on the lock. | |
4567 // | |
4568 // * The current implementation of muxAcquire-muxRelease uses its own | |
4569 // dedicated Thread._MuxEvent instance. If we're interested in | |
4570 // minimizing the peak number of extant ParkEvent instances then | |
4571 // we could eliminate _MuxEvent and "borrow" _ParkEvent as long | |
4572 // as certain invariants were satisfied. Specifically, care would need | |
4573 // to be taken with regards to consuming unpark() "permits". | |
4574 // A safe rule of thumb is that a thread would never call muxAcquire() | |
4575 // if it's enqueued (cxq, EntryList, WaitList, etc) and will subsequently | |
4576 // park(). Otherwise the _ParkEvent park() operation in muxAcquire() could | |
4577 // consume an unpark() permit intended for monitorenter, for instance. | |
4578 // One way around this would be to widen the restricted-range semaphore | |
4579 // implemented in park(). Another alternative would be to provide | |
4580 // multiple instances of the PlatformEvent() for each thread. One | |
4581 // instance would be dedicated to muxAcquire-muxRelease, for instance. | |
4582 // | |
4583 // * Usage: | |
4584 // -- Only as leaf locks | |
4585 // -- for short-term locking only as muxAcquire does not perform | |
4586 // thread state transitions. | |
4587 // | |
4588 // Alternatives: | |
4589 // * We could implement muxAcquire and muxRelease with MCS or CLH locks | |
4590 // but with parking or spin-then-park instead of pure spinning. | |
4591 // * Use Taura-Oyama-Yonenzawa locks. | |
4592 // * It's possible to construct a 1-0 lock if we encode the lockword as | |
4593 // (List,LockByte). Acquire will CAS the full lockword while Release | |
4594 // will STB 0 into the LockByte. The 1-0 scheme admits stranding, so | |
4595 // acquiring threads use timers (ParkTimed) to detect and recover from | |
4596 // the stranding window. Thread/Node structures must be aligned on 256-byte | |
4597 // boundaries by using placement-new. | |
4598 // * Augment MCS with advisory back-link fields maintained with CAS(). | |
4599 // Pictorially: LockWord -> T1 <-> T2 <-> T3 <-> ... <-> Tn <-> Owner. | |
4600 // The validity of the backlinks must be ratified before we trust the value. | |
4601 // If the backlinks are invalid the exiting thread must back-track through the | |
4602 // the forward links, which are always trustworthy. | |
4603 // * Add a successor indication. The LockWord is currently encoded as | |
4604 // (List, LOCKBIT:1). We could also add a SUCCBIT or an explicit _succ variable | |
4605 // to provide the usual futile-wakeup optimization. | |
4606 // See RTStt for details. | |
4607 // * Consider schedctl.sc_nopreempt to cover the critical section. | |
4608 // | |
4609 | |
4610 | |
4611 typedef volatile intptr_t MutexT ; // Mux Lock-word | |
4612 enum MuxBits { LOCKBIT = 1 } ; | |
4613 | |
4614 void Thread::muxAcquire (volatile intptr_t * Lock, const char * LockName) { | |
4615 intptr_t w = Atomic::cmpxchg_ptr (LOCKBIT, Lock, 0) ; | |
4616 if (w == 0) return ; | |
4617 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4618 return ; | |
4619 } | |
4620 | |
4621 TEVENT (muxAcquire - Contention) ; | |
4622 ParkEvent * const Self = Thread::current()->_MuxEvent ; | |
4623 assert ((intptr_t(Self) & LOCKBIT) == 0, "invariant") ; | |
0 | 4624 for (;;) { |
1878 | 4625 int its = (os::is_MP() ? 100 : 0) + 1 ; |
4626 | |
4627 // Optional spin phase: spin-then-park strategy | |
4628 while (--its >= 0) { | |
4629 w = *Lock ; | |
4630 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4631 return ; | |
4632 } | |
4633 } | |
4634 | |
4635 Self->reset() ; | |
4636 Self->OnList = intptr_t(Lock) ; | |
4637 // The following fence() isn't _strictly necessary as the subsequent | |
4638 // CAS() both serializes execution and ratifies the fetched *Lock value. | |
4639 OrderAccess::fence(); | |
4640 for (;;) { | |
4641 w = *Lock ; | |
4642 if ((w & LOCKBIT) == 0) { | |
4643 if (Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4644 Self->OnList = 0 ; // hygiene - allows stronger asserts | |
4645 return ; | |
4646 } | |
4647 continue ; // Interference -- *Lock changed -- Just retry | |
0 | 4648 } |
1878 | 4649 assert (w & LOCKBIT, "invariant") ; |
4650 Self->ListNext = (ParkEvent *) (w & ~LOCKBIT ); | |
4651 if (Atomic::cmpxchg_ptr (intptr_t(Self)|LOCKBIT, Lock, w) == w) break ; | |
4652 } | |
4653 | |
4654 while (Self->OnList != 0) { | |
4655 Self->park() ; | |
4656 } | |
0 | 4657 } |
4658 } | |
4659 | |
1878 | 4660 void Thread::muxAcquireW (volatile intptr_t * Lock, ParkEvent * ev) { |
4661 intptr_t w = Atomic::cmpxchg_ptr (LOCKBIT, Lock, 0) ; | |
4662 if (w == 0) return ; | |
4663 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4664 return ; | |
4665 } | |
4666 | |
4667 TEVENT (muxAcquire - Contention) ; | |
4668 ParkEvent * ReleaseAfter = NULL ; | |
4669 if (ev == NULL) { | |
4670 ev = ReleaseAfter = ParkEvent::Allocate (NULL) ; | |
4671 } | |
4672 assert ((intptr_t(ev) & LOCKBIT) == 0, "invariant") ; | |
4673 for (;;) { | |
4674 guarantee (ev->OnList == 0, "invariant") ; | |
4675 int its = (os::is_MP() ? 100 : 0) + 1 ; | |
4676 | |
4677 // Optional spin phase: spin-then-park strategy | |
4678 while (--its >= 0) { | |
4679 w = *Lock ; | |
4680 if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4681 if (ReleaseAfter != NULL) { | |
4682 ParkEvent::Release (ReleaseAfter) ; | |
4683 } | |
4684 return ; | |
4685 } | |
4686 } | |
4687 | |
4688 ev->reset() ; | |
4689 ev->OnList = intptr_t(Lock) ; | |
4690 // The following fence() isn't _strictly necessary as the subsequent | |
4691 // CAS() both serializes execution and ratifies the fetched *Lock value. | |
4692 OrderAccess::fence(); | |
4693 for (;;) { | |
4694 w = *Lock ; | |
4695 if ((w & LOCKBIT) == 0) { | |
4696 if (Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { | |
4697 ev->OnList = 0 ; | |
4698 // We call ::Release while holding the outer lock, thus | |
4699 // artificially lengthening the critical section. | |
4700 // Consider deferring the ::Release() until the subsequent unlock(), | |
4701 // after we've dropped the outer lock. | |
4702 if (ReleaseAfter != NULL) { | |
4703 ParkEvent::Release (ReleaseAfter) ; | |
4704 } | |
4705 return ; | |
4706 } | |
4707 continue ; // Interference -- *Lock changed -- Just retry | |
4708 } | |
4709 assert (w & LOCKBIT, "invariant") ; | |
4710 ev->ListNext = (ParkEvent *) (w & ~LOCKBIT ); | |
4711 if (Atomic::cmpxchg_ptr (intptr_t(ev)|LOCKBIT, Lock, w) == w) break ; | |
4712 } | |
4713 | |
4714 while (ev->OnList != 0) { | |
4715 ev->park() ; | |
4716 } | |
4717 } | |
4718 } | |
4719 | |
4720 // Release() must extract a successor from the list and then wake that thread. | |
4721 // It can "pop" the front of the list or use a detach-modify-reattach (DMR) scheme | |
4722 // similar to that used by ParkEvent::Allocate() and ::Release(). DMR-based | |
4723 // Release() would : | |
4724 // (A) CAS() or swap() null to *Lock, releasing the lock and detaching the list. | |
4725 // (B) Extract a successor from the private list "in-hand" | |
4726 // (C) attempt to CAS() the residual back into *Lock over null. | |
4727 // If there were any newly arrived threads and the CAS() would fail. | |
4728 // In that case Release() would detach the RATs, re-merge the list in-hand | |
4729 // with the RATs and repeat as needed. Alternately, Release() might | |
4730 // detach and extract a successor, but then pass the residual list to the wakee. | |
4731 // The wakee would be responsible for reattaching and remerging before it | |
4732 // competed for the lock. | |
4733 // | |
4734 // Both "pop" and DMR are immune from ABA corruption -- there can be | |
4735 // multiple concurrent pushers, but only one popper or detacher. | |
4736 // This implementation pops from the head of the list. This is unfair, | |
4737 // but tends to provide excellent throughput as hot threads remain hot. | |
4738 // (We wake recently run threads first). | |
4739 | |
4740 void Thread::muxRelease (volatile intptr_t * Lock) { | |
4741 for (;;) { | |
4742 const intptr_t w = Atomic::cmpxchg_ptr (0, Lock, LOCKBIT) ; | |
4743 assert (w & LOCKBIT, "invariant") ; | |
4744 if (w == LOCKBIT) return ; | |
4745 ParkEvent * List = (ParkEvent *) (w & ~LOCKBIT) ; | |
4746 assert (List != NULL, "invariant") ; | |
4747 assert (List->OnList == intptr_t(Lock), "invariant") ; | |
4748 ParkEvent * nxt = List->ListNext ; | |
4749 | |
4750 // The following CAS() releases the lock and pops the head element. | |
4751 if (Atomic::cmpxchg_ptr (intptr_t(nxt), Lock, w) != w) { | |
4752 continue ; | |
4753 } | |
4754 List->OnList = 0 ; | |
4755 OrderAccess::fence() ; | |
4756 List->unpark () ; | |
4757 return ; | |
4758 } | |
4759 } | |
4760 | |
4761 | |
0 | 4762 void Threads::verify() { |
4763 ALL_JAVA_THREADS(p) { | |
4764 p->verify(); | |
4765 } | |
4766 VMThread* thread = VMThread::vm_thread(); | |
4767 if (thread != NULL) thread->verify(); | |
4768 } |