1 /*
2 * Copyright (c) 2000, 2016, 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 *
67
68 protected void debugMessage(String message) {
69 System.out.println(message);
70 }
71
72 static {
73 VM.registerVMInitializedObserver(new Observer() {
74 public void update(Observable o, Object data) {
75 initialize(VM.getVM().getTypeDataBase());
76 }
77 });
78 }
79
80 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
81 Type type = db.lookupType("ConstantPool");
82 tags = type.getAddressField("_tags");
83 operands = type.getAddressField("_operands");
84 cache = type.getAddressField("_cache");
85 poolHolder = new MetadataField(type.getAddressField("_pool_holder"), 0);
86 length = new CIntField(type.getCIntegerField("_length"), 0);
87 resolvedReferences = type.getAddressField("_resolved_references");
88 referenceMap = type.getAddressField("_reference_map");
89 headerSize = type.getSize();
90 elementSize = 0;
91 // fetch constants:
92 INDY_BSM_OFFSET = db.lookupIntConstant("ConstantPool::_indy_bsm_offset").intValue();
93 INDY_ARGC_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argc_offset").intValue();
94 INDY_ARGV_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argv_offset").intValue();
95 }
96
97 public ConstantPool(Address addr) {
98 super(addr);
99 }
100
101 public boolean isConstantPool() { return true; }
102
103 private static AddressField tags;
104 private static AddressField operands;
105 private static AddressField cache;
106 private static MetadataField poolHolder;
107 private static CIntField length; // number of elements in oop
108 private static AddressField resolvedReferences;
109 private static AddressField referenceMap;
110
111 private static long headerSize;
112 private static long elementSize;
113
114 private static int INDY_BSM_OFFSET;
115 private static int INDY_ARGC_OFFSET;
116 private static int INDY_ARGV_OFFSET;
117
118 public U1Array getTags() { return new U1Array(tags.getValue(getAddress())); }
119 public U2Array getOperands() { return new U2Array(operands.getValue(getAddress())); }
120 public ConstantPoolCache getCache() {
121 Address addr = cache.getValue(getAddress());
122 return (ConstantPoolCache) VMObjectFactory.newObject(ConstantPoolCache.class, addr);
123 }
124 public InstanceKlass getPoolHolder() { return (InstanceKlass)poolHolder.getValue(this); }
125 public int getLength() { return (int)length.getValue(getAddress()); }
126 public Oop getResolvedReferences() {
127 Address handle = resolvedReferences.getValue(getAddress());
128 if (handle != null) {
129 // Load through the handle
130 OopHandle refs = handle.getOopHandleAt(0);
131 return VM.getVM().getObjectHeap().newOop(refs);
132 }
133 return null;
134 }
135
136 public U2Array referenceMap() {
137 return new U2Array(referenceMap.getValue(getAddress()));
138 }
139
140 public int objectToCPIndex(int index) {
141 return referenceMap().at(index);
142 }
143
144 private long getElementSize() {
145 if (elementSize !=0 ) {
146 return elementSize;
147 } else {
148 elementSize = VM.getVM().getOopSize();
149 }
150 return elementSize;
151 }
152
153 private long indexOffset(long index) {
154 if (Assert.ASSERTS_ENABLED) {
155 Assert.that(index >= 0 && index < getLength(), "invalid cp index " + index + " " + getLength());
156 }
157 return (index * getElementSize()) + headerSize;
|
1 /*
2 * Copyright (c) 2000, 2017, 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 *
67
68 protected void debugMessage(String message) {
69 System.out.println(message);
70 }
71
72 static {
73 VM.registerVMInitializedObserver(new Observer() {
74 public void update(Observable o, Object data) {
75 initialize(VM.getVM().getTypeDataBase());
76 }
77 });
78 }
79
80 private static synchronized void initialize(TypeDataBase db) throws WrongTypeException {
81 Type type = db.lookupType("ConstantPool");
82 tags = type.getAddressField("_tags");
83 operands = type.getAddressField("_operands");
84 cache = type.getAddressField("_cache");
85 poolHolder = new MetadataField(type.getAddressField("_pool_holder"), 0);
86 length = new CIntField(type.getCIntegerField("_length"), 0);
87 headerSize = type.getSize();
88 elementSize = 0;
89 // fetch constants:
90 INDY_BSM_OFFSET = db.lookupIntConstant("ConstantPool::_indy_bsm_offset").intValue();
91 INDY_ARGC_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argc_offset").intValue();
92 INDY_ARGV_OFFSET = db.lookupIntConstant("ConstantPool::_indy_argv_offset").intValue();
93 }
94
95 public ConstantPool(Address addr) {
96 super(addr);
97 }
98
99 public boolean isConstantPool() { return true; }
100
101 private static AddressField tags;
102 private static AddressField operands;
103 private static AddressField cache;
104 private static MetadataField poolHolder;
105 private static CIntField length; // number of elements in oop
106
107 private static long headerSize;
108 private static long elementSize;
109
110 private static int INDY_BSM_OFFSET;
111 private static int INDY_ARGC_OFFSET;
112 private static int INDY_ARGV_OFFSET;
113
114 public U1Array getTags() { return new U1Array(tags.getValue(getAddress())); }
115 public U2Array getOperands() { return new U2Array(operands.getValue(getAddress())); }
116 public ConstantPoolCache getCache() {
117 Address addr = cache.getValue(getAddress());
118 return (ConstantPoolCache) VMObjectFactory.newObject(ConstantPoolCache.class, addr);
119 }
120 public InstanceKlass getPoolHolder() { return (InstanceKlass)poolHolder.getValue(this); }
121 public int getLength() { return (int)length.getValue(getAddress()); }
122 public Oop getResolvedReferences() {
123 return getCache().getResolvedReferences();
124 }
125
126 public U2Array referenceMap() {
127 return getCache().referenceMap();
128 }
129
130 public int objectToCPIndex(int index) {
131 return referenceMap().at(index);
132 }
133
134 private long getElementSize() {
135 if (elementSize !=0 ) {
136 return elementSize;
137 } else {
138 elementSize = VM.getVM().getOopSize();
139 }
140 return elementSize;
141 }
142
143 private long indexOffset(long index) {
144 if (Assert.ASSERTS_ENABLED) {
145 Assert.that(index >= 0 && index < getLength(), "invalid cp index " + index + " " + getLength());
146 }
147 return (index * getElementSize()) + headerSize;
|