0
|
1 /*
|
|
2 * Copyright 2000-2006 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.memory;
|
|
26
|
|
27 import java.io.*;
|
|
28 import java.util.*;
|
|
29 import sun.jvm.hotspot.debugger.*;
|
|
30 import sun.jvm.hotspot.gc_interface.*;
|
|
31 import sun.jvm.hotspot.gc_implementation.parallelScavenge.*;
|
|
32 import sun.jvm.hotspot.oops.*;
|
|
33 import sun.jvm.hotspot.types.*;
|
|
34 import sun.jvm.hotspot.runtime.*;
|
|
35
|
|
36
|
|
37 public class Universe {
|
|
38 private static AddressField collectedHeapField;
|
|
39 private static VirtualConstructor heapConstructor;
|
|
40 private static sun.jvm.hotspot.types.OopField mainThreadGroupField;
|
|
41 private static sun.jvm.hotspot.types.OopField systemThreadGroupField;
|
|
42
|
|
43 // single dimensional primitive array klasses
|
|
44 private static sun.jvm.hotspot.types.OopField boolArrayKlassObjField;
|
|
45 private static sun.jvm.hotspot.types.OopField byteArrayKlassObjField;
|
|
46 private static sun.jvm.hotspot.types.OopField charArrayKlassObjField;
|
|
47 private static sun.jvm.hotspot.types.OopField intArrayKlassObjField;
|
|
48 private static sun.jvm.hotspot.types.OopField shortArrayKlassObjField;
|
|
49 private static sun.jvm.hotspot.types.OopField longArrayKlassObjField;
|
|
50 private static sun.jvm.hotspot.types.OopField singleArrayKlassObjField;
|
|
51 private static sun.jvm.hotspot.types.OopField doubleArrayKlassObjField;
|
|
52
|
|
53 // system obj array klass object
|
|
54 private static sun.jvm.hotspot.types.OopField systemObjArrayKlassObjField;
|
|
55
|
|
56 static {
|
|
57 VM.registerVMInitializedObserver(new Observer() {
|
|
58 public void update(Observable o, Object data) {
|
|
59 initialize(VM.getVM().getTypeDataBase());
|
|
60 }
|
|
61 });
|
|
62 }
|
|
63
|
|
64 private static synchronized void initialize(TypeDataBase db) {
|
|
65 Type type = db.lookupType("Universe");
|
|
66
|
|
67 collectedHeapField = type.getAddressField("_collectedHeap");
|
|
68
|
|
69 heapConstructor = new VirtualConstructor(db);
|
|
70 heapConstructor.addMapping("GenCollectedHeap", GenCollectedHeap.class);
|
|
71 heapConstructor.addMapping("ParallelScavengeHeap", ParallelScavengeHeap.class);
|
|
72
|
|
73 mainThreadGroupField = type.getOopField("_main_thread_group");
|
|
74 systemThreadGroupField = type.getOopField("_system_thread_group");
|
|
75
|
|
76 boolArrayKlassObjField = type.getOopField("_boolArrayKlassObj");
|
|
77 byteArrayKlassObjField = type.getOopField("_byteArrayKlassObj");
|
|
78 charArrayKlassObjField = type.getOopField("_charArrayKlassObj");
|
|
79 intArrayKlassObjField = type.getOopField("_intArrayKlassObj");
|
|
80 shortArrayKlassObjField = type.getOopField("_shortArrayKlassObj");
|
|
81 longArrayKlassObjField = type.getOopField("_longArrayKlassObj");
|
|
82 singleArrayKlassObjField = type.getOopField("_singleArrayKlassObj");
|
|
83 doubleArrayKlassObjField = type.getOopField("_doubleArrayKlassObj");
|
|
84
|
|
85 systemObjArrayKlassObjField = type.getOopField("_systemObjArrayKlassObj");
|
|
86 }
|
|
87
|
|
88 public Universe() {
|
|
89 }
|
|
90
|
|
91 public CollectedHeap heap() {
|
|
92 try {
|
|
93 return (CollectedHeap) heapConstructor.instantiateWrapperFor(collectedHeapField.getValue());
|
|
94 } catch (WrongTypeException e) {
|
|
95 return new CollectedHeap(collectedHeapField.getValue());
|
|
96 }
|
|
97 }
|
|
98
|
|
99 /** Returns "TRUE" iff "p" points into the allocated area of the heap. */
|
|
100 public boolean isIn(Address p) {
|
|
101 return heap().isIn(p);
|
|
102 }
|
|
103
|
|
104 /** Returns "TRUE" iff "p" points into the reserved area of the heap. */
|
|
105 public boolean isInReserved(Address p) {
|
|
106 return heap().isInReserved(p);
|
|
107 }
|
|
108
|
|
109 private Oop newOop(OopHandle handle) {
|
|
110 return VM.getVM().getObjectHeap().newOop(handle);
|
|
111 }
|
|
112
|
|
113 public Oop mainThreadGroup() {
|
|
114 return newOop(mainThreadGroupField.getValue());
|
|
115 }
|
|
116
|
|
117 public Oop systemThreadGroup() {
|
|
118 return newOop(systemThreadGroupField.getValue());
|
|
119 }
|
|
120
|
|
121 public Oop systemObjArrayKlassObj() {
|
|
122 return newOop(systemObjArrayKlassObjField.getValue());
|
|
123 }
|
|
124
|
|
125 // iterate through the single dimensional primitive array klasses
|
|
126 // refer to basic_type_classes_do(void f(klassOop)) in universe.cpp
|
|
127 public void basicTypeClassesDo(SystemDictionary.ClassVisitor visitor) {
|
|
128 visitor.visit((Klass)newOop(boolArrayKlassObjField.getValue()));
|
|
129 visitor.visit((Klass)newOop(byteArrayKlassObjField.getValue()));
|
|
130 visitor.visit((Klass)newOop(charArrayKlassObjField.getValue()));
|
|
131 visitor.visit((Klass)newOop(intArrayKlassObjField.getValue()));
|
|
132 visitor.visit((Klass)newOop(shortArrayKlassObjField.getValue()));
|
|
133 visitor.visit((Klass)newOop(longArrayKlassObjField.getValue()));
|
|
134 visitor.visit((Klass)newOop(singleArrayKlassObjField.getValue()));
|
|
135 visitor.visit((Klass)newOop(doubleArrayKlassObjField.getValue()));
|
|
136 }
|
|
137
|
|
138 public void print() { printOn(System.out); }
|
|
139 public void printOn(PrintStream tty) {
|
|
140 heap().printOn(tty);
|
|
141 }
|
|
142
|
|
143 // Check whether an element of a typeArrayOop with the given type must be
|
|
144 // aligned 0 mod 8. The typeArrayOop itself must be aligned at least this
|
|
145 // strongly.
|
|
146 public static boolean elementTypeShouldBeAligned(BasicType type) {
|
|
147 return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
|
|
148 }
|
|
149
|
|
150 // Check whether an object field (static/non-static) of the given type must be
|
|
151 // aligned 0 mod 8.
|
|
152 public static boolean fieldTypeShouldBeAligned(BasicType type) {
|
|
153 return type == BasicType.T_DOUBLE || type == BasicType.T_LONG;
|
|
154 }
|
|
155 }
|