# HG changeset patch # User Lukas Stadler # Date 1310125287 -7200 # Node ID 3d68684b7161946d4d61a3ea7d31aa087231c5d6 # Parent ce2952ab20286f15eb83ea019165fe3530cf385c added FrameModifier extension, added deopt example diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Thu Jul 07 20:46:20 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java Fri Jul 08 13:41:27 2011 +0200 @@ -42,6 +42,7 @@ import com.oracle.max.graal.compiler.util.*; import com.oracle.max.graal.compiler.value.*; import com.oracle.max.graal.compiler.value.FrameState.ValueProcedure; +import com.oracle.max.graal.extensions.*; import com.oracle.max.graal.graph.*; import com.sun.cri.ci.*; import com.sun.cri.ri.*; @@ -1840,6 +1841,23 @@ } } + public static ThreadLocal> frameModifierLoader = new ThreadLocal>(); + + private CiFrame overrideFrame(CiFrame frame) { + ServiceLoader serviceLoader = frameModifierLoader.get(); + if (serviceLoader == null) { + serviceLoader = ServiceLoader.load(FrameModifier.class); + frameModifierLoader.set(serviceLoader); + } + + CiFrame result = frame; + for (FrameModifier modifier : serviceLoader) { + result = modifier.getFrame(compilation.runtime, result); + } + return result; + } + + private class DebugFrameBuilder { private final FrameState topState; @@ -1942,7 +1960,11 @@ if (state.outerFrameState() != null) { caller = computeFrameForState(state.outerFrameState()); } - return new CiFrame(caller, state.method, state.bci, state.rethrowException(), values, state.localsSize(), state.stackSize(), state.locksSize()); + CiFrame frame = new CiFrame(caller, state.method, state.bci, state.rethrowException(), values, state.localsSize(), state.stackSize(), state.locksSize()); + if (GraalOptions.Extend) { + frame = overrideFrame(frame); + } + return frame; } public CiFrame build() { diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/FrameModifier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/extensions/FrameModifier.java Fri Jul 08 13:41:27 2011 +0200 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011, 2011, 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.max.graal.extensions; + +import com.sun.cri.ci.*; +import com.sun.cri.ri.*; + + +public interface FrameModifier { + CiFrame getFrame(RiRuntime runtime, CiFrame frame); +} diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.examples/src/META-INF/services/com.oracle.max.graal.extensions.FrameModifier --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.examples/src/META-INF/services/com.oracle.max.graal.extensions.FrameModifier Fri Jul 08 13:41:27 2011 +0200 @@ -0,0 +1,1 @@ +com.oracle.max.graal.examples.deopt.FrameModifierImpl \ No newline at end of file diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/Main.java --- a/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/Main.java Thu Jul 07 20:46:20 2011 +0200 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/Main.java Fri Jul 08 13:41:27 2011 +0200 @@ -22,6 +22,7 @@ */ package com.oracle.max.graal.examples; +import com.oracle.max.graal.examples.deopt.*; import com.oracle.max.graal.examples.inlining.*; import com.oracle.max.graal.examples.intrinsics.*; import com.oracle.max.graal.examples.opt.*; @@ -30,9 +31,10 @@ public class Main { public static void main(String[] args) { - InliningExample.run(); - SafeAddExample.run(); - OptimizationExample.run(); +// InliningExample.run(); +// SafeAddExample.run(); +// OptimizationExample.run(); + DeoptExample.run(); } } diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/deopt/DeoptExample.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/deopt/DeoptExample.java Fri Jul 08 13:41:27 2011 +0200 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011, 2011, 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.max.graal.examples.deopt; + +import com.oracle.max.graal.examples.intrinsics.*; + + +public class DeoptExample { + + public static void run() { + System.out.println(); + System.out.println(); + System.out.println("Running Deopt Example"); + long start = System.currentTimeMillis(); + System.out.println("result1=" + test()); + System.out.println("time=" + (System.currentTimeMillis() - start) + "ms"); + } + + private static int test() { + try { + return testDeopt(3000000); + } catch (IllegalStateException e) { + System.out.println(e.getMessage()); + return 0; + } + } + + private static int testDeopt(int n) { + int sum = 0; + for (int i = 0; i < n; i = SafeAddExample.safeAdd(i, 1)) { + sum = SafeAddExample.safeAdd(sum, i); + } + return sum; + } +} diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/deopt/DeoptHandler.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/deopt/DeoptHandler.java Fri Jul 08 13:41:27 2011 +0200 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2011, 2011, 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.max.graal.examples.deopt; + + +public class DeoptHandler { + + + public static int test(int bci, Object[] values) { + System.out.println("values at bci " + bci + ": "); + for (Object value : values) { + System.out.print(value + " "); + } + System.out.println(); + return 2; + } + +} diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/deopt/FrameModifierImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/deopt/FrameModifierImpl.java Fri Jul 08 13:41:27 2011 +0200 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2011, 2011, 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.max.graal.examples.deopt; + +import com.oracle.max.graal.extensions.*; +import com.sun.cri.ci.*; +import com.sun.cri.ri.*; + + +public class FrameModifierImpl implements FrameModifier { + + @Override + public CiFrame getFrame(RiRuntime runtime, CiFrame frame) { + try { + DeoptHandler.class.getMethod("test", Integer.TYPE, Object[].class); + } catch (Exception e) { + e.printStackTrace(); + return frame; + } + if (frame.method.name().equals("testDeopt")) { + RiType type = runtime.getType(DeoptHandler.class); + RiMethod method = type.getMethod("test", "(I[Ljava/lang/Object;)I"); + System.out.println("Size: " + method.maxLocals() + " " + method.maxStackSize()); + RiType arrayType = runtime.getType(Object.class).arrayOf(); + CiValue[] values = new CiValue[frame.values.length]; + for (int i = 0; i < values.length; i++) { + values[i] = CiVirtualObject.proxy(runtime, frame.values[i], i + 2); + } + CiVirtualObject local = CiVirtualObject.get(arrayType, values, 0); + CiValue[] values2 = new CiValue[method.maxLocals()]; + values2[0] = CiConstant.forInt(frame.bci); + values2[1] = local; + for (int i = 2; i < values2.length; i++) { + values2[i] = CiValue.IllegalValue; + } + return new CiFrame((CiFrame) frame.caller, method, 0, false, values2, method.maxLocals(), 0, 0); + } + return frame; + } + +} diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/SafeAddExample.java --- a/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/SafeAddExample.java Thu Jul 07 20:46:20 2011 +0200 +++ b/graal/com.oracle.max.graal.examples/src/com/oracle/max/graal/examples/intrinsics/SafeAddExample.java Fri Jul 08 13:41:27 2011 +0200 @@ -32,11 +32,11 @@ System.out.println(); System.out.println("Running SafeAdd Example"); long start = System.currentTimeMillis(); - System.out.println("result=" + test()); + System.out.println("result=" + testSafeAdd()); System.out.println("time=" + (System.currentTimeMillis() - start) + "ms"); } - private static int test() { + private static int testSafeAdd() { int sum = 0; int j = N; for (int i = -N; i < N; ++i) { diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java Thu Jul 07 20:46:20 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotRuntime.java Fri Jul 08 13:41:27 2011 +0200 @@ -526,4 +526,9 @@ private ReadNode readHub(Graph graph, Value value) { return new ReadNode(CiKind.Object, value, LocationNode.create(LocationNode.FINAL_LOCATION, CiKind.Object, config.hubOffset, graph), graph); } + + @Override + public RiType getType(Class clazz) { + return compiler.getVMEntries().getType(clazz); + } } diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypePrimitive.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypePrimitive.java Thu Jul 07 20:46:20 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypePrimitive.java Fri Jul 08 13:41:27 2011 +0200 @@ -154,4 +154,9 @@ public RiField[] fields() { return null; } + + @Override + public RiMethod getMethod(String name, String signature) { + return null; + } } diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypeResolvedImpl.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypeResolvedImpl.java Thu Jul 07 20:46:20 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypeResolvedImpl.java Fri Jul 08 13:41:27 2011 +0200 @@ -230,4 +230,9 @@ } return fields; } + + @Override + public RiMethod getMethod(String name, String signature) { + return compiler.getVMEntries().RiType_resolveMethodImpl(this, name, signature); + } } diff -r ce2952ab2028 -r 3d68684b7161 graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypeUnresolved.java --- a/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypeUnresolved.java Thu Jul 07 20:46:20 2011 +0200 +++ b/graal/com.oracle.max.graal.runtime/src/com/oracle/max/graal/runtime/HotSpotTypeUnresolved.java Fri Jul 08 13:41:27 2011 +0200 @@ -205,4 +205,9 @@ public RiField[] fields() { return null; } + + @Override + public RiMethod getMethod(String name, String signature) { + return null; + } } diff -r ce2952ab2028 -r 3d68684b7161 runexamples.sh diff -r ce2952ab2028 -r 3d68684b7161 runexamplescompare.sh