forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GR-7143] Add slow path to the substitution of Array.newInstance.
- Loading branch information
Showing
5 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...lvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/ArrayGetInstanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2017, 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 org.graalvm.compiler.hotspot.test; | ||
|
||
import jdk.vm.ci.code.InstalledCode; | ||
import jdk.vm.ci.code.InvalidInstalledCodeException; | ||
import jdk.vm.ci.meta.ResolvedJavaMethod; | ||
import org.graalvm.compiler.api.directives.GraalDirectives; | ||
import org.graalvm.compiler.core.phases.HighTier; | ||
import org.graalvm.compiler.core.test.GraalCompilerTest; | ||
import org.graalvm.compiler.options.OptionValues; | ||
import org.junit.Test; | ||
|
||
import java.lang.reflect.Array; | ||
|
||
public class ArrayGetInstanceTest extends GraalCompilerTest { | ||
|
||
public static boolean newArray(Class<?> klass) { | ||
Array.newInstance(klass, 0); | ||
return GraalDirectives.inCompiledCode(); | ||
} | ||
|
||
@Test | ||
public void testNewArray() throws InvalidInstalledCodeException { | ||
ResolvedJavaMethod method = getResolvedJavaMethod("newArray"); | ||
InstalledCode code = getCode(method); | ||
assertTrue((Boolean) code.executeVarargs(ArrayGetInstanceTest.class)); | ||
} | ||
|
||
public static boolean newArrayInLoop(Class<?> klass, int length) { | ||
for (int i = 0; i < 2; i++) { | ||
Array.newInstance(klass, length); | ||
} | ||
return GraalDirectives.inCompiledCode(); | ||
} | ||
|
||
@Test | ||
public void testNewArrayInLoop() throws InvalidInstalledCodeException { | ||
ResolvedJavaMethod method = getResolvedJavaMethod("newArrayInLoop"); | ||
InstalledCode code = getCode(method, new OptionValues(getInitialOptions(), HighTier.Options.Inline, false)); | ||
try { | ||
code.executeVarargs(ArrayGetInstanceTest.class, -1); | ||
} catch (NegativeArraySizeException e) { | ||
} | ||
code = getCode(method, null, true, false, new OptionValues(getInitialOptions(), HighTier.Options.Inline, false)); | ||
assertTrue((Boolean) code.executeVarargs(ArrayGetInstanceTest.class, 0)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...iler.hotspot/src/org/graalvm/compiler/hotspot/replacements/HotSpotArraySubstitutions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2012, 2014, 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 org.graalvm.compiler.hotspot.replacements; | ||
|
||
import static org.graalvm.compiler.hotspot.GraalHotSpotVMConfig.INJECTED_VMCONFIG; | ||
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_ARRAY_KLASS_LOCATION; | ||
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.arrayKlassOffset; | ||
import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.loadKlassFromObject; | ||
|
||
import java.lang.reflect.Array; | ||
|
||
import jdk.vm.ci.meta.JavaKind; | ||
|
||
import org.graalvm.compiler.api.directives.GraalDirectives; | ||
import org.graalvm.compiler.api.replacements.ClassSubstitution; | ||
import org.graalvm.compiler.api.replacements.MethodSubstitution; | ||
import org.graalvm.compiler.nodes.java.DynamicNewArrayNode; | ||
|
||
// JaCoCo Exclude | ||
|
||
/** | ||
* Substitutions for {@link Array} methods. | ||
*/ | ||
@ClassSubstitution(Array.class) | ||
public class HotSpotArraySubstitutions { | ||
|
||
@MethodSubstitution | ||
public static Object newInstance(Class<?> componentType, int length) { | ||
if (componentType == null || loadKlassFromObject(componentType, arrayKlassOffset(INJECTED_VMCONFIG), CLASS_ARRAY_KLASS_LOCATION).isNull()) { | ||
// Exit the intrinsic here for the case where the array class does not exist | ||
return newInstance(componentType, length); | ||
} | ||
return DynamicNewArrayNode.newArray(GraalDirectives.guardingNonNull(componentType), length, JavaKind.Object); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters