0
|
1 /*
|
|
2 * Copyright 2001-2007 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.oops.*;
|
|
30 import sun.jvm.hotspot.utilities.*;
|
|
31 import sun.jvm.hotspot.debugger.*;
|
|
32 import sun.jvm.hotspot.types.*;
|
|
33
|
|
34 public class ObjectSynchronizer {
|
|
35 static {
|
|
36 VM.registerVMInitializedObserver(new Observer() {
|
|
37 public void update(Observable o, Object data) {
|
|
38 initialize(VM.getVM().getTypeDataBase());
|
|
39 }
|
|
40 });
|
|
41 }
|
|
42
|
|
43 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
|
|
44 Type type;
|
|
45 try {
|
|
46 type = db.lookupType("ObjectSynchronizer");
|
|
47 AddressField blockListField;
|
|
48 blockListField = type.getAddressField("gBlockList");
|
|
49 gBlockListAddr = blockListField.getValue();
|
|
50 blockSize = db.lookupIntConstant("ObjectSynchronizer::_BLOCKSIZE").intValue();
|
|
51 } catch (RuntimeException e) { }
|
|
52 type = db.lookupType("ObjectMonitor");
|
|
53 objectMonitorTypeSize = type.getSize();
|
|
54 }
|
|
55
|
|
56 public long identityHashValueFor(Oop obj) {
|
|
57 Mark mark = obj.getMark();
|
|
58 if (mark.isUnlocked()) {
|
|
59 // FIXME: can not generate marks in debugging system
|
|
60 return mark.hash();
|
|
61 } else if (mark.hasMonitor()) {
|
|
62 ObjectMonitor monitor = mark.monitor();
|
|
63 Mark temp = monitor.header();
|
|
64 return temp.hash();
|
|
65 } else {
|
|
66 if (Assert.ASSERTS_ENABLED) {
|
|
67 Assert.that(VM.getVM().isDebugging(), "Can not access displaced header otherwise");
|
|
68 }
|
|
69 if (mark.hasDisplacedMarkHelper()) {
|
|
70 Mark temp = mark.displacedMarkHelper();
|
|
71 return temp.hash();
|
|
72 }
|
|
73 // FIXME: can not do anything else here in debugging system
|
|
74 return 0;
|
|
75 }
|
|
76 }
|
|
77
|
|
78 public static Iterator objectMonitorIterator() {
|
|
79 if (gBlockListAddr != null) {
|
|
80 return new ObjectMonitorIterator();
|
|
81 } else {
|
|
82 return null;
|
|
83 }
|
|
84 }
|
|
85
|
|
86 private static class ObjectMonitorIterator implements Iterator {
|
|
87
|
|
88 // JVMTI raw monitors are not pointed by gBlockList
|
|
89 // and are not included by this Iterator. May add them later.
|
|
90
|
|
91 ObjectMonitorIterator() {
|
|
92 blockAddr = gBlockListAddr;
|
|
93 index = blockSize - 1;
|
|
94 block = new ObjectMonitor(blockAddr);
|
|
95 }
|
|
96
|
|
97 public boolean hasNext() {
|
|
98 return (index > 0 || block.freeNext() != null);
|
|
99 }
|
|
100
|
|
101 public Object next() {
|
|
102 Address addr;
|
|
103 if (index > 0) {
|
|
104 addr = blockAddr.addOffsetTo(index*objectMonitorTypeSize);
|
|
105 } else {
|
|
106 blockAddr = block.freeNext();
|
|
107 index = blockSize - 1;
|
|
108 addr = blockAddr.addOffsetTo(index*objectMonitorTypeSize);
|
|
109 }
|
|
110 index --;
|
|
111 return new ObjectMonitor(addr);
|
|
112 }
|
|
113
|
|
114 public void remove() {
|
|
115 throw new UnsupportedOperationException();
|
|
116 }
|
|
117
|
|
118 private ObjectMonitor block;
|
|
119 private int index;
|
|
120 private Address blockAddr;
|
|
121 }
|
|
122
|
|
123 private static Address gBlockListAddr;
|
|
124 private static int blockSize;
|
|
125 private static long objectMonitorTypeSize;
|
|
126
|
|
127 }
|