Mercurial > hg > graal-compiler
changeset 7096:585fc9f79ebc
Remove ResolvedJavaType.isClass()
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/NameAndSignature.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/NameAndSignature.java Thu Nov 29 09:13:59 2012 -0800 @@ -26,8 +26,12 @@ import java.util.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.api.runtime.*; class NameAndSignature { + + public static final MetaAccessProvider runtime = Graal.getRequiredCapability(MetaAccessProvider.class); + final String name; final Class returnType; final Class[] parameterTypes; @@ -67,14 +71,14 @@ public boolean signatureEquals(ResolvedJavaMethod m) { Signature s = m.getSignature(); ResolvedJavaType declaringClass = m.getDeclaringClass(); - if (!s.getReturnType(declaringClass).resolve(declaringClass).isClass(returnType)) { + if (!s.getReturnType(declaringClass).resolve(declaringClass).equals(runtime.lookupJavaType(returnType))) { return false; } if (s.getParameterCount(false) != parameterTypes.length) { return false; } for (int i = 0; i < parameterTypes.length; i++) { - if (!s.getParameterType(i, declaringClass).resolve(declaringClass).isClass(parameterTypes[i])) { + if (!s.getParameterType(i, declaringClass).resolve(declaringClass).equals(runtime.lookupJavaType(parameterTypes[i]))) { return false; } }
--- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaMethod.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestJavaMethod.java Thu Nov 29 09:13:59 2012 -0800 @@ -68,7 +68,7 @@ for (Map.Entry<Method, ResolvedJavaMethod> e : methods.entrySet()) { Class expected = e.getKey().getDeclaringClass(); ResolvedJavaType actual = e.getValue().getDeclaringClass(); - assertTrue(actual.isClass(expected)); + assertTrue(actual.equals(runtime.lookupJavaType(expected))); } }
--- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestMetaAccessProvider.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestMetaAccessProvider.java Thu Nov 29 09:13:59 2012 -0800 @@ -184,7 +184,6 @@ for (Class c : classes) { ResolvedJavaType type = runtime.lookupJavaType(c); assertNotNull(type); - assertTrue(type.isClass(c)); assertEquals(c.getModifiers(), type.getModifiers()); if (!type.isArray()) { assertEquals(type.getName(), toInternalName(c.getName())); @@ -202,7 +201,7 @@ int expected = reflect.getModifiers() & Modifier.methodModifiers(); int actual = method.getModifiers(); assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); - assertTrue(method.getDeclaringClass().isClass(reflect.getDeclaringClass())); + assertTrue(method.getDeclaringClass().equals(runtime.lookupJavaType(reflect.getDeclaringClass()))); } } } @@ -216,7 +215,7 @@ int expected = reflect.getModifiers() & Modifier.fieldModifiers(); int actual = field.getModifiers(); assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); - assertTrue(field.getDeclaringClass().isClass(reflect.getDeclaringClass())); + assertTrue(field.getDeclaringClass().equals(runtime.lookupJavaType(reflect.getDeclaringClass()))); } } } @@ -228,7 +227,7 @@ Object o = c.asObject(); ResolvedJavaType type = runtime.lookupJavaType(c); assertNotNull(type); - assertTrue(type.isClass(o.getClass())); + assertTrue(type.equals(runtime.lookupJavaType(o.getClass()))); } else { assertEquals(runtime.lookupJavaType(c), null); }
--- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaType.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaType.java Thu Nov 29 09:13:59 2012 -0800 @@ -160,7 +160,7 @@ assertTrue("exact(" + c.getName() + ") != null", exactType == null); } else { assertNotNull(exactType); - assertTrue(exactType.isClass(expected)); + assertTrue(exactType.equals(runtime.lookupJavaType(expected))); } } } @@ -175,7 +175,7 @@ assertTrue(actual == null); } else { assertNotNull(actual); - assertTrue(actual.isClass(expected)); + assertTrue(actual.equals(runtime.lookupJavaType(expected))); } } } @@ -188,7 +188,7 @@ ResolvedJavaType[] actual = type.getInterfaces(); assertEquals(expected.length, actual.length); for (int i = 0; i < expected.length; i++) { - assertTrue(actual[i].isClass(expected[i])); + assertTrue(actual[i].equals(runtime.lookupJavaType(expected[i]))); } } } @@ -242,7 +242,7 @@ assertTrue(actual == null); } else { assertNotNull(actual); - assertTrue(actual.isClass(expected)); + assertTrue(actual.equals(runtime.lookupJavaType(expected))); } } } @@ -264,7 +264,7 @@ if (expected == null) { assertNull(subtype); } else { - assertTrue(subtype.isClass(expected)); + assertTrue(subtype.equals(runtime.lookupJavaType(expected))); } } @@ -318,7 +318,7 @@ if (expected == null) { assertNull(actual); } else { - assertTrue(actual.isClass(expected)); + assertTrue(actual.equals(runtime.lookupJavaType(expected))); } } } @@ -330,7 +330,7 @@ ResolvedJavaType type = runtime.lookupJavaType(c); Class expected = getArrayClass(c); ResolvedJavaType actual = type.getArrayClass(); - assertTrue(actual.isClass(expected)); + assertTrue(actual.equals(runtime.lookupJavaType(expected))); } } } @@ -459,9 +459,9 @@ } public static boolean fieldsEqual(Field f, ResolvedJavaField rjf) { - return rjf.getDeclaringClass().isClass(f.getDeclaringClass()) && + return rjf.getDeclaringClass().equals(runtime.lookupJavaType(f.getDeclaringClass())) && rjf.getName().equals(f.getName()) && - rjf.getType().resolve(rjf.getDeclaringClass()).isClass(f.getType()); + rjf.getType().resolve(rjf.getDeclaringClass()).equals(runtime.lookupJavaType(f.getType())); } public static ResolvedJavaField lookupField(ResolvedJavaField[] fields, Field key) { @@ -485,10 +485,10 @@ } private static boolean isHiddenFromReflection(ResolvedJavaField f) { - if (f.getDeclaringClass().isClass(Throwable.class) && f.getName().equals("backtrace")) { + if (f.getDeclaringClass().equals(runtime.lookupJavaType(Throwable.class)) && f.getName().equals("backtrace")) { return true; } - if (f.getDeclaringClass().isClass(ConstantPool.class) && f.getName().equals("constantPoolOop")) { + if (f.getDeclaringClass().equals(runtime.lookupJavaType(ConstantPool.class)) && f.getName().equals("constantPoolOop")) { return true; } return false;
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MetaUtil.java Thu Nov 29 09:13:59 2012 -0800 @@ -37,6 +37,15 @@ public class MetaUtil { /** + * Returns true if the specified typed is exactly the type {@link java.lang.Object}. + */ + public static boolean isJavaLangObject(ResolvedJavaType type) { + boolean result = type.getSuperclass() == null && !type.isInterface() && type.getKind() == Kind.Object; + assert result == type.getName().equals("Ljava/lang/Object;") : type.getName(); + return result; + } + + /** * Gets the {@link Class} mirror for a given resolved type. * * @param type the type for which the Java mirror is requested
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaType.java Thu Nov 29 09:13:59 2012 -0800 @@ -243,11 +243,6 @@ <T extends Annotation> T getAnnotation(Class<T> annotationClass); /** - * Determines if this type is the same as that represented by a given {@link Class}. - */ - boolean isClass(Class c); - - /** * Returns the instance field of this class (or one of its super classes) at the given * offset, or {@code null} if there is no such field. *
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/BoxingEliminationTest.java Thu Nov 29 09:13:59 2012 -0800 @@ -128,7 +128,7 @@ new InliningPhase(null, runtime(), hints, assumptions, null, phasePlan, OptimisticOptimizations.ALL).apply(graph); new CanonicalizerPhase(null, runtime(), assumptions).apply(graph); Debug.dump(graph, "Graph"); - new BoxingEliminationPhase().apply(graph); + new BoxingEliminationPhase(runtime()).apply(graph); Debug.dump(graph, "Graph"); new ExpandBoxingNodesPhase(pool).apply(graph); new CanonicalizerPhase(null, runtime(), assumptions).apply(graph);
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfBoxingEliminationTest.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/IfBoxingEliminationTest.java Thu Nov 29 09:13:59 2012 -0800 @@ -93,7 +93,7 @@ new PhiStampPhase().apply(graph); new CanonicalizerPhase(null, runtime(), assumptions).apply(graph); Debug.dump(graph, "Graph"); - new BoxingEliminationPhase().apply(graph); + new BoxingEliminationPhase(runtime()).apply(graph); Debug.dump(graph, "Graph"); new ExpandBoxingNodesPhase(pool).apply(graph); new CanonicalizerPhase(null, runtime(), assumptions).apply(graph);
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java Thu Nov 29 09:13:59 2012 -0800 @@ -438,11 +438,6 @@ } @Override - public boolean isClass(Class c) { - return c == javaMirror; - } - - @Override public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { return javaMirror.getAnnotation(annotationClass); }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedPrimitiveType.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedPrimitiveType.java Thu Nov 29 09:13:59 2012 -0800 @@ -167,11 +167,6 @@ } @Override - public boolean isClass(Class c) { - return c == javaMirror; - } - - @Override public ResolvedJavaType resolve(ResolvedJavaType accessingClass) { return this; }
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Thu Nov 29 09:13:59 2012 -0800 @@ -460,7 +460,7 @@ ValueNode expected = cas.expected(); if (expected.kind() == Kind.Object && !cas.newValue().objectStamp().alwaysNull()) { ResolvedJavaType type = cas.object().objectStamp().type(); - if (type != null && !type.isArray() && !type.isClass(Object.class)) { + if (type != null && !type.isArray() && !MetaUtil.isJavaLangObject(type)) { // Use a field write barrier since it's not an array store FieldWriteBarrier writeBarrier = graph.add(new FieldWriteBarrier(cas.object())); graph.addAfterFixed(cas, writeBarrier); @@ -491,7 +491,7 @@ ResolvedJavaType arrayType = array.objectStamp().type(); if (arrayType != null && array.objectStamp().isExactType()) { ResolvedJavaType elementType = arrayType.getComponentType(); - if (!elementType.isClass(Object.class)) { + if (!MetaUtil.isJavaLangObject(elementType)) { CheckCastNode checkcast = graph.add(new CheckCastNode(elementType, value, null)); graph.addBeforeFixed(storeIndexed, checkcast); value = checkcast; @@ -533,7 +533,7 @@ if (write.value().kind() == Kind.Object && !write.value().objectStamp().alwaysNull()) { ResolvedJavaType type = object.objectStamp().type(); WriteBarrier writeBarrier; - if (type != null && !type.isArray() && !type.isClass(Object.class)) { + if (type != null && !type.isArray() && !MetaUtil.isJavaLangObject(type)) { // Use a field write barrier since it's not an array store writeBarrier = graph.add(new FieldWriteBarrier(object)); } else { @@ -602,7 +602,7 @@ ResolvedJavaType holder = method.getDeclaringClass(); String fullName = method.getName() + ((HotSpotSignature) method.getSignature()).asString(); Kind wordKind = graalRuntime.getTarget().wordKind; - if (holder.isClass(Object.class)) { + if (MetaUtil.isJavaLangObject(holder)) { if (fullName.equals("getClass()Ljava/lang/Class;")) { ValueNode obj = (ValueNode) parameters.get(0); ObjectStamp stamp = (ObjectStamp) obj.stamp(); @@ -624,7 +624,7 @@ hub.setNext(ret); return graph; } - } else if (holder.isClass(Class.class)) { + } else if (holder.equals(lookupJavaType(Class.class))) { if (fullName.equals("getModifiers()I")) { StructuredGraph graph = new StructuredGraph(); LocalNode receiver = graph.unique(new LocalNode(0, StampFactory.objectNonNull())); @@ -639,7 +639,7 @@ klass.setNext(ret); return graph; } - } else if (holder.isClass(Thread.class)) { + } else if (holder.equals(lookupJavaType(Thread.class))) { if (fullName.equals("currentThread()Ljava/lang/Thread;")) { StructuredGraph graph = new StructuredGraph(); ReturnNode ret = graph.add(new ReturnNode(graph.unique(new CurrentThread(config.threadObjectOffset, this))));
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Thu Nov 29 09:13:59 2012 -0800 @@ -762,7 +762,7 @@ while (stream.currentBCI() <= block.endBci) { switch (stream.currentBC()) { case RETURN: - if (method.isConstructor() && method.getDeclaringClass().isClass(Object.class)) { + if (method.isConstructor() && MetaUtil.isJavaLangObject(method.getDeclaringClass())) { // return from Object.init implicitly registers a finalizer // for the receiver if needed, so keep it alive. loadOne(block, 0);
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Nov 29 09:13:59 2012 -0800 @@ -1396,7 +1396,7 @@ } private void createReturn() { - if (method.isConstructor() && method.getDeclaringClass().isClass(Object.class)) { + if (method.isConstructor() && MetaUtil.isJavaLangObject(method.getDeclaringClass())) { callRegisterFinalizer(); } Kind returnKind = method.getSignature().getReturnKind().getStackKind();
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BoxingMethodPool.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/BoxingMethodPool.java Thu Nov 29 09:13:59 2012 -0800 @@ -22,32 +22,11 @@ */ package com.oracle.graal.nodes.extended; -import java.lang.reflect.*; import java.util.*; -import java.util.Map.Entry; import com.oracle.graal.api.meta.*; public class BoxingMethodPool { - private static final Map<Kind, BoxingMethod> boxings = new HashMap<>(); - private static class BoxingMethod { - final Class<?> type; - final String unboxMethod; - public BoxingMethod(Class< ? > type, String unboxMethod) { - this.type = type; - this.unboxMethod = unboxMethod; - } - } - static { - boxings.put(Kind.Boolean, new BoxingMethod(Boolean.class, "booleanValue")); - boxings.put(Kind.Byte, new BoxingMethod(Byte.class, "byteValue")); - boxings.put(Kind.Char, new BoxingMethod(Character.class, "charValue")); - boxings.put(Kind.Short, new BoxingMethod(Short.class, "shortValue")); - boxings.put(Kind.Int, new BoxingMethod(Integer.class, "intValue")); - boxings.put(Kind.Long, new BoxingMethod(Long.class, "longValue")); - boxings.put(Kind.Float, new BoxingMethod(Float.class, "floatValue")); - boxings.put(Kind.Double, new BoxingMethod(Double.class, "doubleValue")); - } private final Set<JavaMethod> specialMethods = new HashSet<>(); private final MetaAccessProvider runtime; @@ -57,25 +36,22 @@ public BoxingMethodPool(MetaAccessProvider runtime) { this.runtime = runtime; - initialize(); - } - private void initialize() { try { - for (Entry<Kind, BoxingMethod> entry : boxings.entrySet()) { - Kind kind = entry.getKey(); - BoxingMethod boxing = entry.getValue(); - initialize(kind, boxing.type, boxing.unboxMethod); - } - } catch (SecurityException e) { - throw new RuntimeException(e); - } catch (NoSuchMethodException e) { + initialize(Kind.Boolean, Boolean.class, "booleanValue"); + initialize(Kind.Byte, Byte.class, "byteValue"); + initialize(Kind.Char, Character.class, "charValue"); + initialize(Kind.Short, Short.class, "shortValue"); + initialize(Kind.Int, Integer.class, "intValue"); + initialize(Kind.Long, Long.class, "longValue"); + initialize(Kind.Float, Float.class, "floatValue"); + initialize(Kind.Double, Double.class, "doubleValue"); + } catch (SecurityException | NoSuchMethodException e) { throw new RuntimeException(e); } } private void initialize(Kind kind, Class<?> type, String unboxMethod) throws SecurityException, NoSuchMethodException { - // Get boxing method from runtime. ResolvedJavaMethod boxingMethod = runtime.lookupJavaMethod(type.getDeclaredMethod("valueOf", kind.toJavaClass())); specialMethods.add(boxingMethod); @@ -116,38 +92,4 @@ public ResolvedJavaField getBoxField(Kind kind) { return boxFields[kind.ordinal()]; } - - public static boolean isSpecialMethodStatic(ResolvedJavaMethod method) { - return isUnboxingMethodStatic(method) || isBoxingMethodStatic(method); - } - - public static boolean isBoxingMethodStatic(ResolvedJavaMethod method) { - Signature signature = method.getSignature(); - if (!Modifier.isStatic(method.getModifiers()) - || signature.getReturnKind() == Kind.Object - || signature.getParameterCount(false) != 1) { - return false; - } - Kind kind = signature.getParameterKind(0); - BoxingMethod boxing = boxings.get(kind); - if (boxing == null) { - return false; - } - return method.getDeclaringClass().isClass(boxing.type) && method.getName().equals("valueOf"); - } - - public static boolean isUnboxingMethodStatic(ResolvedJavaMethod method) { - Signature signature = method.getSignature(); - if (signature.getReturnKind() == Kind.Object - || signature.getParameterCount(false) != 0 - || Modifier.isStatic(method.getModifiers())) { - return false; - } - Kind kind = signature.getReturnKind(); - BoxingMethod boxing = boxings.get(kind); - if (boxing == null) { - return false; - } - return method.getDeclaringClass().isClass(boxing.type) && method.getName().equals(boxing.unboxMethod); - } }
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/BoxingEliminationPhase.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/BoxingEliminationPhase.java Thu Nov 29 09:13:59 2012 -0800 @@ -37,8 +37,13 @@ public class BoxingEliminationPhase extends Phase { + private final MetaAccessProvider metaAccess; private int virtualIds = Integer.MIN_VALUE; + public BoxingEliminationPhase(MetaAccessProvider metaAccess) { + this.metaAccess = metaAccess; + } + @Override protected void run(StructuredGraph graph) { if (graph.getNodes(UnboxNode.class).isNotEmpty()) { @@ -71,7 +76,7 @@ ObjectStamp stamp = phiNode.objectStamp(); if (stamp.nonNull() && stamp.isExactType()) { ResolvedJavaType type = stamp.type(); - if (type != null && type.isClass(kind.toBoxedJavaClass())) { + if (type != null && type.equals(metaAccess.lookupJavaType(kind.toBoxedJavaClass()))) { StructuredGraph graph = (StructuredGraph) phiNode.graph(); result = graph.add(new PhiNode(kind, phiNode.merge())); phiReplacements.put(phiNode, result);
--- a/graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/WordTest.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/WordTest.java Thu Nov 29 09:13:59 2012 -0800 @@ -32,6 +32,8 @@ import com.oracle.graal.compiler.*; import com.oracle.graal.compiler.test.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.snippets.Snippet.DefaultSnippetInliningPolicy; import com.oracle.graal.snippets.Snippet.SnippetInliningPolicy; /** @@ -114,9 +116,10 @@ @Test public void test_fromObject() { - inliningPolicy.set(new SnippetInliningPolicy() { + inliningPolicy.set(new DefaultSnippetInliningPolicy(new BoxingMethodPool(runtime())) { + @Override public boolean shouldInline(ResolvedJavaMethod method, ResolvedJavaMethod caller) { - return SnippetInliningPolicy.Default.shouldInline(method, caller) && !method.getName().equals("hashCode"); + return super.shouldInline(method, caller) && !method.getName().equals("hashCode"); } }); test("fromToObject", "object1", "object2");
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/Snippet.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/Snippet.java Thu Nov 29 09:13:59 2012 -0800 @@ -48,7 +48,7 @@ /** * Specifies the class defining the inlining policy for this snippet. - * A {@linkplain SnippetInliningPolicy#Default default} policy is used if none is supplied. + * A {@linkplain DefaultSnippetInliningPolicy default} policy is used if none is supplied. */ Class<? extends SnippetInliningPolicy> inlining() default SnippetInliningPolicy.class; @@ -60,42 +60,49 @@ * Determines if {@code method} should be inlined into {@code caller}. */ boolean shouldInline(ResolvedJavaMethod method, ResolvedJavaMethod caller); + } - /** - * The default inlining policy which inlines everything except for methods - * in any of the following categories. - * <ul> - * <li>{@linkplain Fold foldable} methods</li> - * <li>{@linkplain NodeIntrinsic node intrinsics}</li> - * <li>native methods</li> - * <li>constructors of {@link Throwable} classes</li> - * </ul> - */ - SnippetInliningPolicy Default = new SnippetInliningPolicy() { - public boolean shouldInline(ResolvedJavaMethod method, ResolvedJavaMethod caller) { - if (Modifier.isNative(method.getModifiers())) { + /** + * The default inlining policy which inlines everything except for methods + * in any of the following categories. + * <ul> + * <li>{@linkplain Fold foldable} methods</li> + * <li>{@linkplain NodeIntrinsic node intrinsics}</li> + * <li>native methods</li> + * <li>constructors of {@link Throwable} classes</li> + * </ul> + */ + public static class DefaultSnippetInliningPolicy implements SnippetInliningPolicy { + private final BoxingMethodPool pool; + + public DefaultSnippetInliningPolicy(BoxingMethodPool pool) { + this.pool = pool; + } + + @Override + public boolean shouldInline(ResolvedJavaMethod method, ResolvedJavaMethod caller) { + if (Modifier.isNative(method.getModifiers())) { + return false; + } + if (method.getAnnotation(Fold.class) != null) { + return false; + } + if (method.getAnnotation(NodeIntrinsic.class) != null) { + return false; + } + if (Throwable.class.isAssignableFrom(getMirrorOrFail(method.getDeclaringClass(), null))) { + if (method.getName().equals("<init>")) { return false; } - if (method.getAnnotation(Fold.class) != null) { - return false; - } - if (method.getAnnotation(NodeIntrinsic.class) != null) { - return false; - } - if (Throwable.class.isAssignableFrom(getMirrorOrFail(method.getDeclaringClass(), null))) { - if (method.getName().equals("<init>")) { - return false; - } - } - if (method.getAnnotation(Operation.class) != null) { - return false; - } - if (BoxingMethodPool.isSpecialMethodStatic(method)) { - return false; - } - return true; + } + if (method.getAnnotation(Operation.class) != null) { + return false; } - }; + if (pool.isSpecialMethod(method)) { + return false; + } + return true; + } } /**
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetInstaller.java Thu Nov 29 09:13:59 2012 -0800 @@ -37,6 +37,7 @@ import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; +import com.oracle.graal.snippets.Snippet.DefaultSnippetInliningPolicy; import com.oracle.graal.snippets.Snippet.SnippetInliningPolicy; /** @@ -122,14 +123,14 @@ } } - private static SnippetInliningPolicy inliningPolicy(ResolvedJavaMethod method) { + private SnippetInliningPolicy inliningPolicy(ResolvedJavaMethod method) { Class<? extends SnippetInliningPolicy> policyClass = SnippetInliningPolicy.class; Snippet snippet = method.getAnnotation(Snippet.class); if (snippet != null) { policyClass = snippet.inlining(); } if (policyClass == SnippetInliningPolicy.class) { - return SnippetInliningPolicy.Default; + return new DefaultSnippetInliningPolicy(pool); } try { return policyClass.getConstructor().newInstance(); @@ -169,7 +170,7 @@ Debug.dump(graph, "%s: %s", method.getName(), GraphBuilderPhase.class.getSimpleName()); - new SnippetVerificationPhase().apply(graph); + new SnippetVerificationPhase(runtime).apply(graph); new SnippetIntrinsificationPhase(runtime, pool, true).apply(graph);
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetVerificationPhase.java Thu Nov 29 17:13:59 2012 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetVerificationPhase.java Thu Nov 29 09:13:59 2012 -0800 @@ -42,8 +42,16 @@ */ public class SnippetVerificationPhase extends Phase { + private final MetaAccessProvider metaAccess; + + public SnippetVerificationPhase(MetaAccessProvider metaAccess) { + this.metaAccess = metaAccess; + } + @Override protected void run(StructuredGraph graph) { + ResolvedJavaType wordType = metaAccess.lookupJavaType(Word.class); + for (ValueNode node : graph.getNodes().filter(ValueNode.class)) { for (Node usage : node.usages()) { if (usage instanceof AccessMonitorNode) { @@ -83,7 +91,7 @@ ValueNode argument = arguments.get(argc); if (argument == node) { ResolvedJavaType type = (ResolvedJavaType) signature.getParameterType(i, method.getDeclaringClass()); - verify((type.isClass(Word.class)) == isWord(argument), node, invoke.node(), "cannot pass word value to non-word parameter " + i + " or vice-versa"); + verify(type.equals(wordType) == isWord(argument), node, invoke.node(), "cannot pass word value to non-word parameter " + i + " or vice-versa"); } argc++; }