1 /*
2 * Copyright (c) 2000, 2013, 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 *
23 */
24
25 package sun.jvm.hotspot.types.basic;
26
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.Map;
30
31 import sun.jvm.hotspot.debugger.Address;
32 import sun.jvm.hotspot.debugger.MachineDescription;
33 import sun.jvm.hotspot.runtime.VM;
34 import sun.jvm.hotspot.types.Type;
35 import sun.jvm.hotspot.types.TypeDataBase;
36
37 /** <P> This is a basic implementation of the TypeDataBase interface.
38 It allows an external type database builder to add types to be
39 consumed by a client through the Type interfaces. It has no
40 knowledge of symbol lookup; for example, the builder is
41 responsible for providing the addresses of static fields. </P>
42
43 <P> Among other things, the database builder is responsible for
44 providing the Types for the Java primitive types, as well as their
45 sizes. </P>
46 */
47
48 public class BasicTypeDataBase implements TypeDataBase {
49 private MachineDescription machDesc;
50 private VtblAccess vtblAccess;
51 /** Maps strings to Type objects. This does not contain the primitive types. */
52 private Map nameToTypeMap = new HashMap();
53 /** Maps strings to Integers, used for enums, etc. */
54 private Map nameToIntConstantMap = new HashMap();
55 /** Maps strings to Longs, used for 32/64-bit constants, etc. */
277 // Type was not polymorphic which is an error of some sort
278 throw new InternalError(baseType + " does not appear to be polymorphic");
279 }
280
281 // This is a more restricted version of guessTypeForAddress since
282 // that function has some limitations since it doesn't really know
283 // where in the hierarchy a virtual type starts and just poking
284 // around in memory is likely to trip over some vtable address,
285 // resulting in false positives. Eventually all uses should
286 // switch to this logic but in the interests of stability it will
287 // be separate for the moment.
288
289 // Assuming that the base type is truly the first polymorphic type
290 // then the vtbl for all subclasss should be at several defined
291 // locations so only those locations will be checked. It's also
292 // required that the caller knows that the static type is at least
293 // baseType. See the notes in guessTypeForAddress for the logic of
294 // the locations searched.
295
296 Address loc1 = addr.getAddressAt(0);
297 Address loc2 = null;
298 Address loc3 = null;
299 long offset2 = baseType.getSize();
300 // I don't think this should be misaligned under any
301 // circumstances, but I'm not sure (FIXME: also not sure which
302 // way to go here, up or down -- assuming down)
303 offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
304 if (offset2 > 0) {
305 loc2 = addr.getAddressAt(offset2);
306 }
307 long offset3 = offset2 - getAddressSize();
308 if (offset3 > 0) {
309 loc3 = addr.getAddressAt(offset3);
310 }
311
312 Type loc2Match = null;
313 Type loc3Match = null;
314 for (Iterator iter = getTypes(); iter.hasNext(); ) {
315 Type type = (Type) iter.next();
316 Type superClass = type;
|
1 /*
2 * Copyright (c) 2000, 2018, 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 *
23 */
24
25 package sun.jvm.hotspot.types.basic;
26
27 import java.util.HashMap;
28 import java.util.Iterator;
29 import java.util.Map;
30
31 import sun.jvm.hotspot.debugger.Address;
32 import sun.jvm.hotspot.debugger.MachineDescription;
33 import sun.jvm.hotspot.runtime.VM;
34 import sun.jvm.hotspot.types.Type;
35 import sun.jvm.hotspot.types.TypeDataBase;
36 import sun.jvm.hotspot.memory.FileMapInfo;
37
38 /** <P> This is a basic implementation of the TypeDataBase interface.
39 It allows an external type database builder to add types to be
40 consumed by a client through the Type interfaces. It has no
41 knowledge of symbol lookup; for example, the builder is
42 responsible for providing the addresses of static fields. </P>
43
44 <P> Among other things, the database builder is responsible for
45 providing the Types for the Java primitive types, as well as their
46 sizes. </P>
47 */
48
49 public class BasicTypeDataBase implements TypeDataBase {
50 private MachineDescription machDesc;
51 private VtblAccess vtblAccess;
52 /** Maps strings to Type objects. This does not contain the primitive types. */
53 private Map nameToTypeMap = new HashMap();
54 /** Maps strings to Integers, used for enums, etc. */
55 private Map nameToIntConstantMap = new HashMap();
56 /** Maps strings to Longs, used for 32/64-bit constants, etc. */
278 // Type was not polymorphic which is an error of some sort
279 throw new InternalError(baseType + " does not appear to be polymorphic");
280 }
281
282 // This is a more restricted version of guessTypeForAddress since
283 // that function has some limitations since it doesn't really know
284 // where in the hierarchy a virtual type starts and just poking
285 // around in memory is likely to trip over some vtable address,
286 // resulting in false positives. Eventually all uses should
287 // switch to this logic but in the interests of stability it will
288 // be separate for the moment.
289
290 // Assuming that the base type is truly the first polymorphic type
291 // then the vtbl for all subclasss should be at several defined
292 // locations so only those locations will be checked. It's also
293 // required that the caller knows that the static type is at least
294 // baseType. See the notes in guessTypeForAddress for the logic of
295 // the locations searched.
296
297 Address loc1 = addr.getAddressAt(0);
298
299 if (VM.getVM().isSharingEnabled()) {
300 // Check if the value falls in the _md_region
301 FileMapInfo cdsFileMapInfo = VM.getVM().getFileMapInfo();
302 if (cdsFileMapInfo.inCopiedVtableSpace(loc1) == true) {
303 return cdsFileMapInfo.getTypeForVptrAddress(loc1);
304 }
305 }
306
307 Address loc2 = null;
308 Address loc3 = null;
309 long offset2 = baseType.getSize();
310 // I don't think this should be misaligned under any
311 // circumstances, but I'm not sure (FIXME: also not sure which
312 // way to go here, up or down -- assuming down)
313 offset2 = offset2 - (offset2 % getAddressSize()) - getAddressSize();
314 if (offset2 > 0) {
315 loc2 = addr.getAddressAt(offset2);
316 }
317 long offset3 = offset2 - getAddressSize();
318 if (offset3 > 0) {
319 loc3 = addr.getAddressAt(offset3);
320 }
321
322 Type loc2Match = null;
323 Type loc3Match = null;
324 for (Iterator iter = getTypes(); iter.hasNext(); ) {
325 Type type = (Type) iter.next();
326 Type superClass = type;
|