# HG changeset patch # User Gilles Duboscq # Date 1397748115 -7200 # Node ID affef8631cf42c8f6453d092f2d7d8c68eed1445 # Parent 4d19ee79fcee5ae34484fbea6f0c0da431020297 Add eager resolving for indy call sites diff -r 4d19ee79fcee -r affef8631cf4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Apr 17 17:16:05 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Apr 17 17:21:55 2014 +0200 @@ -351,4 +351,6 @@ * invalidated. */ void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); + + void resolveInvokeDynamic(long metaspaceConstantPool, int index); } diff -r 4d19ee79fcee -r affef8631cf4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Apr 17 17:16:05 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Apr 17 17:21:55 2014 +0200 @@ -180,4 +180,6 @@ public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); public native long getTimeStamp(); + + public native void resolveInvokeDynamic(long metaspaceConstantPool, int index); } diff -r 4d19ee79fcee -r affef8631cf4 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java Thu Apr 17 17:16:05 2014 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotConstantPool.java Thu Apr 17 17:21:55 2014 +0200 @@ -501,7 +501,7 @@ break; case Bytecodes.INVOKEDYNAMIC: // invokedynamic instructions point to a constant pool cache entry. - index = decodeConstantPoolCacheIndex(cpi); + index = decodeConstantPoolCacheIndex(cpi) + runtime().getConfig().constantPoolCpCacheIndexTag; index = runtime().getCompilerToVM().constantPoolRemapInstructionOperandFromCache(metaspaceConstantPool, index); break; default: @@ -517,13 +517,7 @@ index = getUncachedKlassRefIndexAt(index); tag = getTagAt(index); assert tag == JVM_CONSTANT.Class || tag == JVM_CONSTANT.UnresolvedClass || tag == JVM_CONSTANT.UnresolvedClassInError : tag; - break; - default: - // nothing - break; - } - - switch (tag) { + // fall-through case Class: case UnresolvedClass: case UnresolvedClassInError: @@ -534,6 +528,9 @@ unsafe.ensureClassInitialized(klass); } break; + case InvokeDynamic: + runtime().getCompilerToVM().resolveInvokeDynamic(metaspaceConstantPool, cpi); + break; default: // nothing break; diff -r 4d19ee79fcee -r affef8631cf4 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/Int_less02.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/Int_less02.java Thu Apr 17 17:16:05 2014 +0200 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/Int_less02.java Thu Apr 17 17:21:55 2014 +0200 @@ -20,8 +20,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -/* - */ package com.oracle.graal.jtt.lang; import org.junit.*; diff -r 4d19ee79fcee -r affef8631cf4 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/JDK_ClassLoaders02.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/JDK_ClassLoaders02.java Thu Apr 17 17:16:05 2014 +0200 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/JDK_ClassLoaders02.java Thu Apr 17 17:21:55 2014 +0200 @@ -20,26 +20,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -/* - * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. - * - * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product - * that is described in this document. In particular, and without limitation, these intellectual property - * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or - * more additional patents or pending patent applications in the U.S. and in other countries. - * - * U.S. Government Rights - Commercial software. Government users are subject to the Sun - * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its - * supplements. - * - * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or - * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks - * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the - * U.S. and other countries. - * - * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open - * Company, Ltd. - */ package com.oracle.graal.jtt.lang; import java.net.*; diff -r 4d19ee79fcee -r affef8631cf4 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/LambdaEagerTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/lang/LambdaEagerTest.java Thu Apr 17 17:21:55 2014 +0200 @@ -0,0 +1,74 @@ +/* + * Copyright (c) 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 com.oracle.graal.jtt.lang; + +import java.util.*; +import java.util.function.*; + +import org.junit.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.jtt.*; + +public class LambdaEagerTest extends JTTTest { + + private static final EnumSet UNRESOLVED_UNREACHED = EnumSet.of(DeoptimizationReason.Unresolved, DeoptimizationReason.UnreachedCode); + + private static int doBinary(IntBinaryOperator op, int x, int y) { + return op.applyAsInt(x, y); + } + + private static int add(int x, int y) { + return x + y; + } + + public static int nonCapturing(int x, int y) { + return doBinary((a, b) -> a + b, x, y); + } + + public static int nonCapturing2(int x, int y) { + return doBinary(LambdaEagerTest::add, x, y); + } + + public static int capturing(int x, int y, int z) { + return doBinary((a, b) -> a + b - z, x, y); + } + + @Test + public void testEagerResolveNonCapturing01() { + Result expected = new Result(3, null); + testAgainstExpected(getMethod("nonCapturing"), expected, UNRESOLVED_UNREACHED, 1, 2); + } + + @Test + public void testEagerResolveNonCapturing02() { + Result expected = new Result(3, null); + testAgainstExpected(getMethod("nonCapturing2"), expected, UNRESOLVED_UNREACHED, 1, 2); + } + + @Test + public void testEagerResolveCapturing() { + Result expected = new Result(0, null); + testAgainstExpected(getMethod("capturing"), expected, UNRESOLVED_UNREACHED, 1, 2, 3); + } +} \ No newline at end of file diff -r 4d19ee79fcee -r affef8631cf4 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Apr 17 17:16:05 2014 +0200 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Thu Apr 17 17:21:55 2014 +0200 @@ -933,7 +933,13 @@ return NULL; C2V_END - +C2V_VMENTRY(void, resolveInvokeDynamic, (JNIEnv *env, jobject, jlong metaspace_constant_pool, jint index)) + ConstantPool* cp = (ConstantPool*)metaspace_constant_pool; + CallInfo callInfo; + LinkResolver::resolve_invokedynamic(callInfo, cp, index, CHECK); + ConstantPoolCacheEntry* cp_cache_entry = cp->invokedynamic_cp_cache_entry_at(index); + cp_cache_entry->set_dynamic_call(cp, callInfo); +C2V_END // public native void materializeVirtualObjects(HotSpotStackFrameReference stackFrame, boolean invalidate); C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv *env, jobject, jobject hs_frame, bool invalidate)) @@ -1078,6 +1084,7 @@ {CC"lookupMethodInPool", CC"("METASPACE_CONSTANT_POOL"IB)"METASPACE_METHOD, FN_PTR(lookupMethodInPool)}, {CC"constantPoolRemapInstructionOperandFromCache", CC"("METASPACE_CONSTANT_POOL"I)I", FN_PTR(constantPoolRemapInstructionOperandFromCache)}, {CC"resolveField", CC"("METASPACE_CONSTANT_POOL"IB[J)"METASPACE_KLASS, FN_PTR(resolveField)}, + {CC"resolveInvokeDynamic", CC"("METASPACE_CONSTANT_POOL"I)V", FN_PTR(resolveInvokeDynamic)}, {CC"resolveMethod", CC"("METASPACE_KLASS STRING STRING")"METASPACE_METHOD, FN_PTR(resolveMethod)}, {CC"getClassInitializer", CC"("METASPACE_KLASS")"METASPACE_METHOD, FN_PTR(getClassInitializer)}, {CC"hasFinalizableSubclass", CC"("METASPACE_KLASS")Z", FN_PTR(hasFinalizableSubclass)},