# HG changeset patch # User Doug Simon # Date 1391725450 -3600 # Node ID bdeadcd7101d3d76d11beb1c9f722b52dd6da723 # Parent 45f9dbb9398883b910fe7e7b81edba7b62b5473a HSAIL: disable String.equals() substitutions Contributed-by: Tom Deneau diff -r 45f9dbb93988 -r bdeadcd7101d graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringEqualsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringEqualsTest.java Thu Feb 06 23:24:10 2014 +0100 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009, 2012, 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.compiler.hsail.test; + +import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; +import org.junit.Test; + +public class StringEqualsTest extends GraalKernelTester { + + static final int NUM = 20; + @Result public boolean[] outArray = new boolean[NUM]; + public String[] inArray = new String[NUM]; + + void setupArrays() { + char[] chars = new char[100]; + for (int i = 0; i < chars.length; i++) { + chars[i] = (char) ('A' + i); + } + for (int i = 0; i < NUM; i++) { + inArray[i] = new String(chars, 0, 10 + (i % 3)); + } + } + + public void run(String base, int gid) { + outArray[gid] = inArray[gid].equals(base); + } + + @Override + public void runTest() { + setupArrays(); + + dispatchMethodKernel(NUM, "ABCDEFGHIJ"); + } + + @Test + public void test() { + testGeneratedHsail(); + } +} diff -r 45f9dbb93988 -r bdeadcd7101d graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Thu Feb 06 23:14:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Thu Feb 06 23:24:10 2014 +0100 @@ -48,11 +48,9 @@ import com.oracle.graal.lir.asm.*; import com.oracle.graal.lir.hsail.*; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.replacements.hsail.*; /** * HSAIL specific backend. @@ -107,10 +105,8 @@ lowerer.initialize(providers, config); // Register the replacements used by the HSAIL backend. - Replacements replacements = providers.getReplacements(); - - // Register the substitutions for java.lang.Math routines. - replacements.registerSubstitutions(HSAILMathSubstitutions.class); + HSAILHotSpotReplacementsImpl replacements = (HSAILHotSpotReplacementsImpl) providers.getReplacements(); + replacements.completeInitialization(); } /** diff -r 45f9dbb93988 -r bdeadcd7101d graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java Thu Feb 06 23:14:06 2014 +0100 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java Thu Feb 06 23:24:10 2014 +0100 @@ -30,6 +30,8 @@ import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.util.*; import com.oracle.graal.replacements.*; +import com.oracle.graal.replacements.hsail.*; +import java.util.HashSet; /** * The substitutions and snippets supported by HSAIL. @@ -37,12 +39,31 @@ public class HSAILHotSpotReplacementsImpl extends ReplacementsImpl { private final Replacements host; + private HashSet ignoredResolvedMethods = new HashSet<>(); public HSAILHotSpotReplacementsImpl(Providers providers, Assumptions assumptions, TargetDescription target, Replacements host) { super(providers, assumptions, target); this.host = host; } + public void addIgnoredResolvedMethod(Class cls, String methName, Class... params) { + try { + Method m = cls.getMethod(methName, params); + ResolvedJavaMethod rjm = providers.getMetaAccess().lookupJavaMethod(m); + ignoredResolvedMethods.add(rjm); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void completeInitialization() { + // Register the substitutions for java.lang.Math routines. + registerSubstitutions(HSAILMathSubstitutions.class); + + // Register the ignored substitutions + addIgnoredResolvedMethod(String.class, "equals", Object.class); + } + @Override protected ResolvedJavaMethod registerMethodSubstitution(Member originalMethod, Method substituteMethod) { // TODO: decide if we want to override this in any way @@ -70,9 +91,13 @@ public StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) { StructuredGraph m = super.getMethodSubstitution(original); if (m == null) { - // eventually we want to only defer certain substitutions to the host, but for now we - // will defer everything - return host.getMethodSubstitution(original); + // we check for a few special cases we do NOT want to defer here + // but basically we defer everything else to the host + if (ignoredResolvedMethods.contains(original)) { + return null; + } else { + return host.getMethodSubstitution(original); + } } return m; }