Mercurial > hg > graal-jvmci-8
annotate jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotConstantReflectionProvider.java @ 23738:1140503536ae jvmci-0.19
Backport style fixes and comments from jdk9.
author | Roland Schatz <roland.schatz@oracle.com> |
---|---|
date | Fri, 12 Aug 2016 11:07:39 +0200 |
parents | 3e8ce13f4e12 |
children | 2e9d95cef56b |
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 |
22555
2fe06375f2d3
made HotSpotJVMCIRuntimeProvider.getArrayBaseOffset and HotSpotJVMCIRuntimeProvider.getArrayIndexScale static
Doug Simon <doug.simon@oracle.com>
parents:
22536
diff
changeset
|
25 import java.lang.reflect.Array; |
23398
3e8ce13f4e12
minimize diff to jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23393
diff
changeset
|
26 import java.util.Objects; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
27 |
23392
b3a816d3b844
Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents:
23387
diff
changeset
|
28 import jdk.vm.ci.common.JVMCIError; |
22672
1bbd4a7c274b
Rename jdk.internal.jvmci to jdk.vm.ci
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
22664
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 import jdk.vm.ci.meta.ResolvedJavaType; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 /** |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 * HotSpot implementation of {@link ConstantReflectionProvider}. |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 */ |
23393
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
23392
diff
changeset
|
41 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider { |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 |
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
|
43 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
|
44 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
|
45 protected final HotSpotMemoryAccessProviderImpl memoryAccess; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 |
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
|
47 public HotSpotConstantReflectionProvider(HotSpotJVMCIRuntimeProvider runtime) { |
12431
7080a96be216
rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents:
12429
diff
changeset
|
48 this.runtime = runtime; |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
49 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
|
50 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
|
51 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
52 |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
53 public MethodHandleAccessProvider getMethodHandleAccess() { |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
54 return methodHandleAccess; |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 } |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 @Override |
18482
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
58 public MemoryAccessProvider getMemoryAccessProvider() { |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
59 return memoryAccess; |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
60 } |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
61 |
b8a622c3e99f
Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents:
18472
diff
changeset
|
62 @Override |
18188
8652481a1110
Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents:
18187
diff
changeset
|
63 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
|
64 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
|
65 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
|
66 } 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
|
67 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
|
68 } else { |
23398
3e8ce13f4e12
minimize diff to jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23393
diff
changeset
|
69 return Objects.equals(x, 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
|
70 } |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 } |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
74 public Integer readArrayLength(JavaConstant array) { |
23398
3e8ce13f4e12
minimize diff to jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23393
diff
changeset
|
75 if (array == null || array.getJavaKind() != JavaKind.Object || array.isNull()) { |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 return null; |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 } |
18262
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
78 |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
79 Object arrayObject = ((HotSpotObjectConstantImpl) array).object(); |
18262
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
80 if (!arrayObject.getClass().isArray()) { |
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
81 return null; |
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
82 } |
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
83 return Array.getLength(arrayObject); |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 } |
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 |
15023
652564fe42d5
Use CompressionNode for accessing compressed Klass pointers.
Roland Schatz <roland.schatz@oracle.com>
parents:
15018
diff
changeset
|
86 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
87 public JavaConstant readArrayElement(JavaConstant array, int index) { |
23398
3e8ce13f4e12
minimize diff to jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23393
diff
changeset
|
88 if (array == null || 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
|
89 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
90 } |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
91 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
|
92 |
23398
3e8ce13f4e12
minimize diff to jvmci-9
Doug Simon <doug.simon@oracle.com>
parents:
23393
diff
changeset
|
93 if (!a.getClass().isArray() || index < 0 || index >= Array.getLength(a)) { |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
94 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
95 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
96 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
97 if (a instanceof Object[]) { |
18472
de179c27cad3
Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents:
18471
diff
changeset
|
98 Object element = ((Object[]) a)[index]; |
23384
f102ee538647
Remove stable constant handling from ConstantReflectionProvider (JDK-8156552).
Roland Schatz <roland.schatz@oracle.com>
parents:
23325
diff
changeset
|
99 return HotSpotObjectConstantImpl.forObject(element); |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
100 } else { |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
101 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
|
102 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
103 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
104 |
18801
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
105 /** |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
106 * 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
|
107 * 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
|
108 * 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
|
109 * |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
110 * @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
|
111 * @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
|
112 */ |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
113 private static boolean isBoxCached(JavaConstant source) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 default: |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
129 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
|
130 } |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
131 } |
95249d5e794f
Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
18686
diff
changeset
|
132 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
133 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
134 public JavaConstant boxPrimitive(JavaConstant source) { |
23393
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
23392
diff
changeset
|
135 if (source == null || !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
|
136 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
137 } |
18262
f7d45e2426d4
converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18223
diff
changeset
|
138 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
|
139 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
140 |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
141 @Override |
18187
9619ba4daf4c
Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents:
18176
diff
changeset
|
142 public JavaConstant unboxPrimitive(JavaConstant source) { |
23393
1d4ce2d19e52
clean up and minimize JVMCI (JDK-8156835)
Doug Simon <doug.simon@oracle.com>
parents:
23392
diff
changeset
|
143 if (source == null || !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
|
144 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
145 } |
18293
ab8fbaa5e72f
fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18290
diff
changeset
|
146 if (source.isNull()) { |
ab8fbaa5e72f
fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18290
diff
changeset
|
147 return null; |
ab8fbaa5e72f
fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18290
diff
changeset
|
148 } |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
149 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
|
150 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
151 |
18295
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
152 public JavaConstant forString(String value) { |
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
153 return HotSpotObjectConstantImpl.forObject(value); |
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
154 } |
17bf458cf86e
reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents:
18293
diff
changeset
|
155 |
22645
c33f0cb02b34
Add ConstantReflectionProvider.forObject method and make HotSpotObjectConstantImpl package-private.
Roland Schatz <roland.schatz@oracle.com>
parents:
22590
diff
changeset
|
156 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
|
157 return HotSpotObjectConstantImpl.forObject(value); |
c33f0cb02b34
Add ConstantReflectionProvider.forObject method and make HotSpotObjectConstantImpl package-private.
Roland Schatz <roland.schatz@oracle.com>
parents:
22590
diff
changeset
|
158 } |
c33f0cb02b34
Add ConstantReflectionProvider.forObject method and make HotSpotObjectConstantImpl package-private.
Roland Schatz <roland.schatz@oracle.com>
parents:
22590
diff
changeset
|
159 |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
160 @Override |
18487
0f4813e0b4a9
Use asConstant() instead of asJavaConstant() where possible.
Roland Schatz <roland.schatz@oracle.com>
parents:
18482
diff
changeset
|
161 public ResolvedJavaType asJavaType(Constant constant) { |
15909
e43591136d9f
Support for compressed constants.
Roland Schatz <roland.schatz@oracle.com>
parents:
15291
diff
changeset
|
162 if (constant instanceof HotSpotObjectConstant) { |
18290
e7d219e9d01f
removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents:
18266
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 } |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
167 } |
16183
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
168 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
|
169 MetaspaceWrapperObject obj = HotSpotMetaspaceConstantImpl.getMetaspaceObject(constant); |
18223
17c98fad6980
converted HotSpotResolvedObjectType to an interface
Doug Simon <doug.simon@oracle.com>
parents:
18188
diff
changeset
|
170 if (obj instanceof HotSpotResolvedObjectTypeImpl) { |
16183
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
171 return (ResolvedJavaType) obj; |
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
172 } |
b1be2a46cc5c
canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15909
diff
changeset
|
173 } |
15018
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
174 return null; |
db4254246f9a
Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13488
diff
changeset
|
175 } |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
176 |
22757
f4c4cc22a31c
tightened signature of ConstantReflectionProvider methods for reading fields
Doug Simon <doug.simon@oracle.com>
parents:
22672
diff
changeset
|
177 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
|
178 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field; |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
179 if (hotspotField.isStatic()) { |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
180 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
|
181 if (holder.isInitialized()) { |
22536
dc1aeef79e7e
Refactoring: Rename Kind to JavaKind.
Roland Schatz <roland.schatz@oracle.com>
parents:
22054
diff
changeset
|
182 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
|
183 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
184 } else { |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
185 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
|
186 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
|
187 } |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
188 } |
21377
6f2ff1bccbf1
Adhere to specification described in JavaDoc of interface
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21290
diff
changeset
|
189 return null; |
18465
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
190 } |
f0a8b72315c1
Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents:
18362
diff
changeset
|
191 |
23290
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
192 @Override |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
193 public JavaConstant asJavaClass(ResolvedJavaType type) { |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
194 return HotSpotObjectConstantImpl.forObject(((HotSpotResolvedJavaType) type).mirror()); |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
195 } |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
196 |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
197 @Override |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
198 public Constant asObjectHub(ResolvedJavaType type) { |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
199 if (type instanceof HotSpotResolvedObjectType) { |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
200 return ((HotSpotResolvedObjectType) type).klass(); |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
201 } else { |
23392
b3a816d3b844
Backed out changeset: a920338dd4d4
Doug Simon <doug.simon@oracle.com>
parents:
23387
diff
changeset
|
202 throw JVMCIError.unimplemented(); |
23290
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
203 } |
87394b31a42e
Move lookup of Java class and hub from ResolvedJavaType to ConstantReflectionProvider
Christian Wimmer <christian.wimmer@oracle.com>
parents:
22760
diff
changeset
|
204 } |
12429
5124eeec1a7b
split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
205 } |