Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java @ 22773:9273bb6ba33e
Simplify code installation interface: Use CompiledCode class instead of CompilationResult and DataSection.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Fri, 15 Jan 2016 16:50:19 +0100 |
parents | 4cf1946f59fc |
children | 87394b31a42e |
rev | line source |
---|---|
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
2 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
23 package jdk.vm.ci.hotspot; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
25 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
26 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayIndexScale; |
22555
2fe06375f2d3
made HotSpotJVMCIRuntimeProvider.getArrayBaseOffset and HotSpotJVMCIRuntimeProvider.getArrayIndexScale static
Doug Simon <doug.simon@oracle.com>
parents:
22536
diff
changeset
|
27 |
2fe06375f2d3
made HotSpotJVMCIRuntimeProvider.getArrayBaseOffset and HotSpotJVMCIRuntimeProvider.getArrayIndexScale static
Doug Simon <doug.simon@oracle.com>
parents:
22536
diff
changeset
|
28 import java.lang.reflect.Array; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
30 import jdk.vm.ci.meta.Constant; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
31 import jdk.vm.ci.meta.ConstantReflectionProvider; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
32 import jdk.vm.ci.meta.JavaConstant; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
33 import jdk.vm.ci.meta.JavaKind; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
34 import jdk.vm.ci.meta.JavaType; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
35 import jdk.vm.ci.meta.MemoryAccessProvider; |
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
36 import jdk.vm.ci.meta.MethodHandleAccessProvider; |
22757
f4c4cc22a31c
tightened signature of ConstantReflectionProvider methods for reading fields
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
37 import jdk.vm.ci.meta.ResolvedJavaField; |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
38 import jdk.vm.ci.meta.ResolvedJavaType; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 /** |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 * HotSpot implementation of {@link ConstantReflectionProvider}. |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 */ |
18867
7f4cb7587f4c
localized replay compilation marker interface to HotSpot specific code
Doug Simon <doug.simon@oracle.com>
parents:
18801
diff
changeset
|
43 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, HotSpotProxified { |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 |
22758
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
45 private static final String TrustFinalDefaultFieldsProperty = "jvmci.TrustFinalDefaultFields"; |
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
46 |
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
47 /** |
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
48 * Determines whether to treat {@code final} fields with default values as constant. |
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
49 */ |
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
50 private static final boolean TrustFinalDefaultFields = HotSpotJVMCIRuntime.getBooleanOption(TrustFinalDefaultFieldsProperty, true); |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
51 |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
52 protected final HotSpotJVMCIRuntimeProvider runtime; |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
53 protected final HotSpotMethodHandleAccessProvider methodHandleAccess; |
18482
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
54 protected final HotSpotMemoryAccessProviderImpl memoryAccess; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
56 public HotSpotConstantReflectionProvider(HotSpotJVMCIRuntimeProvider runtime) { |
12431
7080a96be216
rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents:
12429
diff
changeset
|
57 this.runtime = runtime; |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
58 this.methodHandleAccess = new HotSpotMethodHandleAccessProvider(this); |
18482
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
59 this.memoryAccess = new HotSpotMemoryAccessProviderImpl(runtime); |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
60 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
61 |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
62 public MethodHandleAccessProvider getMethodHandleAccess() { |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
63 return methodHandleAccess; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 } |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 @Override |
18482
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
67 public MemoryAccessProvider getMemoryAccessProvider() { |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
68 return memoryAccess; |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
69 } |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
70 |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
71 @Override |
18188
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
72 public Boolean constantEquals(Constant x, Constant y) { |
18471
7b60f8334af0
Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents:
18465
diff
changeset
|
73 if (x == y) { |
7b60f8334af0
Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents:
18465
diff
changeset
|
74 return true; |
7b60f8334af0
Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents:
18465
diff
changeset
|
75 } else if (x instanceof HotSpotObjectConstantImpl) { |
7b60f8334af0
Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents:
18465
diff
changeset
|
76 return y instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) x).object() == ((HotSpotObjectConstantImpl) y).object(); |
7b60f8334af0
Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents:
18465
diff
changeset
|
77 } else { |
7b60f8334af0
Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents:
18465
diff
changeset
|
78 return x.equals(y); |
7b60f8334af0
Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents:
18465
diff
changeset
|
79 } |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 } |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
83 public Integer readArrayLength(JavaConstant array) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
84 if (array.getJavaKind() != JavaKind.Object || array.isNull()) { |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 return null; |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 } |
18262
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
87 |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
88 Object arrayObject = ((HotSpotObjectConstantImpl) array).object(); |
18262
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
89 if (!arrayObject.getClass().isArray()) { |
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
90 return null; |
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
91 } |
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
92 return Array.getLength(arrayObject); |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 } |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
95 public JavaConstant readConstantArrayElement(JavaConstant array, int index) { |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
96 if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) { |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
97 JavaConstant element = readArrayElement(array, index); |
18505
3356ea593672
Add missing null check in readConstantArrayElement
Andreas Woess <andreas.woess@jku.at>
parents:
18487
diff
changeset
|
98 if (element != null && (((HotSpotObjectConstantImpl) array).isDefaultStable() || !element.isDefaultForKind())) { |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
99 return element; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
100 } |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
101 } |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
102 return null; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
103 } |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
104 |
21459
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
105 /** |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
106 * Try to convert {@code offset} into an an index into {@code array}. |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
107 * |
21643
2081f8f294fe
Fixed some javadoc
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21556
diff
changeset
|
108 * @return the computed index or -1 if the offset isn't within the array |
21459
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
109 */ |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
110 private int indexForOffset(JavaConstant array, long offset) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
111 if (array.getJavaKind() != JavaKind.Object || array.isNull()) { |
21459
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
112 return -1; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
113 } |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
114 Class<?> componentType = ((HotSpotObjectConstantImpl) array).object().getClass().getComponentType(); |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
115 JavaKind kind = runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType(componentType).getJavaKind(); |
22555
2fe06375f2d3
made HotSpotJVMCIRuntimeProvider.getArrayBaseOffset and HotSpotJVMCIRuntimeProvider.getArrayIndexScale static
Doug Simon <doug.simon@oracle.com>
parents:
22536
diff
changeset
|
116 int arraybase = getArrayBaseOffset(kind); |
2fe06375f2d3
made HotSpotJVMCIRuntimeProvider.getArrayBaseOffset and HotSpotJVMCIRuntimeProvider.getArrayIndexScale static
Doug Simon <doug.simon@oracle.com>
parents:
22536
diff
changeset
|
117 int scale = getArrayIndexScale(kind); |
21459
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
118 if (offset < arraybase) { |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
119 return -1; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
120 } |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
121 long index = offset - arraybase; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
122 if (index % scale != 0) { |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
123 return -1; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
124 } |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
125 long result = index / scale; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
126 if (result >= Integer.MAX_VALUE) { |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
127 return -1; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
128 } |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
129 return (int) result; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
130 } |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
131 |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
132 public JavaConstant readConstantArrayElementForOffset(JavaConstant array, long offset) { |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
133 if (array instanceof HotSpotObjectConstantImpl && ((HotSpotObjectConstantImpl) array).getStableDimension() > 0) { |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
134 return readConstantArrayElement(array, indexForOffset(array, offset)); |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
135 } |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
136 return null; |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
137 } |
f5c2bc68205e
support later folding of constant array reads
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
21377
diff
changeset
|
138 |
15023
652564fe42d5
Use CompressionNode for accessing compressed Klass pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
15018
diff
changeset
|
139 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
140 public JavaConstant readArrayElement(JavaConstant array, int index) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
141 if (array.getJavaKind() != JavaKind.Object || array.isNull()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
142 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
143 } |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
144 Object a = ((HotSpotObjectConstantImpl) array).object(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
145 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
146 if (index < 0 || index >= Array.getLength(a)) { |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
147 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
148 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
149 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
150 if (a instanceof Object[]) { |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
151 Object element = ((Object[]) a)[index]; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
152 if (((HotSpotObjectConstantImpl) array).getStableDimension() > 1) { |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
153 return HotSpotObjectConstantImpl.forStableArray(element, ((HotSpotObjectConstantImpl) array).getStableDimension() - 1, ((HotSpotObjectConstantImpl) array).isDefaultStable()); |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
154 } else { |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
155 return HotSpotObjectConstantImpl.forObject(element); |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
156 } |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
157 } else { |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
158 return JavaConstant.forBoxedPrimitive(Array.get(a, index)); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
159 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
160 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
161 |
18801
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
162 /** |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
163 * Check if the constant is a boxed value that is guaranteed to be cached by the platform. |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
164 * Otherwise the generated code might be the only reference to the boxed value and since object |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
165 * references from nmethods are weak this can cause GC problems. |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
166 * |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
167 * @param source |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
168 * @return true if the box is cached |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
169 */ |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
170 private static boolean isBoxCached(JavaConstant source) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
171 switch (source.getJavaKind()) { |
18801
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
172 case Boolean: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
173 return true; |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
174 case Char: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
175 return source.asInt() <= 127; |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
176 case Byte: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
177 case Short: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
178 case Int: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
179 return source.asInt() >= -128 && source.asInt() <= 127; |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
180 case Long: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
181 return source.asLong() >= -128 && source.asLong() <= 127; |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
182 case Float: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
183 case Double: |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
184 return false; |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
185 default: |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
186 throw new IllegalArgumentException("unexpected kind " + source.getJavaKind()); |
18801
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
187 } |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
188 } |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
189 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
190 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
191 public JavaConstant boxPrimitive(JavaConstant source) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
192 if (!source.getJavaKind().isPrimitive() || !isBoxCached(source)) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
193 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
194 } |
18262
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
195 return HotSpotObjectConstantImpl.forObject(source.asBoxedPrimitive()); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
196 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
197 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
198 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
199 public JavaConstant unboxPrimitive(JavaConstant source) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
200 if (!source.getJavaKind().isObject()) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
201 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
202 } |
18293
ab8fbaa5e72f
fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18290
diff
changeset
|
203 if (source.isNull()) { |
ab8fbaa5e72f
fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18290
diff
changeset
|
204 return null; |
ab8fbaa5e72f
fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18290
diff
changeset
|
205 } |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
206 return JavaConstant.forBoxedPrimitive(((HotSpotObjectConstantImpl) source).object()); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
207 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
208 |
18295
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
209 public JavaConstant forString(String value) { |
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
210 return HotSpotObjectConstantImpl.forObject(value); |
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
211 } |
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
212 |
22645
c33f0cb02b34
Add ConstantReflectionProvider.forObject method and make HotSpotObjectConstantImpl package-private.
Roland Schatz <roland.schatz@oracle.com>
parents:
22590
diff
changeset
|
213 public JavaConstant forObject(Object value) { |
c33f0cb02b34
Add ConstantReflectionProvider.forObject method and make HotSpotObjectConstantImpl package-private.
Roland Schatz <roland.schatz@oracle.com>
parents:
22590
diff
changeset
|
214 return HotSpotObjectConstantImpl.forObject(value); |
c33f0cb02b34
Add ConstantReflectionProvider.forObject method and make HotSpotObjectConstantImpl package-private.
Roland Schatz <roland.schatz@oracle.com>
parents:
22590
diff
changeset
|
215 } |
c33f0cb02b34
Add ConstantReflectionProvider.forObject method and make HotSpotObjectConstantImpl package-private.
Roland Schatz <roland.schatz@oracle.com>
parents:
22590
diff
changeset
|
216 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
217 @Override |
18487
0f4813e0b4a9
Use asConstant() instead of asJavaConstant() where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
18482
diff
changeset
|
218 public ResolvedJavaType asJavaType(Constant constant) { |
15909
e43591136d9f
Support for compressed constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
15291
diff
changeset
|
219 if (constant instanceof HotSpotObjectConstant) { |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
220 Object obj = ((HotSpotObjectConstantImpl) constant).object(); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
221 if (obj instanceof Class) { |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
222 return runtime.getHostJVMCIBackend().getMetaAccess().lookupJavaType((Class<?>) obj); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
223 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
224 } |
16183
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
225 if (constant instanceof HotSpotMetaspaceConstant) { |
22590
3f6488b29c1a
Remove rawValue from HotSpotMetaspaceConstantImpl, patch raw pointer at code installation time.
Roland Schatz <roland.schatz@oracle.com>
parents:
22555
diff
changeset
|
226 MetaspaceWrapperObject obj = HotSpotMetaspaceConstantImpl.getMetaspaceObject(constant); |
18223
17c98fad6980
converted HotSpotResolvedObjectType to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
227 if (obj instanceof HotSpotResolvedObjectTypeImpl) { |
16183
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
228 return (ResolvedJavaType) obj; |
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
229 } |
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
230 } |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
231 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
232 } |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
233 |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
234 private static final String SystemClassName = "Ljava/lang/System;"; |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
235 |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
236 /** |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
237 * Determines if a static field is constant for the purpose of |
22757
f4c4cc22a31c
tightened signature of ConstantReflectionProvider methods for reading fields
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
238 * {@link #readConstantFieldValue(ResolvedJavaField, JavaConstant)}. |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
239 */ |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
240 protected boolean isStaticFieldConstant(HotSpotResolvedJavaField staticField) { |
22760
4cf1946f59fc
must not fold accesses to @Stable fields if -XX:-FoldStableValues (GRAAL-58)
Doug Simon <doug.simon@oracle.com>
parents:
22758
diff
changeset
|
241 if (staticField.isFinal() || (staticField.isStable() && runtime.getConfig().foldStableValues)) { |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
242 ResolvedJavaType holder = staticField.getDeclaringClass(); |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
243 if (holder.isInitialized() && !holder.getName().equals(SystemClassName)) { |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
244 return true; |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
245 } |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
246 } |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
247 return false; |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
248 } |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
249 |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
250 /** |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
251 * Determines if a value read from a {@code final} instance field is considered constant. The |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
252 * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
253 * not the {@link JavaConstant#isDefaultForKind default value} for its kind or if |
22758
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
254 * {@link #TrustFinalDefaultFields} is true. |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
255 * |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
256 * @param value a value read from a {@code final} instance field |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
257 * @param receiverClass the {@link Object#getClass() class} of object from which the |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
258 * {@code value} was read |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
259 */ |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
260 protected boolean isFinalInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) { |
22758
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
261 return !value.isDefaultForKind() || TrustFinalDefaultFields; |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
262 } |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
263 |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
264 /** |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
265 * Determines if a value read from a {@link Stable} instance field is considered constant. The |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
266 * implementation in {@link HotSpotConstantReflectionProvider} returns true if {@code value} is |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
267 * not the {@link JavaConstant#isDefaultForKind default value} for its kind. |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
268 * |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
269 * @param value a value read from a {@link Stable} field |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
270 * @param receiverClass the {@link Object#getClass() class} of object from which the |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
271 * {@code value} was read |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
272 */ |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
273 protected boolean isStableInstanceFieldValueConstant(JavaConstant value, Class<?> receiverClass) { |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
274 return !value.isDefaultForKind(); |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
275 } |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
276 |
22757
f4c4cc22a31c
tightened signature of ConstantReflectionProvider methods for reading fields
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
277 public JavaConstant readConstantFieldValue(ResolvedJavaField field, JavaConstant receiver) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
278 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
279 |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
280 if (hotspotField.isStatic()) { |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
281 if (isStaticFieldConstant(hotspotField)) { |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
282 JavaConstant value = readFieldValue(field, receiver); |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
283 if (hotspotField.isFinal() || !value.isDefaultForKind()) { |
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
284 return value; |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
285 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
286 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
287 } else { |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
288 /* |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
289 * for non-static final fields, we must assume that they are only initialized if they |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
290 * have a non-default value. |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
291 */ |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
292 Object object = receiver.isNull() ? null : ((HotSpotObjectConstantImpl) receiver).object(); |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
293 |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
294 // Canonicalization may attempt to process an unsafe read before |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
295 // processing a guard (e.g. a null check or a type check) for this read |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
296 // so we need to check the object being read |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
297 if (object != null) { |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
298 if (hotspotField.isFinal()) { |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
299 if (hotspotField.isInObject(object)) { |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
300 JavaConstant value = readFieldValue(field, receiver); |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
301 if (isFinalInstanceFieldValueConstant(value, object.getClass())) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
302 return value; |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
303 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
304 } |
22760
4cf1946f59fc
must not fold accesses to @Stable fields if -XX:-FoldStableValues (GRAAL-58)
Doug Simon <doug.simon@oracle.com>
parents:
22758
diff
changeset
|
305 } else if (hotspotField.isStable() && runtime.getConfig().foldStableValues) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
306 if (hotspotField.isInObject(object)) { |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
307 JavaConstant value = readFieldValue(field, receiver); |
21552
9579a3c62a9e
use skeleton findbugs jar containing only SuppresFBWarnings to avoid external dependency for JVMCI classes (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
21459
diff
changeset
|
308 if (isStableInstanceFieldValueConstant(value, object.getClass())) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
309 return value; |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
310 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
311 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
312 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
313 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
314 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
315 return null; |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
316 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
317 |
22757
f4c4cc22a31c
tightened signature of ConstantReflectionProvider methods for reading fields
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
318 public JavaConstant readFieldValue(ResolvedJavaField field, JavaConstant receiver) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
319 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
320 if (!hotspotField.isStable()) { |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
321 return readNonStableFieldValue(field, receiver); |
22760
4cf1946f59fc
must not fold accesses to @Stable fields if -XX:-FoldStableValues (GRAAL-58)
Doug Simon <doug.simon@oracle.com>
parents:
22758
diff
changeset
|
322 } else if (runtime.getConfig().foldStableValues) { |
4cf1946f59fc
must not fold accesses to @Stable fields if -XX:-FoldStableValues (GRAAL-58)
Doug Simon <doug.simon@oracle.com>
parents:
22758
diff
changeset
|
323 return readStableFieldValue(field, receiver, hotspotField.isDefaultStable()); |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
324 } else { |
22760
4cf1946f59fc
must not fold accesses to @Stable fields if -XX:-FoldStableValues (GRAAL-58)
Doug Simon <doug.simon@oracle.com>
parents:
22758
diff
changeset
|
325 return null; |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
326 } |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
327 } |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
328 |
22758
a130b51efb07
removed @Option mechanism from JVMCI (GRAAL-1371)
Doug Simon <doug.simon@oracle.com>
parents:
22757
diff
changeset
|
329 private JavaConstant readNonStableFieldValue(ResolvedJavaField field, JavaConstant receiver) { |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
330 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
331 if (hotspotField.isStatic()) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
332 HotSpotResolvedJavaType holder = (HotSpotResolvedJavaType) hotspotField.getDeclaringClass(); |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
333 if (holder.isInitialized()) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
334 return memoryAccess.readUnsafeConstant(hotspotField.getJavaKind(), HotSpotObjectConstantImpl.forObject(holder.mirror()), hotspotField.offset()); |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
335 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
336 } else { |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
337 if (receiver.isNonNull() && hotspotField.isInObject(((HotSpotObjectConstantImpl) receiver).object())) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
338 return memoryAccess.readUnsafeConstant(hotspotField.getJavaKind(), receiver, hotspotField.offset()); |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
339 } |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
340 } |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
341 return null; |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
342 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
343 |
22757
f4c4cc22a31c
tightened signature of ConstantReflectionProvider methods for reading fields
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
344 public JavaConstant readStableFieldValue(ResolvedJavaField field, JavaConstant receiver, boolean isDefaultStable) { |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
345 JavaConstant fieldValue = readNonStableFieldValue(field, receiver); |
18564
966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
346 if (fieldValue.isNonNull()) { |
966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
347 JavaType declaredType = field.getType(); |
966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
348 if (declaredType.getComponentType() != null) { |
966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
349 int stableDimension = getArrayDimension(declaredType); |
966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
350 return HotSpotObjectConstantImpl.forStableArray(((HotSpotObjectConstantImpl) fieldValue).object(), stableDimension, isDefaultStable); |
966081b8e830
guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents:
18530
diff
changeset
|
351 } |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
352 } |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
353 return fieldValue; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
354 } |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
355 |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
356 private static int getArrayDimension(JavaType type) { |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
357 int dimensions = 0; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
358 JavaType componentType = type; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
359 while ((componentType = componentType.getComponentType()) != null) { |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
360 dimensions++; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
361 } |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
362 return dimensions; |
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
363 } |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
364 } |