annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantReflectionProvider.java @ 18801:95249d5e794f

Only embed boxed primitives when the box is cached by the JDK Contributed-by: Igor Veresov <igor.veresov@oracle.com>
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Thu, 08 Jan 2015 17:59:19 -0800
parents 3f15de59df5e
children 7f4cb7587f4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
18176
c2270ad35f57 Better construction of data section and data patches.
Roland Schatz <roland.schatz@oracle.com>
parents: 16183
diff changeset
2 * Copyright (c) 2011, 2014, 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 */
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot.meta;
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
25 import static com.oracle.graal.compiler.common.GraalOptions.*;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
26 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import java.lang.reflect.*;
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
29 import java.util.*;
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 import com.oracle.graal.api.meta.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 15053
diff changeset
32 import com.oracle.graal.compiler.common.*;
18340
a0381103324b More folding of constant classes and NodeClass references
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18295
diff changeset
33 import com.oracle.graal.graph.*;
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.hotspot.*;
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
35 import com.oracle.graal.options.*;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
36 import com.oracle.graal.replacements.*;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
37 import com.oracle.graal.replacements.ReplacementsImpl.FrameStateProcessing;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
38 import com.oracle.graal.replacements.Snippet.SnippetInliningPolicy;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
39 import com.oracle.graal.replacements.SnippetTemplate.Arguments;
12429
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 /**
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 * HotSpot implementation of {@link ConstantReflectionProvider}.
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 */
18530
2906b3cc3e2f moved application of Remote marker interface to implementation classes only
Doug Simon <doug.simon@oracle.com>
parents: 18524
diff changeset
44 public class HotSpotConstantReflectionProvider implements ConstantReflectionProvider, Remote {
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
45 private static final String SystemClassName = "Ljava/lang/System;";
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46
18524
c538c2c6b7e2 changed most references to HotSpotGraalRuntime to use HotSpotGraalRuntimeProvider instead
Doug Simon <doug.simon@oracle.com>
parents: 18507
diff changeset
47 protected final HotSpotGraalRuntimeProvider runtime;
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
48 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
49 protected final HotSpotMemoryAccessProviderImpl memoryAccess;
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50
18524
c538c2c6b7e2 changed most references to HotSpotGraalRuntime to use HotSpotGraalRuntimeProvider instead
Doug Simon <doug.simon@oracle.com>
parents: 18507
diff changeset
51 public HotSpotConstantReflectionProvider(HotSpotGraalRuntimeProvider runtime) {
12431
7080a96be216 rename: graalRuntime -> runtime, getGraalRuntime -> getRuntime
Doug Simon <doug.simon@oracle.com>
parents: 12429
diff changeset
52 this.runtime = runtime;
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
53 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
54 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
55 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
56
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
57 public MethodHandleAccessProvider getMethodHandleAccess() {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
58 return methodHandleAccess;
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 }
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 @Override
18482
b8a622c3e99f Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 18472
diff changeset
62 public MemoryAccessProvider getMemoryAccessProvider() {
b8a622c3e99f Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 18472
diff changeset
63 return memoryAccess;
b8a622c3e99f Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 18472
diff changeset
64 }
b8a622c3e99f Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 18472
diff changeset
65
b8a622c3e99f Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 18472
diff changeset
66 @Override
18188
8652481a1110 Introduce new Constant interface for use in high-level graph.
Roland Schatz <roland.schatz@oracle.com>
parents: 18187
diff changeset
67 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
68 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
69 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
70 } 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
71 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
72 } else {
7b60f8334af0 Compare compressed flag in HotSpotObjectConstantImpl#equals and reference equality in HotSpotConstantReflectionProvider#constantEquals
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
73 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
74 }
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 }
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 @Override
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18176
diff changeset
78 public Integer readArrayLength(JavaConstant array) {
18262
f7d45e2426d4 converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18223
diff changeset
79 if (array.getKind() != Kind.Object || array.isNull()) {
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 return null;
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 }
18262
f7d45e2426d4 converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18223
diff changeset
82
18290
e7d219e9d01f removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents: 18266
diff changeset
83 Object arrayObject = ((HotSpotObjectConstantImpl) array).object();
18262
f7d45e2426d4 converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18223
diff changeset
84 if (!arrayObject.getClass().isArray()) {
f7d45e2426d4 converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18223
diff changeset
85 return null;
f7d45e2426d4 converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18223
diff changeset
86 }
f7d45e2426d4 converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18223
diff changeset
87 return Array.getLength(arrayObject);
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88 }
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89
18472
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
90 public JavaConstant readConstantArrayElement(JavaConstant array, int index) {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
91 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
92 JavaConstant element = readArrayElement(array, index);
18505
3356ea593672 Add missing null check in readConstantArrayElement
Andreas Woess <andreas.woess@jku.at>
parents: 18487
diff changeset
93 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
94 return element;
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
95 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
96 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
97 return null;
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
98 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
99
15023
652564fe42d5 Use CompressionNode for accessing compressed Klass pointers.
Roland Schatz <roland.schatz@oracle.com>
parents: 15018
diff changeset
100 @Override
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18176
diff changeset
101 public JavaConstant readArrayElement(JavaConstant array, int 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 if (array.getKind() != Kind.Object || array.isNull()) {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
103 return null;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
104 }
18290
e7d219e9d01f removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents: 18266
diff changeset
105 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
106
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
107 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
108 return null;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
109 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
110
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
111 if (a instanceof Object[]) {
18472
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
112 Object element = ((Object[]) a)[index];
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
113 if (((HotSpotObjectConstantImpl) array).getStableDimension() > 1) {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
114 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
115 } else {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
116 return HotSpotObjectConstantImpl.forObject(element);
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
117 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
118 } else {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18176
diff changeset
119 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
120 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
121 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
122
18801
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
123 /**
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
124 * 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
125 * 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
126 * 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
127 *
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
128 * @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
129 * @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
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 private static boolean isBoxCached(JavaConstant source) {
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
132 switch (source.getKind()) {
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144 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
145 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
146 default:
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
147 throw new IllegalArgumentException("unexpected kind " + source.getKind());
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
148 }
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
149 }
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
150
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
151 @Override
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18176
diff changeset
152 public JavaConstant boxPrimitive(JavaConstant source) {
18801
95249d5e794f Only embed boxed primitives when the box is cached by the JDK
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18686
diff changeset
153 if (!source.getKind().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
154 return null;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
155 }
18262
f7d45e2426d4 converted HotSpotObjectConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18223
diff changeset
156 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
157 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
158
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
159 @Override
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18176
diff changeset
160 public JavaConstant unboxPrimitive(JavaConstant source) {
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
161 if (!source.getKind().isObject()) {
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
162 return null;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
163 }
18293
ab8fbaa5e72f fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents: 18290
diff changeset
164 if (source.isNull()) {
ab8fbaa5e72f fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents: 18290
diff changeset
165 return null;
ab8fbaa5e72f fixed minor regressions after removing HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents: 18290
diff changeset
166 }
18290
e7d219e9d01f removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents: 18266
diff changeset
167 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
168 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
169
18295
17bf458cf86e reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents: 18293
diff changeset
170 public JavaConstant forString(String value) {
17bf458cf86e reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents: 18293
diff changeset
171 return HotSpotObjectConstantImpl.forObject(value);
17bf458cf86e reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents: 18293
diff changeset
172 }
17bf458cf86e reduced use of HotSpotObjectConstantImpl.forObject
Doug Simon <doug.simon@oracle.com>
parents: 18293
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 @Override
18487
0f4813e0b4a9 Use asConstant() instead of asJavaConstant() where possible.
Roland Schatz <roland.schatz@oracle.com>
parents: 18482
diff changeset
175 public ResolvedJavaType asJavaType(Constant constant) {
15909
e43591136d9f Support for compressed constants.
Roland Schatz <roland.schatz@oracle.com>
parents: 15291
diff changeset
176 if (constant instanceof HotSpotObjectConstant) {
18290
e7d219e9d01f removed HotSpotObjectConstantImpl.asObject()
Doug Simon <doug.simon@oracle.com>
parents: 18266
diff changeset
177 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
178 if (obj instanceof Class) {
15040
288c23143d47 Fix most raw type references.
Josef Eisl <josef.eisl@jku.at>
parents: 15023
diff changeset
179 return runtime.getHostProviders().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
180 }
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
181 }
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15909
diff changeset
182 if (constant instanceof HotSpotMetaspaceConstant) {
18266
ae181ec869c5 converted HotSpotMetaspaceConstant to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18262
diff changeset
183 Object obj = HotSpotMetaspaceConstantImpl.getMetaspaceObject(constant);
18223
17c98fad6980 converted HotSpotResolvedObjectType to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18188
diff changeset
184 if (obj instanceof HotSpotResolvedObjectTypeImpl) {
16183
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15909
diff changeset
185 return (ResolvedJavaType) obj;
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15909
diff changeset
186 }
b1be2a46cc5c canonicalize LoadMethodNodes
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15909
diff changeset
187 }
15018
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
188 return null;
db4254246f9a Remove Constant.forObject and Constant.asObject to improve compiler/VM separation
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13488
diff changeset
189 }
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 /**
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
192 * {@inheritDoc}
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
193 * <p>
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
194 * The {@code value} field in {@link OptionValue} is considered constant if the type of
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
195 * {@code receiver} is (assignable to) {@link StableOptionValue}.
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
196 */
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
197 public JavaConstant readConstantFieldValue(JavaField field, JavaConstant receiver) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
198 assert !ImmutableCode.getValue() || isCalledForSnippets() : receiver;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
199 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
200
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
201 if (receiver == null) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
202 assert hotspotField.isStatic();
18507
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18505
diff changeset
203 if (hotspotField.isFinal() || hotspotField.isStable()) {
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
204 ResolvedJavaType holder = hotspotField.getDeclaringClass();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
205 if (holder.isInitialized() && !holder.getName().equals(SystemClassName) && isEmbeddable(hotspotField)) {
18507
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18505
diff changeset
206 JavaConstant value = readFieldValue(field, receiver);
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18505
diff changeset
207 if (hotspotField.isFinal() || !value.isDefaultForKind()) {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18505
diff changeset
208 return value;
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18505
diff changeset
209 }
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
210 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
211 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
212 } else {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
213 /*
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
214 * 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
215 * 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
216 */
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
217 assert !hotspotField.isStatic();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
218 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
219
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
220 // 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
221 // 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
222 // 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
223 if (object != null) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
224 if (hotspotField.isFinal()) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
225 if (hotspotField.isInObject(object)) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
226 JavaConstant value = readFieldValue(field, receiver);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
227 if (!value.isDefaultForKind() || assumeNonStaticFinalDefaultFieldsAsFinal(object.getClass())) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
228 return value;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
229 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
230 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
231 } else if (hotspotField.isStable()) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
232 if (hotspotField.isInObject(object)) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
233 JavaConstant value = readFieldValue(field, receiver);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
234 if (assumeDefaultStableFieldsAsFinal(object.getClass()) || !value.isDefaultForKind()) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
235 return value;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
236 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
237 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
238 } else {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
239 Class<?> clazz = object.getClass();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
240 if (StableOptionValue.class.isAssignableFrom(clazz)) {
18686
3f15de59df5e Support multiple fields in StableOptionValue
Christian Wimmer <christian.wimmer@oracle.com>
parents: 18564
diff changeset
241 if (hotspotField.isInObject(object) && hotspotField.getName().equals("value")) {
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
242 StableOptionValue<?> option = (StableOptionValue<?>) object;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
243 return HotSpotObjectConstantImpl.forObject(option.getValue());
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
244 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
245 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
246 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
247 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
248 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
249 return null;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
250 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
251
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
252 public JavaConstant readFieldValue(JavaField field, JavaConstant receiver) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
253 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field;
18472
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
254 if (!hotspotField.isStable()) {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
255 return readNonStableFieldValue(field, receiver);
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
256 } else {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
257 return readStableFieldValue(field, receiver, false);
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
258 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
259 }
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
260
18472
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
261 private JavaConstant readNonStableFieldValue(JavaField field, JavaConstant receiver) {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
262 HotSpotResolvedJavaField hotspotField = (HotSpotResolvedJavaField) field;
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
263 if (receiver == null) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
264 assert hotspotField.isStatic();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
265 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
266 if (holder.isInitialized()) {
18482
b8a622c3e99f Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 18472
diff changeset
267 return memoryAccess.readUnsafeConstant(hotspotField.getKind(), 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
268 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
269 return null;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
270 } else {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
271 assert !hotspotField.isStatic();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
272 assert receiver.isNonNull() && hotspotField.isInObject(((HotSpotObjectConstantImpl) receiver).object());
18482
b8a622c3e99f Move raw memory access operations to a separate interface.
Roland Schatz <roland.schatz@oracle.com>
parents: 18472
diff changeset
273 return memoryAccess.readUnsafeConstant(hotspotField.getKind(), receiver, hotspotField.offset());
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
274 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
275 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
276
18472
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
277 public JavaConstant readStableFieldValue(JavaField field, JavaConstant receiver, boolean isDefaultStable) {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
278 JavaConstant fieldValue = readNonStableFieldValue(field, receiver);
18564
966081b8e830 guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents: 18530
diff changeset
279 if (fieldValue.isNonNull()) {
966081b8e830 guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents: 18530
diff changeset
280 JavaType declaredType = field.getType();
966081b8e830 guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents: 18530
diff changeset
281 if (declaredType.getComponentType() != null) {
966081b8e830 guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents: 18530
diff changeset
282 int stableDimension = getArrayDimension(declaredType);
966081b8e830 guard against null element in HotSpotConstantReflectionProvider.readStableFieldValue
Doug Simon <doug.simon@oracle.com>
parents: 18530
diff changeset
283 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
284 }
18472
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
285 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
286 return fieldValue;
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
287 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
288
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
289 private static int getArrayDimension(JavaType type) {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
290 int dimensions = 0;
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
291 JavaType componentType = type;
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
292 while ((componentType = componentType.getComponentType()) != null) {
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
293 dimensions++;
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
294 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
295 return dimensions;
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
296 }
de179c27cad3 Add support for stable array constants
Andreas Woess <andreas.woess@jku.at>
parents: 18471
diff changeset
297
18465
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
298 /**
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
299 * Compares two {@link StackTraceElement}s for equality, ignoring differences in
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
300 * {@linkplain StackTraceElement#getLineNumber() line number}.
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
301 */
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
302 private static boolean equalsIgnoringLine(StackTraceElement left, StackTraceElement right) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
303 return left.getClassName().equals(right.getClassName()) && left.getMethodName().equals(right.getMethodName()) && left.getFileName().equals(right.getFileName());
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
304 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
305
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
306 /**
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
307 * If the compiler is configured for AOT mode,
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
308 * {@link #readConstantFieldValue(JavaField, JavaConstant)} should be only called for snippets
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
309 * or replacements.
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 private static boolean isCalledForSnippets() {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
312 MetaAccessProvider metaAccess = runtime().getHostProviders().getMetaAccess();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
313 ResolvedJavaMethod makeGraphMethod = null;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
314 ResolvedJavaMethod initMethod = null;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
315 try {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
316 Class<?> rjm = ResolvedJavaMethod.class;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
317 makeGraphMethod = metaAccess.lookupJavaMethod(ReplacementsImpl.class.getDeclaredMethod("makeGraph", rjm, rjm, SnippetInliningPolicy.class, FrameStateProcessing.class));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
318 initMethod = metaAccess.lookupJavaMethod(SnippetTemplate.AbstractTemplates.class.getDeclaredMethod("template", Arguments.class));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
319 } catch (NoSuchMethodException | SecurityException e) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
320 throw new GraalInternalError(e);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
321 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
322 StackTraceElement makeGraphSTE = makeGraphMethod.asStackTraceElement(0);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
323 StackTraceElement initSTE = initMethod.asStackTraceElement(0);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
324
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
325 StackTraceElement[] stackTrace = new Exception().getStackTrace();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
326 for (StackTraceElement element : stackTrace) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
327 // Ignoring line numbers should not weaken this check too much while at
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
328 // the same time making it more robust against source code changes
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
329 if (equalsIgnoringLine(makeGraphSTE, element) || equalsIgnoringLine(initSTE, element)) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
330 return true;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
331 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
332 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
333 return false;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
334 }
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 private static boolean assumeNonStaticFinalDefaultFieldsAsFinal(Class<?> clazz) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
337 if (TrustFinalDefaultFields.getValue()) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
338 return true;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
339 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
340 return clazz == SnippetCounter.class || clazz == NodeClass.class;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
341 }
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 /**
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
344 * Usually {@link Stable} fields are not considered constant if the value is the
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
345 * {@link JavaConstant#isDefaultForKind default value}. For some special classes we want to
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
346 * override this behavior.
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
347 */
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
348 private static boolean assumeDefaultStableFieldsAsFinal(Class<?> clazz) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
349 // HotSpotVMConfig has a lot of zero-value fields which we know are stable and want to be
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
350 // considered as constants.
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
351 if (clazz == HotSpotVMConfig.class) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
352 return true;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
353 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
354 return false;
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
355 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
356
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
357 /**
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
358 * in AOT mode, some fields should never be embedded even for snippets/replacements.
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
359 */
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
360 private static boolean isEmbeddable(HotSpotResolvedJavaField field) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
361 return Embeddable.test(field);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
362 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
363
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
364 /**
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
365 * Separate out the static initialization to eliminate cycles between clinit and other locks
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
366 * that could lead to deadlock. Static code that doesn't call back into type or field machinery
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
367 * is probably ok but anything else should be made lazy.
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
368 */
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
369 static class Embeddable {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
370
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
371 /**
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
372 * @return Return true if it's ok to embed the value of {@code field}.
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
373 */
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
374 public static boolean test(HotSpotResolvedJavaField field) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
375 return !ImmutableCode.getValue() || !fields.contains(field);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
376 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
377
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
378 private static final List<ResolvedJavaField> fields = new ArrayList<>();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
379 static {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
380 try {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
381 MetaAccessProvider metaAccess = runtime().getHostProviders().getMetaAccess();
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
382 fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("TRUE")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
383 fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("FALSE")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
384
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
385 Class<?> characterCacheClass = Character.class.getDeclaredClasses()[0];
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
386 assert "java.lang.Character$CharacterCache".equals(characterCacheClass.getName());
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
387 fields.add(metaAccess.lookupJavaField(characterCacheClass.getDeclaredField("cache")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
388
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
389 Class<?> byteCacheClass = Byte.class.getDeclaredClasses()[0];
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
390 assert "java.lang.Byte$ByteCache".equals(byteCacheClass.getName());
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
391 fields.add(metaAccess.lookupJavaField(byteCacheClass.getDeclaredField("cache")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
392
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
393 Class<?> shortCacheClass = Short.class.getDeclaredClasses()[0];
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
394 assert "java.lang.Short$ShortCache".equals(shortCacheClass.getName());
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
395 fields.add(metaAccess.lookupJavaField(shortCacheClass.getDeclaredField("cache")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
396
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
397 Class<?> integerCacheClass = Integer.class.getDeclaredClasses()[0];
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
398 assert "java.lang.Integer$IntegerCache".equals(integerCacheClass.getName());
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
399 fields.add(metaAccess.lookupJavaField(integerCacheClass.getDeclaredField("cache")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
400
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
401 Class<?> longCacheClass = Long.class.getDeclaredClasses()[0];
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
402 assert "java.lang.Long$LongCache".equals(longCacheClass.getName());
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
403 fields.add(metaAccess.lookupJavaField(longCacheClass.getDeclaredField("cache")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
404
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
405 fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("UNASSIGNED_STACK")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
406 fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("SUPPRESSED_SENTINEL")));
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
407 } catch (SecurityException | NoSuchFieldException e) {
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
408 throw new GraalInternalError(e);
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
409 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
410 }
f0a8b72315c1 Move ResolvedJavaField#read[Constant]Value and getMethodHandleAccess() to ConstantReflectionProvider
Andreas Woess <andreas.woess@jku.at>
parents: 18362
diff changeset
411 }
12429
5124eeec1a7b split HotSpotRuntime into separate provider implementations
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
412 }