comparison src/share/vm/runtime/thread.hpp @ 2100:b1a2afa37ec4

7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis Summary: Track allocated bytes in Thread's, update on TLAB retirement and direct allocation in Eden and tenured, add JNI methods for ThreadMXBean. Reviewed-by: coleenp, kvn, dholmes, ysr
author phh
date Fri, 07 Jan 2011 10:42:32 -0500
parents fd1d227ef1b9
children 91fe28b03d6a db2b0f8c1cef
comparison
equal deleted inserted replaced
2097:039eb4201e06 2100:b1a2afa37ec4
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
58 58
59 class JvmtiThreadState; 59 class JvmtiThreadState;
60 class JvmtiGetLoadedClassesClosure; 60 class JvmtiGetLoadedClassesClosure;
61 class ThreadStatistics; 61 class ThreadStatistics;
62 class ConcurrentLocksDump; 62 class ConcurrentLocksDump;
63 class ParkEvent ; 63 class ParkEvent;
64 class Parker; 64 class Parker;
65 65
66 class ciEnv; 66 class ciEnv;
67 class CompileThread; 67 class CompileThread;
68 class CompileLog; 68 class CompileLog;
168 // part of java_suspend(), but that probably would affect the suspend/query 168 // part of java_suspend(), but that probably would affect the suspend/query
169 // performance. Need more investigation on this. 169 // performance. Need more investigation on this.
170 // 170 //
171 171
172 // suspend/resume lock: used for self-suspend 172 // suspend/resume lock: used for self-suspend
173 Monitor* _SR_lock; 173 Monitor* _SR_lock;
174 174
175 protected: 175 protected:
176 enum SuspendFlags { 176 enum SuspendFlags {
177 // NOTE: avoid using the sign-bit as cc generates different test code 177 // NOTE: avoid using the sign-bit as cc generates different test code
178 // when the sign-bit is used, and sometimes incorrectly - see CR 6398077 178 // when the sign-bit is used, and sometimes incorrectly - see CR 6398077
192 int _num_nested_signal; 192 int _num_nested_signal;
193 193
194 public: 194 public:
195 void enter_signal_handler() { _num_nested_signal++; } 195 void enter_signal_handler() { _num_nested_signal++; }
196 void leave_signal_handler() { _num_nested_signal--; } 196 void leave_signal_handler() { _num_nested_signal--; }
197 bool is_inside_signal_handler() const { return _num_nested_signal > 0; } 197 bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
198 198
199 private: 199 private:
200 // Debug tracing 200 // Debug tracing
201 static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN; 201 static void trace(const char* msg, const Thread* const thread) PRODUCT_RETURN;
202 202
213 // claimed as a task. 213 // claimed as a task.
214 jint _oops_do_parity; 214 jint _oops_do_parity;
215 215
216 public: 216 public:
217 void set_last_handle_mark(HandleMark* mark) { _last_handle_mark = mark; } 217 void set_last_handle_mark(HandleMark* mark) { _last_handle_mark = mark; }
218 HandleMark* last_handle_mark() const { return _last_handle_mark; } 218 HandleMark* last_handle_mark() const { return _last_handle_mark; }
219 private: 219 private:
220 220
221 // debug support for checking if code does allow safepoints or not 221 // debug support for checking if code does allow safepoints or not
222 // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on 222 // GC points in the VM can happen because of allocation, invoking a VM operation, or blocking on
223 // mutex, or blocking on an object synchronizer (Java locking). 223 // mutex, or blocking on an object synchronizer (Java locking).
225 // If !allow_allocation(), then an assertion failure will happen during allocation 225 // If !allow_allocation(), then an assertion failure will happen during allocation
226 // (Hence, !allow_safepoint() => !allow_allocation()). 226 // (Hence, !allow_safepoint() => !allow_allocation()).
227 // 227 //
228 // The two classes No_Safepoint_Verifier and No_Allocation_Verifier are used to set these counters. 228 // The two classes No_Safepoint_Verifier and No_Allocation_Verifier are used to set these counters.
229 // 229 //
230 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen 230 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
231 debug_only (int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops. 231 debug_only (int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
232 232
233 // Used by SkipGCALot class. 233 // Used by SkipGCALot class.
234 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot? 234 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
235 235
236 // Record when GC is locked out via the GC_locker mechanism 236 // Record when GC is locked out via the GC_locker mechanism
237 CHECK_UNHANDLED_OOPS_ONLY(int _gc_locked_out_count;) 237 CHECK_UNHANDLED_OOPS_ONLY(int _gc_locked_out_count;)
238 238
239 friend class No_Alloc_Verifier; 239 friend class No_Alloc_Verifier;
240 friend class No_Safepoint_Verifier; 240 friend class No_Safepoint_Verifier;
241 friend class Pause_No_Safepoint_Verifier; 241 friend class Pause_No_Safepoint_Verifier;
242 friend class ThreadLocalStorage; 242 friend class ThreadLocalStorage;
243 friend class GC_locker; 243 friend class GC_locker;
244 244
245 ThreadLocalAllocBuffer _tlab; // Thread-local eden 245 ThreadLocalAllocBuffer _tlab; // Thread-local eden
246 246 jlong _allocated_bytes; // Cumulative number of bytes allocated on
247 int _vm_operation_started_count; // VM_Operation support 247 // the Java heap
248 int _vm_operation_completed_count; // VM_Operation support 248
249 249 int _vm_operation_started_count; // VM_Operation support
250 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread 250 int _vm_operation_completed_count; // VM_Operation support
251 // is waiting to lock 251
252 bool _current_pending_monitor_is_from_java; // locking is from Java code 252 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
253 // is waiting to lock
254 bool _current_pending_monitor_is_from_java; // locking is from Java code
253 255
254 // ObjectMonitor on which this thread called Object.wait() 256 // ObjectMonitor on which this thread called Object.wait()
255 ObjectMonitor* _current_waiting_monitor; 257 ObjectMonitor* _current_waiting_monitor;
256 258
257 // Private thread-local objectmonitor list - a simple cache organized as a SLL. 259 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
258 public: 260 public:
259 ObjectMonitor * omFreeList ; 261 ObjectMonitor* omFreeList;
260 int omFreeCount ; // length of omFreeList 262 int omFreeCount; // length of omFreeList
261 int omFreeProvision ; // reload chunk size 263 int omFreeProvision; // reload chunk size
262 ObjectMonitor * omInUseList; // SLL to track monitors in circulation 264 ObjectMonitor* omInUseList; // SLL to track monitors in circulation
263 int omInUseCount; // length of omInUseList 265 int omInUseCount; // length of omInUseList
264 266
265 public: 267 public:
266 enum { 268 enum {
267 is_definitely_current_thread = true 269 is_definitely_current_thread = true
278 virtual void run(); 280 virtual void run();
279 281
280 // Testers 282 // Testers
281 virtual bool is_VM_thread() const { return false; } 283 virtual bool is_VM_thread() const { return false; }
282 virtual bool is_Java_thread() const { return false; } 284 virtual bool is_Java_thread() const { return false; }
283 // Remove this ifdef when C1 is ported to the compiler interface.
284 virtual bool is_Compiler_thread() const { return false; } 285 virtual bool is_Compiler_thread() const { return false; }
285 virtual bool is_hidden_from_external_view() const { return false; } 286 virtual bool is_hidden_from_external_view() const { return false; }
286 virtual bool is_jvmti_agent_thread() const { return false; } 287 virtual bool is_jvmti_agent_thread() const { return false; }
287 // True iff the thread can perform GC operations at a safepoint. 288 // True iff the thread can perform GC operations at a safepoint.
288 // Generally will be true only of VM thread and parallel GC WorkGang 289 // Generally will be true only of VM thread and parallel GC WorkGang
342 } 343 }
343 344
344 // Support for Unhandled Oop detection 345 // Support for Unhandled Oop detection
345 #ifdef CHECK_UNHANDLED_OOPS 346 #ifdef CHECK_UNHANDLED_OOPS
346 private: 347 private:
347 UnhandledOops *_unhandled_oops; 348 UnhandledOops* _unhandled_oops;
348 public: 349 public:
349 UnhandledOops* unhandled_oops() { return _unhandled_oops; } 350 UnhandledOops* unhandled_oops() { return _unhandled_oops; }
350 // Mark oop safe for gc. It may be stack allocated but won't move. 351 // Mark oop safe for gc. It may be stack allocated but won't move.
351 void allow_unhandled_oop(oop *op) { 352 void allow_unhandled_oop(oop *op) {
352 if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op); 353 if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op);
353 } 354 }
354 // Clear oops at safepoint so crashes point to unhandled oop violator 355 // Clear oops at safepoint so crashes point to unhandled oop violator
355 void clear_unhandled_oops() { 356 void clear_unhandled_oops() {
356 if (CheckUnhandledOops) unhandled_oops()->clear_unhandled_oops(); 357 if (CheckUnhandledOops) unhandled_oops()->clear_unhandled_oops();
357 } 358 }
358 bool is_gc_locked_out() { return _gc_locked_out_count > 0; } 359 bool is_gc_locked_out() { return _gc_locked_out_count > 0; }
359 #endif // CHECK_UNHANDLED_OOPS 360 #endif // CHECK_UNHANDLED_OOPS
360 361
388 ThreadLocalAllocBuffer& tlab() { return _tlab; } 389 ThreadLocalAllocBuffer& tlab() { return _tlab; }
389 void initialize_tlab() { 390 void initialize_tlab() {
390 if (UseTLAB) { 391 if (UseTLAB) {
391 tlab().initialize(); 392 tlab().initialize();
392 } 393 }
394 }
395
396 jlong allocated_bytes() { return _allocated_bytes; }
397 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
398 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
399 jlong cooked_allocated_bytes() {
400 jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes);
401 if (UseTLAB) {
402 size_t used_bytes = tlab().used_bytes();
403 if ((ssize_t)used_bytes > 0) {
404 // More-or-less valid tlab. The load_acquire above should ensure
405 // that the result of the add is <= the instantaneous value
406 return allocated_bytes + used_bytes;
407 }
408 }
409 return allocated_bytes;
393 } 410 }
394 411
395 // VM operation support 412 // VM operation support
396 int vm_operation_ticket() { return ++_vm_operation_started_count; } 413 int vm_operation_ticket() { return ++_vm_operation_started_count; }
397 int vm_operation_completed_count() { return _vm_operation_completed_count; } 414 int vm_operation_completed_count() { return _vm_operation_completed_count; }
487 bool on_local_stack(address adr) const { 504 bool on_local_stack(address adr) const {
488 /* QQQ this has knowledge of direction, ought to be a stack method */ 505 /* QQQ this has knowledge of direction, ought to be a stack method */
489 return (_stack_base >= adr && adr >= (_stack_base - _stack_size)); 506 return (_stack_base >= adr && adr >= (_stack_base - _stack_size));
490 } 507 }
491 508
492 int lgrp_id() const { return _lgrp_id; } 509 uintptr_t self_raw_id() { return _self_raw_id; }
493 void set_lgrp_id(int value) { _lgrp_id = value; } 510 void set_self_raw_id(uintptr_t value) { _self_raw_id = value; }
511
512 int lgrp_id() const { return _lgrp_id; }
513 void set_lgrp_id(int value) { _lgrp_id = value; }
494 514
495 // Printing 515 // Printing
496 void print_on(outputStream* st) const; 516 void print_on(outputStream* st) const;
497 void print() const { print_on(tty); } 517 void print() const { print_on(tty); }
498 virtual void print_on_error(outputStream* st, char* buf, int buflen) const; 518 virtual void print_on_error(outputStream* st, char* buf, int buflen) const;
500 // Debug-only code 520 // Debug-only code
501 521
502 #ifdef ASSERT 522 #ifdef ASSERT
503 private: 523 private:
504 // Deadlock detection support for Mutex locks. List of locks own by thread. 524 // Deadlock detection support for Mutex locks. List of locks own by thread.
505 Monitor *_owned_locks; 525 Monitor* _owned_locks;
506 // Mutex::set_owner_implementation is the only place where _owned_locks is modified, 526 // Mutex::set_owner_implementation is the only place where _owned_locks is modified,
507 // thus the friendship 527 // thus the friendship
508 friend class Mutex; 528 friend class Mutex;
509 friend class Monitor; 529 friend class Monitor;
510 530
511 public: 531 public:
512 void print_owned_locks_on(outputStream* st) const; 532 void print_owned_locks_on(outputStream* st) const;
513 void print_owned_locks() const { print_owned_locks_on(tty); } 533 void print_owned_locks() const { print_owned_locks_on(tty); }
514 Monitor * owned_locks() const { return _owned_locks; } 534 Monitor* owned_locks() const { return _owned_locks; }
515 bool owns_locks() const { return owned_locks() != NULL; } 535 bool owns_locks() const { return owned_locks() != NULL; }
516 bool owns_locks_but_compiled_lock() const; 536 bool owns_locks_but_compiled_lock() const;
517 537
518 // Deadlock detection 538 // Deadlock detection
519 bool allow_allocation() { return _allow_allocation_count == 0; } 539 bool allow_allocation() { return _allow_allocation_count == 0; }
536 556
537 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base ); } 557 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base ); }
538 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size ); } 558 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size ); }
539 559
540 #define TLAB_FIELD_OFFSET(name) \ 560 #define TLAB_FIELD_OFFSET(name) \
541 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); } 561 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
542 562
543 TLAB_FIELD_OFFSET(start) 563 TLAB_FIELD_OFFSET(start)
544 TLAB_FIELD_OFFSET(end) 564 TLAB_FIELD_OFFSET(end)
545 TLAB_FIELD_OFFSET(top) 565 TLAB_FIELD_OFFSET(top)
546 TLAB_FIELD_OFFSET(pf_top) 566 TLAB_FIELD_OFFSET(pf_top)
549 TLAB_FIELD_OFFSET(number_of_refills) 569 TLAB_FIELD_OFFSET(number_of_refills)
550 TLAB_FIELD_OFFSET(fast_refill_waste) 570 TLAB_FIELD_OFFSET(fast_refill_waste)
551 TLAB_FIELD_OFFSET(slow_allocations) 571 TLAB_FIELD_OFFSET(slow_allocations)
552 572
553 #undef TLAB_FIELD_OFFSET 573 #undef TLAB_FIELD_OFFSET
574
575 static ByteSize allocated_bytes_offset() { return byte_offset_of(Thread, _allocated_bytes ); }
554 576
555 public: 577 public:
556 volatile intptr_t _Stalled ; 578 volatile intptr_t _Stalled ;
557 volatile int _TypeTag ; 579 volatile int _TypeTag ;
558 ParkEvent * _ParkEvent ; // for synchronized() 580 ParkEvent * _ParkEvent ; // for synchronized()