# HG changeset patch # User Doug Simon # Date 1375091877 -7200 # Node ID d518ea24c82b31290e327b09b18f08ad5e77b9e7 # Parent 4cda6853056e98e68712ad63b1049a6862665f37 added ClassIsInterfaceNode macro node diff -r 4cda6853056e -r d518ea24c82b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ClassIsInterfaceNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ClassIsInterfaceNode.java Mon Jul 29 11:57:57 2013 +0200 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.nodes; + +import com.oracle.graal.hotspot.replacements.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.replacements.nodes.*; + +/** + * {@link MacroNode Macro node} for {@link Class#isInterface()}. + * + * @see ClassSubstitutions#isInterface(Class) + */ +public class ClassIsInterfaceNode extends MacroNode implements Canonicalizable, Lowerable { + + public ClassIsInterfaceNode(Invoke invoke) { + super(invoke); + } + + private ValueNode getJavaClass() { + return arguments.get(0); + } + + public ValueNode canonical(CanonicalizerTool tool) { + ValueNode javaClass = getJavaClass(); + if (javaClass.isConstant()) { + Class c = (Class) javaClass.asConstant().asObject(); + return ConstantNode.forBoolean(c.isInterface(), graph()); + } + return this; + } +} diff -r 4cda6853056e -r d518ea24c82b graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java Mon Jul 29 11:43:27 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java Mon Jul 29 11:57:57 2013 +0200 @@ -51,6 +51,7 @@ } } + @MacroSubstitution(macro = ClassIsInterfaceNode.class, isStatic = false) @MethodSubstitution(isStatic = false) public static boolean isInterface(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); diff -r 4cda6853056e -r d518ea24c82b graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Mon Jul 29 11:43:27 2013 +0200 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsImpl.java Mon Jul 29 11:57:57 2013 +0200 @@ -123,12 +123,15 @@ int modifiers = substituteMethod.getModifiers(); if (!Modifier.isStatic(modifiers)) { - throw new RuntimeException("Substitution methods must be static: " + substituteMethod); + throw new GraalInternalError("Substitution methods must be static: " + substituteMethod); } if (methodSubstitution != null) { + if (macroSubstitution != null && macroSubstitution.isStatic() != methodSubstitution.isStatic()) { + throw new GraalInternalError("Macro and method substitution must agree on isStatic attribute: " + substituteMethod); + } if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) { - throw new RuntimeException("Substitution method must not be abstract or native: " + substituteMethod); + throw new GraalInternalError("Substitution method must not be abstract or native: " + substituteMethod); } String originalName = originalName(substituteMethod, methodSubstitution.value()); Class[] originalParameters = originalParameters(substituteMethod, methodSubstitution.signature(), methodSubstitution.isStatic());