annotate agent/src/share/classes/sun/jvm/hotspot/code/StubQueue.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
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: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.code;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import java.util.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28 import sun.jvm.hotspot.debugger.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
29 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.types.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 import sun.jvm.hotspot.utilities.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 /** <P> A port of the VM's StubQueue. Note that the VM implicitly
a61af66fc99e Initial load
duke
parents:
diff changeset
34 knows the type of the objects contained in each StubQueue because
a61af66fc99e Initial load
duke
parents:
diff changeset
35 it passes in an instance of a StubInterface to the StubQueue's
a61af66fc99e Initial load
duke
parents:
diff changeset
36 constructor; the goal in the VM was to save space in the generated
a61af66fc99e Initial load
duke
parents:
diff changeset
37 code. In the SA APIs the pattern has been to use the
a61af66fc99e Initial load
duke
parents:
diff changeset
38 VirtualConstructor mechanism to instantiate wrapper objects of the
a61af66fc99e Initial load
duke
parents:
diff changeset
39 appropriate type for objects down in the VM; see, for example, the
a61af66fc99e Initial load
duke
parents:
diff changeset
40 CodeCache, which identifies NMethods, RuntimeStubs, etc. </P>
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 <P> In this port we eliminate the StubInterface in favor of
a61af66fc99e Initial load
duke
parents:
diff changeset
43 passing in the class corresponding to the type of Stub which this
a61af66fc99e Initial load
duke
parents:
diff changeset
44 StubQueue contains. </P> */
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 public class StubQueue extends VMObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 // FIXME: add the rest of the fields
a61af66fc99e Initial load
duke
parents:
diff changeset
48 private static AddressField stubBufferField;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 private static CIntegerField bufferLimitField;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 private static CIntegerField queueBeginField;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 private static CIntegerField queueEndField;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 private static CIntegerField numberOfStubsField;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // The type of the contained stubs (i.e., InterpreterCodelet,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // ICStub). Must be a subclass of type Stub.
a61af66fc99e Initial load
duke
parents:
diff changeset
56 private Class stubType;
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 VM.registerVMInitializedObserver(new Observer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 public void update(Observable o, Object data) {
a61af66fc99e Initial load
duke
parents:
diff changeset
61 initialize(VM.getVM().getTypeDataBase());
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 });
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 private static synchronized void initialize(TypeDataBase db) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 Type type = db.lookupType("StubQueue");
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 stubBufferField = type.getAddressField("_stub_buffer");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 bufferLimitField = type.getCIntegerField("_buffer_limit");
a61af66fc99e Initial load
duke
parents:
diff changeset
71 queueBeginField = type.getCIntegerField("_queue_begin");
a61af66fc99e Initial load
duke
parents:
diff changeset
72 queueEndField = type.getCIntegerField("_queue_end");
a61af66fc99e Initial load
duke
parents:
diff changeset
73 numberOfStubsField = type.getCIntegerField("_number_of_stubs");
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 public StubQueue(Address addr, Class stubType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 super(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 this.stubType = stubType;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 public boolean contains(Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (pc == null) return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
83 long offset = pc.minus(getStubBuffer());
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return ((0 <= offset) && (offset < getBufferLimit()));
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 public Stub getStubContaining(Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (contains(pc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 int i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 for (Stub s = getFirst(); s != null; s = getNext(s)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (stubContains(s, pc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return s;
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 public boolean stubContains(Stub s, Address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return (s.codeBegin().lessThanOrEqual(pc) && s.codeEnd().greaterThan(pc));
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 public int getNumberOfStubs() {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 return (int) numberOfStubsField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public Stub getFirst() {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 return ((getNumberOfStubs() > 0) ? getStubAt(getQueueBegin()) : null);
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 public Stub getNext(Stub s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 long i = getIndexOf(s) + getStubSize(s);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (i == getBufferLimit()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 i = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return ((i == getQueueEnd()) ? null : getStubAt(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 public Stub getPrev(Stub s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if (getIndexOf(s) == getQueueBegin()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 Stub temp = getFirst();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 Stub prev = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 while (temp != null && getIndexOf(temp) != getIndexOf(s)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 prev = temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 temp = getNext(temp);
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return prev;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 //--------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
136 //
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 private long getQueueBegin() {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 return queueBeginField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 private long getQueueEnd() {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 return queueEndField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 }
a61af66fc99e Initial load
duke
parents:
diff changeset
145
a61af66fc99e Initial load
duke
parents:
diff changeset
146 private long getBufferLimit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 return bufferLimitField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 private Address getStubBuffer() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 return stubBufferField.getValue(addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153
a61af66fc99e Initial load
duke
parents:
diff changeset
154 private Stub getStubAt(long offset) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 checkIndex(offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
156 return (Stub) VMObjectFactory.newObject(stubType, getStubBuffer().addOffsetTo(offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
157 }
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 private long getIndexOf(Stub s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 long i = s.getAddress().minus(getStubBuffer());
a61af66fc99e Initial load
duke
parents:
diff changeset
161 checkIndex(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return i;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 private long getStubSize(Stub s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return s.getSize();
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 private void checkIndex(long i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 if (Assert.ASSERTS_ENABLED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 Assert.that(0 <= i && i < getBufferLimit() && (i % VM.getVM().getAddressSize() == 0), "illegal index");
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }