0
|
1 /*
|
|
2 * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
|
|
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 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.runtime;
|
|
26
|
|
27 import java.util.*;
|
|
28
|
|
29 import sun.jvm.hotspot.debugger.*;
|
|
30 import sun.jvm.hotspot.oops.*;
|
|
31 import sun.jvm.hotspot.types.*;
|
|
32
|
|
33 public class ObjectMonitor extends VMObject {
|
|
34 static {
|
|
35 VM.registerVMInitializedObserver(new Observer() {
|
|
36 public void update(Observable o, Object data) {
|
|
37 initialize(VM.getVM().getTypeDataBase());
|
|
38 }
|
|
39 });
|
|
40 }
|
|
41
|
|
42 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
|
|
43 heap = VM.getVM().getObjectHeap();
|
|
44 Type type = db.lookupType("ObjectMonitor");
|
|
45 sun.jvm.hotspot.types.Field f = type.getField("_header");
|
|
46 headerFieldOffset = f.getOffset();
|
|
47 f = type.getField("_object");
|
|
48 objectFieldOffset = f.getOffset();
|
|
49 f = type.getField("_owner");
|
|
50 ownerFieldOffset = f.getOffset();
|
|
51 f = type.getField("FreeNext");
|
|
52 FreeNextFieldOffset = f.getOffset();
|
|
53 countField = type.getCIntegerField("_count");
|
|
54 waitersField = type.getCIntegerField("_waiters");
|
|
55 recursionsField = type.getCIntegerField("_recursions");
|
|
56 }
|
|
57
|
|
58 public ObjectMonitor(Address addr) {
|
|
59 super(addr);
|
|
60 }
|
|
61
|
|
62 public Mark header() {
|
|
63 return new Mark(addr.addOffsetTo(headerFieldOffset));
|
|
64 }
|
|
65
|
|
66 // FIXME
|
|
67 // void set_header(markOop hdr);
|
|
68
|
|
69 // FIXME: must implement and delegate to platform-dependent implementation
|
|
70 // public boolean isBusy();
|
|
71 public boolean isEntered(sun.jvm.hotspot.runtime.Thread current) {
|
|
72 Address o = owner();
|
|
73 if (current.threadObjectAddress().equals(o) ||
|
|
74 current.isLockOwned(o)) {
|
|
75 return true;
|
|
76 }
|
|
77 return false;
|
|
78 }
|
|
79
|
|
80 public Address owner() { return addr.getAddressAt(ownerFieldOffset); }
|
|
81 // FIXME
|
|
82 // void set_owner(void* owner);
|
|
83
|
|
84 public long waiters() { return waitersField.getValue(addr); }
|
|
85
|
|
86 public Address freeNext() { return addr.getAddressAt(FreeNextFieldOffset); }
|
|
87 // FIXME
|
|
88 // void set_queue(void* owner);
|
|
89
|
|
90 public long count() { return countField.getValue(addr); }
|
|
91 // FIXME
|
|
92 // void set_count(intptr_t count);
|
|
93
|
|
94 public long recursions() { return recursionsField.getValue(addr); }
|
|
95
|
|
96 public OopHandle object() {
|
|
97 return addr.getOopHandleAt(objectFieldOffset);
|
|
98 }
|
|
99
|
|
100 public long contentions() {
|
|
101 // refer to objectMonitor_xxx.inline.hpp - contentions definition.
|
|
102 // for Solaris and Linux, contentions is same as count. for Windows
|
|
103 // it is different (objectMonitor_win32.inline.hpp)
|
|
104 long count = count();
|
|
105 if (VM.getVM().getOS().equals("win32")) {
|
|
106 // don't count the owner of the monitor
|
|
107 return count > 0? count - 1 : 0;
|
|
108 } else {
|
|
109 // Solaris and Linux
|
|
110 return count;
|
|
111 }
|
|
112 }
|
|
113
|
|
114 // FIXME
|
|
115 // void* object_addr();
|
|
116 // void set_object(void* obj);
|
|
117
|
|
118 // The following four either aren't expressed as typed fields in
|
|
119 // vmStructs.cpp because they aren't strongly typed in the VM, or
|
|
120 // would confuse the SA's type system.
|
|
121 private static ObjectHeap heap;
|
|
122 private static long headerFieldOffset;
|
|
123 private static long objectFieldOffset;
|
|
124 private static long ownerFieldOffset;
|
|
125 private static long FreeNextFieldOffset;
|
|
126 private static CIntegerField countField;
|
|
127 private static CIntegerField waitersField;
|
|
128 private static CIntegerField recursionsField;
|
|
129 // FIXME: expose platform-dependent stuff
|
|
130 }
|