Shark safepoint removal (part 2)
Gary Benson
gbenson at redhat.com
Fri May 29 04:42:44 PDT 2009
Hi again,
In order to ensure the VM doesn't spend too long inbetween safepoint
checks, HotSpot requires every loop to contain at least one safepoint
check. This is done by inserting an explicit safepoint every time a
branch moves backwards in the bytecode (which is called a backedge).
Not all backedges are parts of loops, however. This commit makes
Shark check whether the backedge is part of a loop, and omits the
safepoint check otherwise.
Cheers,
Gary
--
http://gbenson.net/
-------------- next part --------------
diff -r 1c47ca6df830 -r e3339b19c3d9 ChangeLog
--- a/ChangeLog Fri May 29 10:12:01 2009 +0100
+++ b/ChangeLog Fri May 29 12:38:51 2009 +0100
@@ -1,3 +1,23 @@
+2009-05-29 Gary Benson <gbenson at redhat.com>
+
+ * ports/hotspot/src/share/vm/shark/sharkBlock.hpp
+ (SharkBlock::maybe_add_safepoint): Replaced with...
+ (SharkBlock::maybe_add_backedge_safepoint): New method.
+ * ports/hotspot/src/share/vm/shark/sharkBlock.cpp
+ (SharkBlock::maybe_add_safepoint): Replaced with...
+ (SharkBlock::maybe_add_backedge_safepoint): New method.
+ (SharkBlock::parse_bytecode): Updated for above.
+
+ * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
+ (SharkBlock::maybe_add_backedge_safepoint): New method.
+ (SharkBlock::_can_reach_visited): New field.
+ (SharkBlock::can_reach): New method.
+ (SharkBlock::can_reach_helper): Likewise.
+ * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
+ (SharkBlock::maybe_add_backedge_safepoint): New method.
+ (SharkBlock::can_reach): Likewise.
+ (SharkBlock::can_reach_helper): Likewise.
+
2009-05-29 Gary Benson <gbenson at redhat.com>
* ports/hotspot/src/share/vm/shark/sharkState.hpp
diff -r 1c47ca6df830 -r e3339b19c3d9 ports/hotspot/src/share/vm/shark/sharkBlock.cpp
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.cpp Fri May 29 10:12:01 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.cpp Fri May 29 12:38:51 2009 +0100
@@ -74,24 +74,24 @@
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmpge:
if (iter()->get_dest() <= bci())
- maybe_add_safepoint();
+ maybe_add_backedge_safepoint();
break;
case Bytecodes::_goto_w:
if (iter()->get_far_dest() <= bci())
- maybe_add_safepoint();
+ maybe_add_backedge_safepoint();
break;
case Bytecodes::_tableswitch:
case Bytecodes::_lookupswitch:
if (switch_default_dest() <= bci()) {
- maybe_add_safepoint();
+ maybe_add_backedge_safepoint();
break;
}
int len = switch_table_length();
for (int i = 0; i < len; i++) {
if (switch_dest(i) <= bci()) {
- maybe_add_safepoint();
+ maybe_add_backedge_safepoint();
break;
}
}
@@ -1138,7 +1138,7 @@
ShouldNotCallThis();
}
-void SharkBlock::maybe_add_safepoint()
+void SharkBlock::maybe_add_backedge_safepoint()
{
ShouldNotCallThis();
}
diff -r 1c47ca6df830 -r e3339b19c3d9 ports/hotspot/src/share/vm/shark/sharkBlock.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.hpp Fri May 29 10:12:01 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.hpp Fri May 29 12:38:51 2009 +0100
@@ -231,7 +231,7 @@
// Safepoints
protected:
- virtual void maybe_add_safepoint();
+ virtual void maybe_add_backedge_safepoint();
// Traps
protected:
diff -r 1c47ca6df830 -r e3339b19c3d9 ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp Fri May 29 10:12:01 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp Fri May 29 12:38:51 2009 +0100
@@ -469,6 +469,51 @@
current_state()->set_has_safepointed(true);
}
+void SharkTopLevelBlock::maybe_add_backedge_safepoint()
+{
+ if (current_state()->has_safepointed())
+ return;
+
+ for (int i = 0; i < num_successors(); i++) {
+ if (successor(i)->can_reach(this)) {
+ maybe_add_safepoint();
+ break;
+ }
+ }
+}
+
+bool SharkTopLevelBlock::can_reach(SharkTopLevelBlock* other)
+{
+ for (int i = 0; i < function()->block_count(); i++)
+ function()->block(i)->_can_reach_visited = false;
+
+ return can_reach_helper(other);
+}
+
+bool SharkTopLevelBlock::can_reach_helper(SharkTopLevelBlock* other)
+{
+ if (this == other)
+ return true;
+
+ if (_can_reach_visited)
+ return false;
+ _can_reach_visited = true;
+
+ if (!has_trap()) {
+ for (int i = 0; i < num_successors(); i++) {
+ if (successor(i)->can_reach_helper(other))
+ return true;
+ }
+ }
+
+ for (int i = 0; i < num_exceptions(); i++) {
+ if (exception(i)->can_reach_helper(other))
+ return true;
+ }
+
+ return false;
+}
+
void SharkTopLevelBlock::do_trap(int trap_request)
{
current_state()->decache_for_trap();
diff -r 1c47ca6df830 -r e3339b19c3d9 ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp Fri May 29 10:12:01 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp Fri May 29 12:38:51 2009 +0100
@@ -311,6 +311,14 @@
// Safepoints
private:
void maybe_add_safepoint();
+ void maybe_add_backedge_safepoint();
+
+ // Loop safepoint removal
+ private:
+ bool _can_reach_visited;
+
+ bool can_reach(SharkTopLevelBlock* other);
+ bool can_reach_helper(SharkTopLevelBlock* other);
// Traps
private:
More information about the distro-pkg-dev
mailing list