annotate agent/src/share/classes/sun/jvm/hotspot/utilities/soql/JSJavaVM.java @ 113:ba764ed4b6f2

6420645: Create a vm that uses compressed oops for up to 32gb heapsizes Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold
author coleenp
date Sun, 13 Apr 2008 17:43:42 -0400
parents a61af66fc99e
children c18cbe5936b8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
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.utilities.soql;
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.oops.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
30 import sun.jvm.hotspot.runtime.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 public class JSJavaVM extends DefaultScriptObject {
a61af66fc99e Initial load
duke
parents:
diff changeset
33 private static final int FIELD_ADDRESS_SIZE = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 private static final int FIELD_BUILD_INFO = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 private static final int FIELD_CPU = 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 private static final int FIELD_FLAGS = 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 private static final int FIELD_HEAP = 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 private static final int FIELD_OS = 5;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 private static final int FIELD_SYS_PROPS = 6;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private static final int FIELD_THREADS = 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private static final int FIELD_TYPE = 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private static final int FIELD_VERSION = 9;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private static final int FIELD_CLASS_PATH = 10;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 private static final int FIELD_BOOT_CLASS_PATH = 11;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 private static final int FIELD_USER_DIR = 12;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 private static final int FIELD_UNDEFINED = -1;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public JSJavaVM(JSJavaFactory factory) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 this.factory = factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 this.vm = VM.getVM();
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 public Object get(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 int fieldID = getFieldID(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 switch (fieldID) {
a61af66fc99e Initial load
duke
parents:
diff changeset
56 case FIELD_ADDRESS_SIZE:
a61af66fc99e Initial load
duke
parents:
diff changeset
57 return new Long(getVMBit());
a61af66fc99e Initial load
duke
parents:
diff changeset
58 case FIELD_BUILD_INFO:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return vm.getVMInternalInfo();
a61af66fc99e Initial load
duke
parents:
diff changeset
60 case FIELD_CPU:
a61af66fc99e Initial load
duke
parents:
diff changeset
61 return vm.getCPU();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 case FIELD_FLAGS:
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return getFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
64 case FIELD_HEAP:
a61af66fc99e Initial load
duke
parents:
diff changeset
65 return getHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 case FIELD_OS:
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return vm.getOS();
a61af66fc99e Initial load
duke
parents:
diff changeset
68 case FIELD_SYS_PROPS:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return getSysProps();
a61af66fc99e Initial load
duke
parents:
diff changeset
70 case FIELD_THREADS:
a61af66fc99e Initial load
duke
parents:
diff changeset
71 return getThreads();
a61af66fc99e Initial load
duke
parents:
diff changeset
72 case FIELD_TYPE:
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return getType();
a61af66fc99e Initial load
duke
parents:
diff changeset
74 case FIELD_VERSION:
a61af66fc99e Initial load
duke
parents:
diff changeset
75 return vm.getVMRelease();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 case FIELD_CLASS_PATH:
a61af66fc99e Initial load
duke
parents:
diff changeset
77 return getClassPath();
a61af66fc99e Initial load
duke
parents:
diff changeset
78 case FIELD_BOOT_CLASS_PATH:
a61af66fc99e Initial load
duke
parents:
diff changeset
79 return getBootClassPath();
a61af66fc99e Initial load
duke
parents:
diff changeset
80 case FIELD_USER_DIR:
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return getUserDir();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 case FIELD_UNDEFINED:
a61af66fc99e Initial load
duke
parents:
diff changeset
83 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return super.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 }
a61af66fc99e Initial load
duke
parents:
diff changeset
86 }
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 public Object[] getIds() {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 Object[] superIds = super.getIds();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 Object[] tmp = fields.keySet().toArray();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 Object[] res = new Object[superIds.length + tmp.length];
a61af66fc99e Initial load
duke
parents:
diff changeset
92 System.arraycopy(tmp, 0, res, 0, tmp.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 System.arraycopy(superIds, 0, res, tmp.length, superIds.length);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 public boolean has(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 if (getFieldID(name) != FIELD_UNDEFINED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
100 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return super.has(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 public void put(String name, Object value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (getFieldID(name) == FIELD_UNDEFINED) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 super.put(name, value);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
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 String toString() {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 StringBuffer buf = new StringBuffer();
a61af66fc99e Initial load
duke
parents:
diff changeset
113 buf.append("Java Hotspot ");
a61af66fc99e Initial load
duke
parents:
diff changeset
114 buf.append(getType());
a61af66fc99e Initial load
duke
parents:
diff changeset
115 buf.append(' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
116 buf.append(getVMBit());
a61af66fc99e Initial load
duke
parents:
diff changeset
117 buf.append(" bit VM (build ");
a61af66fc99e Initial load
duke
parents:
diff changeset
118 buf.append(vm.getVMRelease());
a61af66fc99e Initial load
duke
parents:
diff changeset
119 buf.append(")");
a61af66fc99e Initial load
duke
parents:
diff changeset
120 return buf.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 //-- Internals only below this point
a61af66fc99e Initial load
duke
parents:
diff changeset
124 private static Map fields = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
125 private static void addField(String name, int fieldId) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 fields.put(name, new Integer(fieldId));
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 private static int getFieldID(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 Integer res = (Integer) fields.get(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 return (res != null)? res.intValue() : FIELD_UNDEFINED;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 }
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 static {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 addField("addressSize", FIELD_ADDRESS_SIZE);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 addField("buildInfo", FIELD_BUILD_INFO);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 addField("cpu", FIELD_CPU);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 addField("flags", FIELD_FLAGS);
a61af66fc99e Initial load
duke
parents:
diff changeset
139 addField("heap", FIELD_HEAP);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 addField("os", FIELD_OS);
a61af66fc99e Initial load
duke
parents:
diff changeset
141 addField("sysProps", FIELD_SYS_PROPS);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 addField("threads", FIELD_THREADS);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 addField("type", FIELD_TYPE);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 addField("version", FIELD_VERSION);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 addField("classPath", FIELD_CLASS_PATH);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 addField("bootClassPath", FIELD_BOOT_CLASS_PATH);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 addField("userDir", FIELD_USER_DIR);
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 long getVMBit() {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // address size in bits
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return vm.getAddressSize() * 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 private synchronized JSMap getFlags() {
a61af66fc99e Initial load
duke
parents:
diff changeset
156 if (flagsCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 VM.Flag[] flags = vm.getCommandLineFlags();
a61af66fc99e Initial load
duke
parents:
diff changeset
158 Map map = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
159 if (flags != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 for (int f = 0; f < flags.length; f++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
161 VM.Flag flag = flags[f];
a61af66fc99e Initial load
duke
parents:
diff changeset
162 map.put(flag.getName(), flag.getValue());
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 flagsCache = factory.newJSMap(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 return flagsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
168 }
a61af66fc99e Initial load
duke
parents:
diff changeset
169
a61af66fc99e Initial load
duke
parents:
diff changeset
170 private synchronized JSJavaHeap getHeap() {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 if (heapCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 heapCache = factory.newJSJavaHeap();
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 return heapCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 }
a61af66fc99e Initial load
duke
parents:
diff changeset
176
a61af66fc99e Initial load
duke
parents:
diff changeset
177 private synchronized JSMap getSysProps() {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 if (sysPropsCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 Properties props = vm.getSystemProperties();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 Map map = new HashMap();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if (props != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 Enumeration e = props.propertyNames();
a61af66fc99e Initial load
duke
parents:
diff changeset
183 while (e.hasMoreElements()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 String key = (String) e.nextElement();
a61af66fc99e Initial load
duke
parents:
diff changeset
185 map.put(key, props.getProperty(key));
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187 }
a61af66fc99e Initial load
duke
parents:
diff changeset
188 sysPropsCache = factory.newJSMap(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 return sysPropsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192
a61af66fc99e Initial load
duke
parents:
diff changeset
193 private synchronized JSList getThreads() {
a61af66fc99e Initial load
duke
parents:
diff changeset
194 if (threadsCache == null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 List threads = new ArrayList(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
196 threadsCache = factory.newJSList(threads);
a61af66fc99e Initial load
duke
parents:
diff changeset
197 JavaThread jthread = vm.getThreads().first();
a61af66fc99e Initial load
duke
parents:
diff changeset
198 while (jthread != null) {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 threads.add(jthread);
a61af66fc99e Initial load
duke
parents:
diff changeset
200 jthread = jthread.next();
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 return threadsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205
a61af66fc99e Initial load
duke
parents:
diff changeset
206 private String getType() {
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (vm.isClientCompiler()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 return "Client";
a61af66fc99e Initial load
duke
parents:
diff changeset
209 } else if (vm.isServerCompiler()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 return "Server";
a61af66fc99e Initial load
duke
parents:
diff changeset
211 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
212 return "Core";
a61af66fc99e Initial load
duke
parents:
diff changeset
213 }
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 private String getClassPath() {
a61af66fc99e Initial load
duke
parents:
diff changeset
217 return vm.getSystemProperty("java.class.path");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 }
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 private String getBootClassPath() {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 return vm.getSystemProperty("sun.boot.class.path");
a61af66fc99e Initial load
duke
parents:
diff changeset
222 }
a61af66fc99e Initial load
duke
parents:
diff changeset
223
a61af66fc99e Initial load
duke
parents:
diff changeset
224 private String getUserDir() {
a61af66fc99e Initial load
duke
parents:
diff changeset
225 return vm.getSystemProperty("user.dir");
a61af66fc99e Initial load
duke
parents:
diff changeset
226 }
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 private JSMap flagsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
229 private JSJavaHeap heapCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
230 private JSMap sysPropsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 private JSList threadsCache;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 private final JSJavaFactory factory;
a61af66fc99e Initial load
duke
parents:
diff changeset
233 private final VM vm;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }