comparison src/share/vm/runtime/objectMonitor.hpp @ 10405:f2110083203d

8005849: JEP 167: Event-Based JVM Tracing Reviewed-by: acorn, coleenp, sla Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>
author sla
date Mon, 10 Jun 2013 11:30:51 +0200
parents f9be75d21404
children 9758d9f36299
comparison
equal deleted inserted replaced
10404:d0add7016434 10405:f2110083203d
1 /* 1 /*
2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1998, 2013, 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.
27 27
28 #include "runtime/os.hpp" 28 #include "runtime/os.hpp"
29 #include "runtime/park.hpp" 29 #include "runtime/park.hpp"
30 #include "runtime/perfData.hpp" 30 #include "runtime/perfData.hpp"
31 31
32
33 // ObjectWaiter serves as a "proxy" or surrogate thread. 32 // ObjectWaiter serves as a "proxy" or surrogate thread.
34 // TODO-FIXME: Eliminate ObjectWaiter and use the thread-specific 33 // TODO-FIXME: Eliminate ObjectWaiter and use the thread-specific
35 // ParkEvent instead. Beware, however, that the JVMTI code 34 // ParkEvent instead. Beware, however, that the JVMTI code
36 // knows about ObjectWaiters, so we'll have to reconcile that code. 35 // knows about ObjectWaiters, so we'll have to reconcile that code.
37 // See next_waiter(), first_waiter(), etc. 36 // See next_waiter(), first_waiter(), etc.
41 enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ } ; 40 enum TStates { TS_UNDEF, TS_READY, TS_RUN, TS_WAIT, TS_ENTER, TS_CXQ } ;
42 enum Sorted { PREPEND, APPEND, SORTED } ; 41 enum Sorted { PREPEND, APPEND, SORTED } ;
43 ObjectWaiter * volatile _next; 42 ObjectWaiter * volatile _next;
44 ObjectWaiter * volatile _prev; 43 ObjectWaiter * volatile _prev;
45 Thread* _thread; 44 Thread* _thread;
45 jlong _notifier_tid;
46 ParkEvent * _event; 46 ParkEvent * _event;
47 volatile int _notified ; 47 volatile int _notified ;
48 volatile TStates TState ; 48 volatile TStates TState ;
49 Sorted _Sorted ; // List placement disposition 49 Sorted _Sorted ; // List placement disposition
50 bool _active ; // Contention monitoring is enabled 50 bool _active ; // Contention monitoring is enabled
52 ObjectWaiter(Thread* thread); 52 ObjectWaiter(Thread* thread);
53 53
54 void wait_reenter_begin(ObjectMonitor *mon); 54 void wait_reenter_begin(ObjectMonitor *mon);
55 void wait_reenter_end(ObjectMonitor *mon); 55 void wait_reenter_end(ObjectMonitor *mon);
56 }; 56 };
57
58 // forward declaration to avoid include tracing.hpp
59 class EventJavaMonitorWait;
57 60
58 // WARNING: 61 // WARNING:
59 // This is a very sensitive and fragile class. DO NOT make any 62 // This is a very sensitive and fragile class. DO NOT make any
60 // change unless you are fully aware of the underlying semantics. 63 // change unless you are fully aware of the underlying semantics.
61 64
149 FreeNext = NULL ; 152 FreeNext = NULL ;
150 _EntryList = NULL ; 153 _EntryList = NULL ;
151 _SpinFreq = 0 ; 154 _SpinFreq = 0 ;
152 _SpinClock = 0 ; 155 _SpinClock = 0 ;
153 OwnerIsThread = 0 ; 156 OwnerIsThread = 0 ;
157 _previous_owner_tid = 0;
154 } 158 }
155 159
156 ~ObjectMonitor() { 160 ~ObjectMonitor() {
157 // TODO: Add asserts ... 161 // TODO: Add asserts ...
158 // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0 162 // _cxq == 0 _succ == NULL _owner == NULL _waiters == 0
190 void print(); 194 void print();
191 #endif 195 #endif
192 196
193 bool try_enter (TRAPS) ; 197 bool try_enter (TRAPS) ;
194 void enter(TRAPS); 198 void enter(TRAPS);
195 void exit(TRAPS); 199 void exit(bool not_suspended, TRAPS);
196 void wait(jlong millis, bool interruptable, TRAPS); 200 void wait(jlong millis, bool interruptable, TRAPS);
197 void notify(TRAPS); 201 void notify(TRAPS);
198 void notifyAll(TRAPS); 202 void notifyAll(TRAPS);
199 203
200 // Use the following at your own risk 204 // Use the following at your own risk
216 int TrySpin_VaryFrequency (Thread * Self) ; 220 int TrySpin_VaryFrequency (Thread * Self) ;
217 int TrySpin_VaryDuration (Thread * Self) ; 221 int TrySpin_VaryDuration (Thread * Self) ;
218 void ctAsserts () ; 222 void ctAsserts () ;
219 void ExitEpilog (Thread * Self, ObjectWaiter * Wakee) ; 223 void ExitEpilog (Thread * Self, ObjectWaiter * Wakee) ;
220 bool ExitSuspendEquivalent (JavaThread * Self) ; 224 bool ExitSuspendEquivalent (JavaThread * Self) ;
225 void post_monitor_wait_event(EventJavaMonitorWait * event,
226 jlong notifier_tid,
227 jlong timeout,
228 bool timedout);
221 229
222 private: 230 private:
223 friend class ObjectSynchronizer; 231 friend class ObjectSynchronizer;
224 friend class ObjectWaiter; 232 friend class ObjectWaiter;
225 friend class VMStructs; 233 friend class VMStructs;
238 // The VM assumes write ordering wrt these fields, which can be 246 // The VM assumes write ordering wrt these fields, which can be
239 // read from other threads. 247 // read from other threads.
240 248
241 protected: // protected for jvmtiRawMonitor 249 protected: // protected for jvmtiRawMonitor
242 void * volatile _owner; // pointer to owning thread OR BasicLock 250 void * volatile _owner; // pointer to owning thread OR BasicLock
251 volatile jlong _previous_owner_tid; // thread id of the previous owner of the monitor
243 volatile intptr_t _recursions; // recursion count, 0 for first entry 252 volatile intptr_t _recursions; // recursion count, 0 for first entry
244 private: 253 private:
245 int OwnerIsThread ; // _owner is (Thread *) vs SP/BasicLock 254 int OwnerIsThread ; // _owner is (Thread *) vs SP/BasicLock
246 ObjectWaiter * volatile _cxq ; // LL of recently-arrived threads blocked on entry. 255 ObjectWaiter * volatile _cxq ; // LL of recently-arrived threads blocked on entry.
247 // The list is actually composed of WaitNodes, acting 256 // The list is actually composed of WaitNodes, acting