equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
39 // initialize fields for java.lang.Class |
39 // initialize fields for java.lang.Class |
40 public class java_lang_Class { |
40 public class java_lang_Class { |
41 |
41 |
42 // java.lang.Class fields |
42 // java.lang.Class fields |
43 static int klassOffset; |
43 static int klassOffset; |
|
44 static int arrayKlassOffset; |
44 static IntField oopSizeField; |
45 static IntField oopSizeField; |
45 |
46 |
46 static { |
47 static { |
47 VM.registerVMInitializedObserver(new Observer() { |
48 VM.registerVMInitializedObserver(new Observer() { |
48 public void update(Observable o, Object data) { |
49 public void update(Observable o, Object data) { |
54 private static synchronized void initialize(TypeDataBase db) { |
55 private static synchronized void initialize(TypeDataBase db) { |
55 // klass and oop_size are HotSpot magic fields and hence we can't |
56 // klass and oop_size are HotSpot magic fields and hence we can't |
56 // find them from InstanceKlass for java.lang.Class. |
57 // find them from InstanceKlass for java.lang.Class. |
57 Type jlc = db.lookupType("java_lang_Class"); |
58 Type jlc = db.lookupType("java_lang_Class"); |
58 klassOffset = (int) jlc.getCIntegerField("_klass_offset").getValue(); |
59 klassOffset = (int) jlc.getCIntegerField("_klass_offset").getValue(); |
|
60 arrayKlassOffset = (int) jlc.getCIntegerField("_array_klass_offset").getValue(); |
59 int oopSizeOffset = (int) jlc.getCIntegerField("_oop_size_offset").getValue(); |
61 int oopSizeOffset = (int) jlc.getCIntegerField("_oop_size_offset").getValue(); |
60 oopSizeField = new IntField(new NamedFieldIdentifier("oop_size"), oopSizeOffset, true); |
62 oopSizeField = new IntField(new NamedFieldIdentifier("oop_size"), oopSizeOffset, true); |
61 } |
63 } |
62 |
64 |
63 /** get Klass* field at offset hc_klass_offset from a java.lang.Class object */ |
65 /** get Klass* field at offset hc_klass_offset from a java.lang.Class object */ |
67 |
69 |
68 /** get oop_size field at offset oop_size_offset from a java.lang.Class object */ |
70 /** get oop_size field at offset oop_size_offset from a java.lang.Class object */ |
69 public static long getOopSize(Oop aClass) { |
71 public static long getOopSize(Oop aClass) { |
70 return java_lang_Class.oopSizeField.getValue(aClass); |
72 return java_lang_Class.oopSizeField.getValue(aClass); |
71 } |
73 } |
|
74 |
|
75 /** |
|
76 * Returns the Java name for this Java mirror |
|
77 */ |
|
78 public static String asExternalName(Oop aClass) { |
|
79 Klass k = java_lang_Class.asKlass(aClass); |
|
80 if (k == null) { // primitive array |
|
81 BasicType type = BasicType.T_VOID; |
|
82 ArrayKlass ak = (ArrayKlass)Metadata.instantiateWrapperFor( |
|
83 aClass.getHandle().getAddressAt(arrayKlassOffset)); |
|
84 if (ak != null) { |
|
85 type = BasicType.intToBasicType(ak.getElementType()); |
|
86 } |
|
87 return type.getName(); |
|
88 } else { |
|
89 return k.getName().asString(); |
|
90 } |
|
91 } |
|
92 |
72 } |
93 } |