1 /*
2 * Copyright (c) 2011, 2015, 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 */
59 public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) {
60 this.runtime = runtime;
61 }
62
63 public ResolvedJavaType lookupJavaType(Class<?> clazz) {
64 if (clazz == null) {
65 throw new IllegalArgumentException("Class parameter was null");
66 }
67 return runtime.fromClass(clazz);
68 }
69
70 public HotSpotResolvedObjectType lookupJavaType(JavaConstant constant) {
71 if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) {
72 return null;
73 }
74 return ((HotSpotObjectConstant) constant).getType();
75 }
76
77 public Signature parseMethodDescriptor(String signature) {
78 return new HotSpotSignature(runtime, signature);
79 }
80
81 /**
82 * {@link Field} object of {@link Method#slot}.
83 */
84 private Field reflectionMethodSlot = getReflectionSlotField(Method.class);
85
86 /**
87 * {@link Field} object of {@link Constructor#slot}.
88 */
89 private Field reflectionConstructorSlot = getReflectionSlotField(Constructor.class);
90
91 private static Field getReflectionSlotField(Class<?> reflectionClass) {
92 try {
93 Field field = reflectionClass.getDeclaredField("slot");
94 field.setAccessible(true);
95 return field;
96 } catch (NoSuchFieldException | SecurityException e) {
97 throw new JVMCIError(e);
98 }
|
1 /*
2 * Copyright (c) 2011, 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 */
59 public HotSpotMetaAccessProvider(HotSpotJVMCIRuntimeProvider runtime) {
60 this.runtime = runtime;
61 }
62
63 public ResolvedJavaType lookupJavaType(Class<?> clazz) {
64 if (clazz == null) {
65 throw new IllegalArgumentException("Class parameter was null");
66 }
67 return runtime.fromClass(clazz);
68 }
69
70 public HotSpotResolvedObjectType lookupJavaType(JavaConstant constant) {
71 if (constant.isNull() || !(constant instanceof HotSpotObjectConstant)) {
72 return null;
73 }
74 return ((HotSpotObjectConstant) constant).getType();
75 }
76
77 public Signature parseMethodDescriptor(String signature) {
78 return new HotSpotSignature(runtime, signature);
79 }
80
81 public HotSpotSymbol lookupSymbol(String symbol) {
82 long pointer = runtime.getCompilerToVM().lookupSymbol(symbol);
83 if (pointer == 0) {
84 return null;
85 } else {
86 return new HotSpotSymbol(symbol, pointer);
87 }
88 }
89
90 /**
91 * {@link Field} object of {@link Method#slot}.
92 */
93 private Field reflectionMethodSlot = getReflectionSlotField(Method.class);
94
95 /**
96 * {@link Field} object of {@link Constructor#slot}.
97 */
98 private Field reflectionConstructorSlot = getReflectionSlotField(Constructor.class);
99
100 private static Field getReflectionSlotField(Class<?> reflectionClass) {
101 try {
102 Field field = reflectionClass.getDeclaredField("slot");
103 field.setAccessible(true);
104 return field;
105 } catch (NoSuchFieldException | SecurityException e) {
106 throw new JVMCIError(e);
107 }
|