comparison graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java @ 10066:295ef03139f4

HotSpotResolvedJavaField: be more precise about fields that are not embeddable (GRAAL-290)
author Bernhard Urban <bernhard.urban@jku.at>
date Sun, 16 Jun 2013 23:55:22 +0200
parents 5ba3763d6986
children 1397c3e1f642
comparison
equal deleted inserted replaced
10065:5ba3763d6986 10066:295ef03139f4
27 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; 27 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
28 import static com.oracle.graal.phases.GraalOptions.*; 28 import static com.oracle.graal.phases.GraalOptions.*;
29 29
30 import java.lang.annotation.*; 30 import java.lang.annotation.*;
31 import java.lang.reflect.*; 31 import java.lang.reflect.*;
32 import java.util.*;
32 33
33 import com.oracle.graal.api.meta.*; 34 import com.oracle.graal.api.meta.*;
34 import com.oracle.graal.graph.*; 35 import com.oracle.graal.graph.*;
35 import com.oracle.graal.hotspot.*; 36 import com.oracle.graal.hotspot.*;
36 import com.oracle.graal.options.*; 37 import com.oracle.graal.options.*;
104 } 105 }
105 } 106 }
106 return false; 107 return false;
107 } 108 }
108 109
110 private static final Set<ResolvedJavaField> notEmbeddable = new HashSet<>();
111
112 private static void addResolvedToSet(Field field) {
113 HotSpotRuntime runtime = graalRuntime().getRuntime();
114 notEmbeddable.add(runtime.lookupJavaField(field));
115 }
116
117 static {
118 try {
119 addResolvedToSet(Boolean.class.getDeclaredField("TRUE"));
120 addResolvedToSet(Boolean.class.getDeclaredField("FALSE"));
121
122 Class<?> integerCacheClass = Integer.class.getDeclaredClasses()[0];
123 assert "java.lang.Integer$IntegerCache".equals(integerCacheClass.getName());
124 addResolvedToSet(integerCacheClass.getDeclaredField("cache"));
125
126 Class<?> longCacheClass = Long.class.getDeclaredClasses()[0];
127 assert "java.lang.Long$LongCache".equals(longCacheClass.getName());
128 addResolvedToSet(longCacheClass.getDeclaredField("cache"));
129
130 addResolvedToSet(Throwable.class.getDeclaredField("UNASSIGNED_STACK"));
131 addResolvedToSet(Throwable.class.getDeclaredField("SUPPRESSED_SENTINEL"));
132 } catch (SecurityException | NoSuchFieldException e) {
133 throw new GraalInternalError(e);
134 }
135 }
136
137 /**
138 * in AOT mode, some fields should never be embedded even for snippets/replacements.
139 */
140 private boolean isEmbeddable() {
141 if (AOTCompilation.getValue() && notEmbeddable.contains(this)) {
142 return false;
143 }
144 return true;
145 }
146
109 private static final String SystemClassName = MetaUtil.toInternalName(System.class.getName()); 147 private static final String SystemClassName = MetaUtil.toInternalName(System.class.getName());
110 private static final String IntegerCacheClassName = "Ljava/lang/Integer$IntegerCache;";
111 private static final String LongCacheClassName = "Ljava/lang/Long$LongCache;";
112 private static final String BooleanCacheName = MetaUtil.toInternalName(Boolean.class.getName());
113 private static final String ThrowableClassName = MetaUtil.toInternalName(Throwable.class.getName());
114
115 private boolean isConstantCache() {
116 if (AOTCompilation.getValue()) {
117 String n = holder.getName();
118 return n.equals(IntegerCacheClassName) || n.equals(LongCacheClassName) || n.equals(BooleanCacheName) || n.equals(ThrowableClassName);
119 }
120 return false;
121 }
122 148
123 @Override 149 @Override
124 public Constant readConstantValue(Constant receiver) { 150 public Constant readConstantValue(Constant receiver) {
125 assert !AOTCompilation.getValue() || isCalledForSnippets(); 151 assert !AOTCompilation.getValue() || isCalledForSnippets();
126 152
127 if (receiver == null) { 153 if (receiver == null) {
128 assert Modifier.isStatic(flags); 154 assert Modifier.isStatic(flags);
129 if (constant == null) { 155 if (constant == null) {
130 if (holder.isInitialized() && !holder.getName().equals(SystemClassName) && !isConstantCache()) { 156 if (holder.isInitialized() && !holder.getName().equals(SystemClassName) && isEmbeddable()) {
131 if (Modifier.isFinal(getModifiers())) { 157 if (Modifier.isFinal(getModifiers())) {
132 constant = readValue(receiver); 158 constant = readValue(receiver);
133 } 159 }
134 } 160 }
135 } 161 }