use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class HotSpotGraalConstantFieldProvider method isEmbeddableField.
protected boolean isEmbeddableField(ResolvedJavaField field) {
if (nonEmbeddableFields == null) {
synchronized (this) {
if (nonEmbeddableFields == null) {
List<ResolvedJavaField> fields = new ArrayList<>();
try {
fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("TRUE")));
fields.add(metaAccess.lookupJavaField(Boolean.class.getDeclaredField("FALSE")));
Class<?> characterCacheClass = Character.class.getDeclaredClasses()[0];
assert "java.lang.Character$CharacterCache".equals(characterCacheClass.getName());
fields.add(metaAccess.lookupJavaField(characterCacheClass.getDeclaredField("cache")));
Class<?> byteCacheClass = Byte.class.getDeclaredClasses()[0];
assert "java.lang.Byte$ByteCache".equals(byteCacheClass.getName());
fields.add(metaAccess.lookupJavaField(byteCacheClass.getDeclaredField("cache")));
Class<?> shortCacheClass = Short.class.getDeclaredClasses()[0];
assert "java.lang.Short$ShortCache".equals(shortCacheClass.getName());
fields.add(metaAccess.lookupJavaField(shortCacheClass.getDeclaredField("cache")));
Class<?> integerCacheClass = Integer.class.getDeclaredClasses()[0];
assert "java.lang.Integer$IntegerCache".equals(integerCacheClass.getName());
fields.add(metaAccess.lookupJavaField(integerCacheClass.getDeclaredField("cache")));
Class<?> longCacheClass = Long.class.getDeclaredClasses()[0];
assert "java.lang.Long$LongCache".equals(longCacheClass.getName());
fields.add(metaAccess.lookupJavaField(longCacheClass.getDeclaredField("cache")));
fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("UNASSIGNED_STACK")));
fields.add(metaAccess.lookupJavaField(Throwable.class.getDeclaredField("SUPPRESSED_SENTINEL")));
} catch (SecurityException | NoSuchFieldException e) {
throw new GraalError(e);
}
nonEmbeddableFields = fields;
}
}
}
return !nonEmbeddableFields.contains(field);
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class ObjectScanner method unsupportedFeature.
private void unsupportedFeature(String key, String message, Object entry) {
StringBuilder objectBacktrace = new StringBuilder();
Object cur = entry;
AnalysisMethod method = null;
while (cur instanceof WorklistEntry) {
WorklistEntry curEntry = (WorklistEntry) cur;
objectBacktrace.append("\tobject ").append(bb.getMetaAccess().lookupJavaType(curEntry.constant).toJavaName(true)).append(System.lineSeparator());
cur = curEntry.reason;
}
if (cur instanceof ResolvedJavaField) {
objectBacktrace.append("\tfield ").append(((ResolvedJavaField) cur).format("%H.%n"));
} else if (cur instanceof ResolvedJavaMethod) {
objectBacktrace.append("\tmethod ").append(((ResolvedJavaMethod) cur).format("%H.%n(%p)"));
method = (AnalysisMethod) cur;
} else {
objectBacktrace.append("\t[unknown] ").append(cur.toString());
}
bb.getUnsupportedFeatures().addMessage(key, method, message, objectBacktrace.toString());
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class NewInstanceNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
/*
* Reference objects can escape into their ReferenceQueue at any safepoint, therefore
* they're excluded from escape analysis.
*/
if (!tool.getMetaAccessProvider().lookupJavaType(Reference.class).isAssignableFrom(instanceClass)) {
VirtualInstanceNode virtualObject = createVirtualInstanceNode(true);
ResolvedJavaField[] fields = virtualObject.getFields();
ValueNode[] state = new ValueNode[fields.length];
for (int i = 0; i < state.length; i++) {
state[i] = defaultFieldValue(fields[i]);
}
tool.createVirtualObject(virtualObject, state, Collections.<MonitorIdNode>emptyList(), false);
tool.replaceWithVirtual(virtualObject);
}
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class PushNodesThroughPiTest method test1.
@Ignore
@Test
@SuppressWarnings("try")
public void test1() {
final String snippet = "test1Snippet";
DebugContext debug = getDebugContext();
try (DebugContext.Scope s = debug.scope("PushThroughPi", new DebugDumpScope(snippet))) {
StructuredGraph graph = compileTestSnippet(snippet);
for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
long disp = address.getOffset().asJavaConstant().asLong();
ResolvedJavaType receiverType = StampTool.typeOrNull(address.getBase());
ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(disp, rn.getStackKind());
assert field != null : "Node " + rn + " tries to access a field which doesn't exists for this type";
if (field.getName().equals("x")) {
Assert.assertTrue(address.getBase() instanceof ParameterNode);
} else {
Assert.assertTrue(address.getBase().toString(), address.getBase() instanceof PiNode);
}
}
Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
} catch (Throwable e) {
throw debug.handle(e);
}
}
use of jdk.vm.ci.meta.ResolvedJavaField in project graal by oracle.
the class RecomputedFields method compute.
@Override
public Object compute(ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) {
try {
ObjectLayout layout = ImageSingletons.lookup(ObjectLayout.class);
/*
* ASHIFT is a hard-coded constant in the original implementation, so there is no need
* to recompute it. It is a private field, so we need reflection to access it.
*/
Field ashiftField = java.util.concurrent.Exchanger.class.getDeclaredField("ASHIFT");
ashiftField.setAccessible(true);
int ashift = ashiftField.getInt(null);
/*
* The original implementation uses Node[].class, but we know that all Object arrays
* have the same kind and layout. The kind denotes the element type of the array.
*/
JavaKind ak = JavaKind.Object;
// ABASE absorbs padding in front of element 0
int abase = layout.getArrayBaseOffset(ak) + (1 << ashift);
/* Sanity check. */
final int s = layout.getArrayIndexScale(ak);
if ((s & (s - 1)) != 0 || s > (1 << ashift)) {
throw VMError.shouldNotReachHere("Unsupported array scale");
}
return abase;
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException ex) {
throw VMError.shouldNotReachHere(ex);
}
}
Aggregations