# HG changeset patch # User Thomas Wuerthinger # Date 1362508326 -3600 # Node ID 29c2103630ef3a0f83a7e38e834b21bd30c5508c # Parent c6c72de0537e29c3edff1994d676bcd8a15c2515 New strategy for inserting safepoints - always insert in loops but avoid in leaf methods. diff -r c6c72de0537e -r 29c2103630ef graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Tue Mar 05 19:20:05 2013 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Tue Mar 05 19:32:06 2013 +0100 @@ -194,9 +194,7 @@ plan.runPhases(PhasePosition.LOW_LEVEL, graph); // Add safepoints to loops - if (GraalOptions.GenLoopSafepoints) { - new LoopSafepointInsertionPhase().apply(graph); - } + new SafepointInsertionPhase().apply(graph); final SchedulePhase schedule = new SchedulePhase(); schedule.apply(graph); diff -r c6c72de0537e -r 29c2103630ef graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Tue Mar 05 19:20:05 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Tue Mar 05 19:32:06 2013 +0100 @@ -236,27 +236,6 @@ asm.incrementq(rsp, frameSize - 8); // account for the pop of RBP below asm.pop(rbp); - - if (GraalOptions.GenSafepoints) { - HotSpotVMConfig config = runtime().config; - - // If at the return point, then the frame has already been popped - // so deoptimization cannot be performed here. The HotSpot runtime - // detects this case - see the definition of frame::should_be_deoptimized() - - Register scratch = regConfig.getScratchRegister(); - int offset = SafepointPollOffset % unsafe.pageSize(); - if (config.isPollingPageFar) { - asm.movq(scratch, config.safepointPollingAddress + offset); - tasm.recordMark(Marks.MARK_POLL_RETURN_FAR); - asm.movq(scratch, new AMD64Address(tasm.target.wordKind, scratch.asValue())); - } else { - tasm.recordMark(Marks.MARK_POLL_RETURN_NEAR); - // The C++ code transforms the polling page offset into an RIP displacement - // to the real address at that offset in the polling page. - asm.movq(scratch, new AMD64Address(tasm.target.wordKind, rip.asValue(), offset)); - } - } } } diff -r c6c72de0537e -r 29c2103630ef graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoopSafepointInsertionPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoopSafepointInsertionPhase.java Tue Mar 05 19:20:05 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 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.graal.phases.common; - -import com.oracle.graal.graph.iterators.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.util.*; -import com.oracle.graal.phases.*; - -/** - * Adds safepoints to loops. - */ -public class LoopSafepointInsertionPhase extends Phase { - - @Override - protected void run(StructuredGraph graph) { - nextLoop: for (LoopEndNode loopEnd : graph.getNodes(LoopEndNode.class)) { - if (!loopEnd.canSafepoint()) { - continue; - } - if (GraalOptions.OptSafepointElimination) { - // We 'eliminate' safepoints by simply never placing them into loops that have at - // least one call - NodeIterable it = NodeIterators.dominators(loopEnd).until(loopEnd.loopBegin()); - for (FixedNode n : it) { - if (n instanceof Invoke) { - continue nextLoop; - } - } - } - SafepointNode safepoint = graph.add(new SafepointNode()); - graph.addBeforeFixed(loopEnd, safepoint); - } - } -} diff -r c6c72de0537e -r 29c2103630ef graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/SafepointInsertionPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/SafepointInsertionPhase.java Tue Mar 05 19:32:06 2013 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011, 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.phases.common; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.java.*; +import com.oracle.graal.phases.*; + +/** + * Adds safepoints to loops and return points. + */ +public class SafepointInsertionPhase extends Phase { + + @Override + protected void run(StructuredGraph graph) { + if (GraalOptions.GenLoopSafepoints) { + for (LoopEndNode loopEnd : graph.getNodes(LoopEndNode.class)) { + if (!loopEnd.canSafepoint()) { + continue; + } + SafepointNode safepoint = graph.add(new SafepointNode()); + graph.addBeforeFixed(loopEnd, safepoint); + } + } + + if (GraalOptions.GenSafepoints) { + if (!GraalOptions.OptEliminateSafepoints || graph.getNodes(MethodCallTargetNode.class).first() != null) { + for (ReturnNode loopEnd : graph.getNodes(ReturnNode.class)) { + SafepointNode safepoint = graph.add(new SafepointNode()); + graph.addBeforeFixed(loopEnd, safepoint); + } + } + } + } +} diff -r c6c72de0537e -r 29c2103630ef graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Tue Mar 05 19:20:05 2013 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Tue Mar 05 19:32:06 2013 +0100 @@ -186,10 +186,10 @@ public static boolean OptCanonicalizer = true; public static boolean OptScheduleOutOfLoops = true; public static boolean OptEliminateGuards = true; + public static boolean OptEliminateSafepoints = true; public static boolean OptImplicitNullChecks = true; public static boolean OptLivenessAnalysis = true; public static boolean OptLoopTransform = true; - public static boolean OptSafepointElimination = true; public static boolean OptFloatingReads = true; public static boolean OptTailDuplication = true; public static boolean OptEliminatePartiallyRedundantGuards = true;