1 /*
2 * Copyright (c) 2000, 2025, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
163 return true;
164 } catch (Exception e) {
165 return false;
166 }
167 }
168
169 // Creates an instance from the Oop hierarchy based based on the handle
170 public Oop newOop(OopHandle handle) {
171 // The only known way to detect the right type of an oop is
172 // traversing the class chain until a well-known klass is recognized.
173 // A more direct solution would require the klasses to expose
174 // the C++ vtbl structure.
175
176 // Handle the null reference
177 if (handle == null) return null;
178
179 // Then check if obj.klass() is one of the root objects
180 Klass klass = Oop.getKlassForOopHandle(handle);
181 if (klass != null) {
182 if (klass instanceof TypeArrayKlass) return new TypeArray(handle, this);
183 if (klass instanceof ObjArrayKlass) return new ObjArray(handle, this);
184 if (klass instanceof InstanceKlass) return new Instance(handle, this);
185 }
186
187 if (DEBUG) {
188 System.err.println("Unknown oop at " + handle);
189 System.err.println("Oop's klass is " + klass);
190 }
191
192 throw new UnknownOopException(handle.toString());
193 }
194
195 // Print all objects in the object heap
196 public void print() {
197 HeapPrinter printer = new HeapPrinter(System.out);
198 iterate(printer);
199 }
200
201 //---------------------------------------------------------------------------
202 // Internals only below this point
|
1 /*
2 * Copyright (c) 2000, 2026, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
163 return true;
164 } catch (Exception e) {
165 return false;
166 }
167 }
168
169 // Creates an instance from the Oop hierarchy based based on the handle
170 public Oop newOop(OopHandle handle) {
171 // The only known way to detect the right type of an oop is
172 // traversing the class chain until a well-known klass is recognized.
173 // A more direct solution would require the klasses to expose
174 // the C++ vtbl structure.
175
176 // Handle the null reference
177 if (handle == null) return null;
178
179 // Then check if obj.klass() is one of the root objects
180 Klass klass = Oop.getKlassForOopHandle(handle);
181 if (klass != null) {
182 if (klass instanceof TypeArrayKlass) return new TypeArray(handle, this);
183 if (klass instanceof FlatArrayKlass) return new FlatArray(handle, this);
184 if (klass instanceof ObjArrayKlass) return new ObjArray(handle, this);
185 if (klass instanceof InstanceKlass) return new Instance(handle, this);
186 }
187
188 if (DEBUG) {
189 System.err.println("Unknown oop at " + handle);
190 System.err.println("Oop's klass is " + klass);
191 }
192
193 throw new UnknownOopException(handle.toString());
194 }
195
196 // Print all objects in the object heap
197 public void print() {
198 HeapPrinter printer = new HeapPrinter(System.out);
199 iterate(printer);
200 }
201
202 //---------------------------------------------------------------------------
203 // Internals only below this point
|