changeset 1903:8caa172d8bbc

2009-06-18 Gary Benson <gbenson@redhat.com> * ports/hotspot/src/share/vm/shark/sharkInvariants.hpp: New file. * ports/hotspot/src/share/vm/shark/sharkInvariants.cpp: Likewise. * ports/hotspot/src/share/vm/shark/sharkFunction.hpp (SharkFunction): Made a subclass of SharkTargetInvariants. (SharkFunction::SharkFunction): Updated constructor. (SharkFunction::_compiler): Removed. (SharkFunction::_flow): Likewise. (SharkFunction::_iter): Likewise. (SharkFunction::_thread): Likewise. (SharkFunction::_max_monitors): Likewise. (SharkFunction::compiler): Likewise. (SharkFunction::flow): Likewise. (SharkFunction::iter): Likewise. (SharkFunction::thread): Likewise. (SharkFunction::max_monitors): Likewise. (SharkFunction::builder): Likewise. (SharkFunction::arg_size): Likewise. (SharkFunction::debug_info): Likewise. (SharkFunction::env): Likewise. (SharkFunction::max_locals): Likewise. (SharkFunction::max_stack): Likewise. (SharkFunction::target): Likewise. * ports/hotspot/src/share/vm/shark/sharkFunction.hpp (SharkFunction::initialize): Updated. * ports/hotspot/src/share/vm/shark/sharkBlock.hpp (SharkBlock): Made a subclass of SharkTargetInvariants. (SharkBlock::SharkBlock): Updated constructors. (SharkBlock::_builder): Removed. (SharkBlock::_target): Likewise. (SharkBlock::_thread): Likewise. (SharkBlock::builder): Likewise. (SharkBlock::target): Likewise. (SharkBlock::thread): Likewise. (SharkBlock::max_locals): Likewise. (SharkBlock::max_stack): Likewise. * ports/hotspot/src/share/vm/shark/sharkBlock.cpp (SharkBlock::initial_current_state): Use SharkState::copy. * ports/hotspot/src/share/vm/shark/sharkState.hpp (SharkState): Made a subclass of SharkTargetInvariants. (SharkState::SharkState): Updated constructors. (SharkState::_block): Removed. (SharkState::_function): Likewise. (SharkState::block): Likewise. (SharkState::function): Likewise. (SharkState::builder): Likewise. (SharkState::max_locals): Likewise. (SharkState::max_stack): Likewise. (SharkState::max_monitors): Likewise. (SharkState::pop): Likewise. (SharkState::copy): Updated. (SharkState::decache_for_Java_call): Moved to SharkTopLevelBlock. (SharkState::cache_after_Java_call): Likewise. (SharkState::decache_for_VM_call): Likewise. (SharkState::cache_after_VM_call): Likewise. (SharkState::decache_for_trap): Likewise. (SharkPHIState::_block): New field. (SharkPHIState::block): New method. * ports/hotspot/src/share/vm/shark/sharkState.inline.hpp: Removed. * ports/hotspot/src/share/vm/shark/sharkState.cpp (SharkState::equal_to): Updated. (SharkState::decache_for_Java_call): Moved to SharkTopLevelBlock. (SharkState::cache_after_Java_call): Likewise. (SharkState::decache_for_VM_call): Likewise. (SharkState::cache_after_VM_call): Likewise. (SharkState::decache_for_trap): Likewise. (SharkEntryState::SharkEntryState): Updated. (SharkPHIState::SharkPHIState): Likewise. (SharkPHIState::add_incoming): Likewise. * ports/hotspot/src/share/vm/shark/sharkStateScanner.hpp (SharkStateScanner): Made a subclass of SharkTargetInvariants. (SharkStateScanner::SharkStateScanner): Updated constructor. (SharkStateScanner::start_stack): Updated arguments. (SharkStateScanner::start_locals): Likewise. (SharkStateScanner::stack_integrity_checks): Made non-static. (SharkStateScanner::locals_integrity_checks): Likewise. * ports/hotspot/src/share/vm/shark/sharkStateScanner.cpp (SharkStateScanner::scan): Updated. (SharkStateScanner::locals_integrity_checks): Likewise. * ports/hotspot/src/share/vm/shark/sharkCacheDecache.hpp (SharkCacherDecacher::builder): Removed. (SharkDecacher::debug_info): Likewise. (SharkDecacher::start_stack): Updated arguments. (SharkDecacher::start_locals): Likewise. * ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp (SharkDecacher::start_frame): Updated. (SharkDecacher::start_stack): Likewise.. (SharkDecacher::start_locals): Likewise. (SharkDecacher::end_frame): Likewise. * ports/hotspot/src/share/vm/shark/sharkInliner.hpp (SharkInliner::attempt_inline): Removed thread argument. * ports/hotspot/src/share/vm/shark/sharkInliner.cpp (SharkInlineBlock): Made a subclass of SharkTargetInvariants. (SharkInlineBlock::SharkInlineBlock): Updated constructor. (SharkInlinerHelper::SharkInlinerHelper): Likewise. (SharkInlinerHelper::_thread): Removed. (SharkInlinerHelper::thread): Likewise. (SharkInlinerHelper::do_inline): Updated. (SharkInliner::attempt_inline): Updated. * ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp (SharkIntrinsics): Made a subclass of SharkTargetInvariants. (SharkIntrinsics::inline_intrinsic): Updated arguments. (SharkIntrinsics::SharkIntrinsics): New method. (SharkIntrinsics::_state): New field. (SharkIntrinsics::state): New method. (SharkIntrinsics::do_intrinsic): Likewise. (SharkIntrinsics::do_Math_minmax): Updated arguments. (SharkIntrinsics::do_Math_1to1): Likewise. (SharkIntrinsics::do_Math_2to1): Likewise. (SharkIntrinsics::do_Object_getClass): Likewise. (SharkIntrinsics::do_System_currentTimeMillis): Likewise. (SharkIntrinsics::do_Thread_currentThread): Likewise. (SharkIntrinsics::do_Unsafe_compareAndSwapInt): Likewise. * ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp (SharkIntrinsics::inline_intrinsic): Updated. (SharkIntrinsics::do_intrinsic): New method. (SharkIntrinsics::do_Math_minmax): Updated. (SharkIntrinsics::do_Math_1to1): Likewise. (SharkIntrinsics::do_Math_2to1): Likewise. (SharkIntrinsics::do_Object_getClass): Likewise. (SharkIntrinsics::do_System_currentTimeMillis): Likewise. (SharkIntrinsics::do_Thread_currentThread): Likewise. (SharkIntrinsics::do_Unsafe_compareAndSwapInt): Likewise. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp (SharkTopLevelBlock::SharkTopLevelBlock): Updated constructor. (SharkTopLevelBlock::decache_for_Java_call): Moved from SharkState. (SharkTopLevelBlock::cache_after_Java_call): Likewise. (SharkTopLevelBlock::decache_for_VM_call): Likewise. (SharkTopLevelBlock::cache_after_VM_call): Likewise. (SharkTopLevelBlock::decache_for_trap): Likewise. (SharkTopLevelBlock::call_vm): Updated. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp (SharkTopLevelBlock::decache_for_Java_call): Moved from SharkState. (SharkTopLevelBlock::cache_after_Java_call): Likewise. (SharkTopLevelBlock::decache_for_VM_call): Likewise. (SharkTopLevelBlock::cache_after_VM_call): Likewise. (SharkTopLevelBlock::decache_for_trap): Likewise. (SharkTopLevelBlock::do_trap): Updated. (SharkTopLevelBlock::improve_virtual_call): Likewise. (SharkTopLevelBlock::do_call): Likewise. (SharkTopLevelBlock::acquire_lock): Likewise. * ports/hotspot/src/share/vm/includeDB_shark: Updated.
author Gary Benson <gbenson@redhat.com>
date Thu, 18 Jun 2009 12:00:59 -0400
parents 9c4c94b5f4a2
children 21f0340f7c98
files ChangeLog ports/hotspot/src/share/vm/includeDB_shark ports/hotspot/src/share/vm/shark/sharkBlock.cpp ports/hotspot/src/share/vm/shark/sharkBlock.hpp ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp ports/hotspot/src/share/vm/shark/sharkCacheDecache.hpp ports/hotspot/src/share/vm/shark/sharkCompiler.cpp ports/hotspot/src/share/vm/shark/sharkFunction.cpp ports/hotspot/src/share/vm/shark/sharkFunction.hpp ports/hotspot/src/share/vm/shark/sharkInliner.cpp ports/hotspot/src/share/vm/shark/sharkInliner.hpp ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp ports/hotspot/src/share/vm/shark/sharkInvariants.cpp ports/hotspot/src/share/vm/shark/sharkInvariants.hpp ports/hotspot/src/share/vm/shark/sharkState.cpp ports/hotspot/src/share/vm/shark/sharkState.hpp ports/hotspot/src/share/vm/shark/sharkState.inline.hpp ports/hotspot/src/share/vm/shark/sharkStateScanner.cpp ports/hotspot/src/share/vm/shark/sharkStateScanner.hpp ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
diffstat 22 files changed, 689 insertions(+), 494 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 17 14:37:31 2009 +0100
+++ b/ChangeLog	Thu Jun 18 12:00:59 2009 -0400
@@ -1,3 +1,156 @@
+2009-06-18  Gary Benson  <gbenson@redhat.com>
+
+	* ports/hotspot/src/share/vm/shark/sharkInvariants.hpp: New file.
+	* ports/hotspot/src/share/vm/shark/sharkInvariants.cpp: Likewise.
+	
+	* ports/hotspot/src/share/vm/shark/sharkFunction.hpp
+	(SharkFunction): Made a subclass of SharkTargetInvariants.
+	(SharkFunction::SharkFunction): Updated constructor.
+	(SharkFunction::_compiler): Removed.
+	(SharkFunction::_flow): Likewise.
+	(SharkFunction::_iter): Likewise.
+	(SharkFunction::_thread): Likewise.
+	(SharkFunction::_max_monitors): Likewise.
+	(SharkFunction::compiler): Likewise.
+	(SharkFunction::flow): Likewise.
+	(SharkFunction::iter): Likewise.
+	(SharkFunction::thread): Likewise.
+	(SharkFunction::max_monitors): Likewise.
+	(SharkFunction::builder): Likewise.
+	(SharkFunction::arg_size): Likewise.
+	(SharkFunction::debug_info): Likewise.
+	(SharkFunction::env): Likewise.
+	(SharkFunction::max_locals): Likewise.
+	(SharkFunction::max_stack): Likewise.
+	(SharkFunction::target): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkFunction.hpp
+	(SharkFunction::initialize): Updated.
+
+	* ports/hotspot/src/share/vm/shark/sharkBlock.hpp
+	(SharkBlock): Made a subclass of SharkTargetInvariants.
+	(SharkBlock::SharkBlock): Updated constructors.
+	(SharkBlock::_builder): Removed.
+	(SharkBlock::_target): Likewise.
+	(SharkBlock::_thread): Likewise.
+	(SharkBlock::builder): Likewise.
+	(SharkBlock::target): Likewise.
+	(SharkBlock::thread): Likewise.
+	(SharkBlock::max_locals): Likewise.
+	(SharkBlock::max_stack): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkBlock.cpp
+	(SharkBlock::initial_current_state): Use SharkState::copy.
+
+	* ports/hotspot/src/share/vm/shark/sharkState.hpp
+	(SharkState): Made a subclass of SharkTargetInvariants.
+	(SharkState::SharkState): Updated constructors.
+	(SharkState::_block): Removed.
+	(SharkState::_function): Likewise.
+	(SharkState::block): Likewise.
+	(SharkState::function): Likewise.
+	(SharkState::builder): Likewise.
+	(SharkState::max_locals): Likewise.
+	(SharkState::max_stack): Likewise.
+	(SharkState::max_monitors): Likewise.
+	(SharkState::pop): Likewise.
+	(SharkState::copy): Updated.
+	(SharkState::decache_for_Java_call): Moved to SharkTopLevelBlock.
+	(SharkState::cache_after_Java_call): Likewise.
+	(SharkState::decache_for_VM_call): Likewise.
+	(SharkState::cache_after_VM_call): Likewise.
+	(SharkState::decache_for_trap): Likewise.
+	(SharkPHIState::_block): New field.
+	(SharkPHIState::block): New method.
+	* ports/hotspot/src/share/vm/shark/sharkState.inline.hpp: Removed.
+	* ports/hotspot/src/share/vm/shark/sharkState.cpp
+	(SharkState::equal_to): Updated.
+	(SharkState::decache_for_Java_call): Moved to SharkTopLevelBlock.
+	(SharkState::cache_after_Java_call): Likewise.
+	(SharkState::decache_for_VM_call): Likewise.
+	(SharkState::cache_after_VM_call): Likewise.
+	(SharkState::decache_for_trap): Likewise.
+	(SharkEntryState::SharkEntryState): Updated.
+	(SharkPHIState::SharkPHIState): Likewise.
+	(SharkPHIState::add_incoming): Likewise.
+
+	* ports/hotspot/src/share/vm/shark/sharkStateScanner.hpp
+	(SharkStateScanner): Made a subclass of SharkTargetInvariants.
+	(SharkStateScanner::SharkStateScanner): Updated constructor.
+	(SharkStateScanner::start_stack): Updated arguments.
+	(SharkStateScanner::start_locals): Likewise.
+	(SharkStateScanner::stack_integrity_checks): Made non-static.
+	(SharkStateScanner::locals_integrity_checks): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkStateScanner.cpp
+	(SharkStateScanner::scan): Updated.
+	(SharkStateScanner::locals_integrity_checks): Likewise.
+	
+	* ports/hotspot/src/share/vm/shark/sharkCacheDecache.hpp
+	(SharkCacherDecacher::builder): Removed.
+	(SharkDecacher::debug_info): Likewise.
+	(SharkDecacher::start_stack): Updated arguments.
+	(SharkDecacher::start_locals): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp
+	(SharkDecacher::start_frame): Updated.
+	(SharkDecacher::start_stack): Likewise..
+	(SharkDecacher::start_locals): Likewise.
+	(SharkDecacher::end_frame): Likewise.
+
+	* ports/hotspot/src/share/vm/shark/sharkInliner.hpp
+	(SharkInliner::attempt_inline): Removed thread argument.
+	* ports/hotspot/src/share/vm/shark/sharkInliner.cpp
+	(SharkInlineBlock): Made a subclass of SharkTargetInvariants.
+	(SharkInlineBlock::SharkInlineBlock): Updated constructor.
+	(SharkInlinerHelper::SharkInlinerHelper): Likewise.
+	(SharkInlinerHelper::_thread): Removed.
+	(SharkInlinerHelper::thread): Likewise.
+	(SharkInlinerHelper::do_inline): Updated.
+	(SharkInliner::attempt_inline): Updated.
+
+	* ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp
+	(SharkIntrinsics): Made a subclass of SharkTargetInvariants.
+	(SharkIntrinsics::inline_intrinsic): Updated arguments.
+	(SharkIntrinsics::SharkIntrinsics): New method.
+	(SharkIntrinsics::_state): New field.
+	(SharkIntrinsics::state): New method.
+	(SharkIntrinsics::do_intrinsic): Likewise.
+	(SharkIntrinsics::do_Math_minmax): Updated arguments.
+	(SharkIntrinsics::do_Math_1to1): Likewise.
+	(SharkIntrinsics::do_Math_2to1): Likewise.
+	(SharkIntrinsics::do_Object_getClass): Likewise.
+	(SharkIntrinsics::do_System_currentTimeMillis): Likewise.
+	(SharkIntrinsics::do_Thread_currentThread): Likewise.
+	(SharkIntrinsics::do_Unsafe_compareAndSwapInt): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp
+	(SharkIntrinsics::inline_intrinsic): Updated.
+	(SharkIntrinsics::do_intrinsic): New method.
+	(SharkIntrinsics::do_Math_minmax): Updated.
+	(SharkIntrinsics::do_Math_1to1): Likewise.
+	(SharkIntrinsics::do_Math_2to1): Likewise.
+	(SharkIntrinsics::do_Object_getClass): Likewise.
+	(SharkIntrinsics::do_System_currentTimeMillis): Likewise.
+	(SharkIntrinsics::do_Thread_currentThread): Likewise.
+	(SharkIntrinsics::do_Unsafe_compareAndSwapInt): Likewise.
+
+	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
+	(SharkTopLevelBlock::SharkTopLevelBlock): Updated constructor.
+	(SharkTopLevelBlock::decache_for_Java_call): Moved from SharkState.
+	(SharkTopLevelBlock::cache_after_Java_call): Likewise.
+	(SharkTopLevelBlock::decache_for_VM_call): Likewise.
+	(SharkTopLevelBlock::cache_after_VM_call): Likewise.
+	(SharkTopLevelBlock::decache_for_trap): Likewise.
+	(SharkTopLevelBlock::call_vm): Updated.
+	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
+	(SharkTopLevelBlock::decache_for_Java_call): Moved from SharkState.
+	(SharkTopLevelBlock::cache_after_Java_call): Likewise.
+	(SharkTopLevelBlock::decache_for_VM_call): Likewise.
+	(SharkTopLevelBlock::cache_after_VM_call): Likewise.
+	(SharkTopLevelBlock::decache_for_trap): Likewise.
+	(SharkTopLevelBlock::do_trap): Updated.
+	(SharkTopLevelBlock::improve_virtual_call): Likewise.
+	(SharkTopLevelBlock::do_call): Likewise.
+	(SharkTopLevelBlock::acquire_lock): Likewise.
+
+	* ports/hotspot/src/share/vm/includeDB_shark: Updated.	
+
 2009-06-17  Gary Benson  <gbenson@redhat.com>
 
 	* ports/hotspot/src/share/vm/shark/sharkCacheDecache.hpp
--- a/ports/hotspot/src/share/vm/includeDB_shark	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/includeDB_shark	Thu Jun 18 12:00:59 2009 -0400
@@ -50,8 +50,6 @@
 
 compileBroker.cpp                       sharkCompiler.hpp
 
-disassembler_<arch>.cpp                 sharkEntry.hpp
-
 globals.hpp                             shark_globals_<arch>.hpp
 
 globals.cpp                             shark_globals.hpp
@@ -75,7 +73,7 @@
 sharkBlock.cpp                          sharkBuilder.hpp
 sharkBlock.cpp                          sharkConstant.hpp
 sharkBlock.cpp                          sharkRuntime.hpp
-sharkBlock.cpp                          sharkState.inline.hpp
+sharkBlock.cpp                          sharkState.hpp
 sharkBlock.cpp                          sharkValue.hpp
 
 sharkBlock.hpp                          allocation.hpp
@@ -85,6 +83,7 @@
 sharkBlock.hpp                          llvmHeaders.hpp
 sharkBlock.hpp                          sharkBuilder.hpp
 sharkBlock.hpp                          sharkConstant.hpp
+sharkBlock.hpp                          sharkInvariants.hpp
 sharkBlock.hpp                          sharkState.hpp
 sharkBlock.hpp                          sharkValue.hpp
 
@@ -121,7 +120,7 @@
 sharkCacheDecache.cpp                   sharkBuilder.hpp
 sharkCacheDecache.cpp                   sharkCacheDecache.hpp
 sharkCacheDecache.cpp                   sharkFunction.hpp
-sharkCacheDecache.cpp                   sharkState.inline.hpp
+sharkCacheDecache.cpp                   sharkState.hpp
 
 sharkCacheDecache.hpp                   ciMethod.hpp
 sharkCacheDecache.hpp                   debugInfoRec.hpp
@@ -181,7 +180,7 @@
 sharkFunction.cpp                       sharkBuilder.hpp
 sharkFunction.cpp                       sharkEntry.hpp
 sharkFunction.cpp                       sharkFunction.hpp
-sharkFunction.cpp                       sharkState.inline.hpp
+sharkFunction.cpp                       sharkState.hpp
 sharkFunction.cpp                       sharkTopLevelBlock.hpp
 
 sharkFunction.hpp                       allocation.hpp
@@ -191,6 +190,7 @@
 sharkFunction.hpp                       llvmHeaders.hpp
 sharkFunction.hpp                       llvmValue.hpp
 sharkFunction.hpp                       sharkBuilder.hpp
+sharkFunction.hpp                       sharkInvariants.hpp
 
 sharkInliner.cpp                        allocation.hpp
 sharkInliner.cpp                        bytecodes.hpp
@@ -198,23 +198,24 @@
 sharkInliner.cpp                        ciMethod.hpp
 sharkInliner.cpp                        ciStreams.hpp
 sharkInliner.cpp                        shark_globals.hpp
+sharkInliner.cpp                        sharkBlock.hpp
 sharkInliner.cpp                        sharkConstant.hpp
 sharkInliner.cpp                        sharkInliner.hpp
 sharkInliner.cpp                        sharkIntrinsics.hpp
-sharkInliner.cpp                        sharkState.inline.hpp
+sharkInliner.cpp                        sharkState.hpp
 sharkInliner.cpp                        sharkValue.hpp
 
 sharkInliner.hpp                        allocation.hpp
 sharkInliner.hpp                        ciMethod.hpp
 sharkInliner.hpp                        llvmHeaders.hpp
-sharkInliner.hpp                        sharkState.inline.hpp
+sharkInliner.hpp                        sharkState.hpp
 
 sharkIntrinsics.cpp                     ciMethod.hpp
 sharkIntrinsics.cpp                     llvmHeaders.hpp
 sharkIntrinsics.cpp                     shark_globals.hpp
 sharkIntrinsics.cpp                     sharkIntrinsics.hpp
 sharkIntrinsics.cpp                     sharkRuntime.hpp
-sharkIntrinsics.cpp                     sharkState.inline.hpp
+sharkIntrinsics.cpp                     sharkState.hpp
 sharkIntrinsics.cpp                     sharkValue.hpp
 
 sharkIntrinsics.hpp                     allocation.hpp
@@ -222,6 +223,20 @@
 sharkIntrinsics.hpp                     llvmHeaders.hpp
 sharkIntrinsics.hpp                     sharkState.hpp
 
+sharkInvariants.cpp                     sharkInvariants.hpp
+
+sharkInvariants.hpp                     allocation.hpp
+sharkInvariants.hpp                     ciEnv.hpp
+sharkInvariants.hpp                     ciMethod.hpp
+sharkInvariants.hpp                     ciInstanceKlass.hpp
+sharkInvariants.hpp                     ciTypeFlow.hpp
+sharkInvariants.hpp                     debugInfoRec.hpp
+sharkInvariants.hpp                     dependencies.hpp
+sharkInvariants.hpp                     llvmHeaders.hpp
+sharkInvariants.hpp                     sharkBuilder.hpp
+sharkInvariants.hpp                     sharkCompiler.hpp
+sharkInvariants.hpp                     sharkMemoryManager.hpp
+
 sharkMemoryManager.hpp                  llvmHeaders.hpp
 sharkMemoryManager.hpp                  sharkEntry.hpp
 
@@ -249,7 +264,7 @@
 sharkState.cpp                          ciTypeFlow.hpp
 sharkState.cpp                          sharkBuilder.hpp
 sharkState.cpp                          sharkCacheDecache.hpp
-sharkState.cpp                          sharkState.inline.hpp
+sharkState.cpp                          sharkState.hpp
 sharkState.cpp                          sharkTopLevelBlock.hpp
 sharkState.cpp                          sharkType.hpp
 sharkState.cpp                          sharkValue.hpp
@@ -258,19 +273,16 @@
 sharkState.hpp                          ciMethod.hpp
 sharkState.hpp                          llvmHeaders.hpp
 sharkState.hpp                          sharkBuilder.hpp
+sharkState.hpp                          sharkInvariants.hpp
 sharkState.hpp                          sharkValue.hpp
 
-sharkState.inline.hpp                   sharkBlock.hpp
-sharkState.inline.hpp                   sharkBuilder.hpp
-sharkState.inline.hpp                   sharkFunction.hpp
-sharkState.inline.hpp                   sharkState.hpp
-
-sharkStateScanner.cpp                   sharkState.inline.hpp
+sharkStateScanner.cpp                   sharkState.hpp
 sharkStateScanner.cpp                   sharkStateScanner.hpp
 
 sharkStateScanner.hpp                   allocation.hpp
 sharkStateScanner.hpp                   llvmHeaders.hpp
 sharkStateScanner.hpp                   sharkFunction.hpp
+sharkStateScanner.hpp                   sharkInvariants.hpp
 
 sharkTopLevelBlock.cpp                  allocation.hpp
 sharkTopLevelBlock.cpp                  bytecodes.hpp
@@ -283,12 +295,13 @@
 sharkTopLevelBlock.cpp                  llvmHeaders.hpp
 sharkTopLevelBlock.cpp                  llvmValue.hpp
 sharkTopLevelBlock.cpp                  shark_globals.hpp
+sharkTopLevelBlock.cpp                  sharkCacheDecache.hpp
 sharkTopLevelBlock.cpp                  sharkTopLevelBlock.hpp
 sharkTopLevelBlock.cpp                  sharkBuilder.hpp
 sharkTopLevelBlock.cpp                  sharkConstant.hpp
 sharkTopLevelBlock.cpp                  sharkInliner.hpp
 sharkTopLevelBlock.cpp                  sharkRuntime.hpp
-sharkTopLevelBlock.cpp                  sharkState.inline.hpp
+sharkTopLevelBlock.cpp                  sharkState.hpp
 sharkTopLevelBlock.cpp                  sharkValue.hpp
 
 sharkTopLevelBlock.hpp                  allocation.hpp
@@ -300,7 +313,7 @@
 sharkTopLevelBlock.hpp                  sharkBlock.hpp
 sharkTopLevelBlock.hpp                  sharkBuilder.hpp
 sharkTopLevelBlock.hpp                  sharkFunction.hpp
-sharkTopLevelBlock.hpp                  sharkState.inline.hpp
+sharkTopLevelBlock.hpp                  sharkState.hpp
 sharkTopLevelBlock.hpp                  sharkValue.hpp
 
 sharkType.cpp                           arrayOop.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -888,7 +888,7 @@
 
 SharkState* SharkBlock::initial_current_state()
 {
-  return new SharkState(this, entry_state());
+  return entry_state()->copy();
 }
 
 int SharkBlock::switch_default_dest()
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -25,61 +25,32 @@
 
 class SharkState;
 
-class SharkBlock : public ResourceObj {
- public:
-  SharkBlock(SharkBuilder*     builder,
-             ciMethod*         target,
-             ciBytecodeStream* iter,
-             llvm::Value*      thread)
-    : _builder(builder),
-      _target(target),
-      _iter(iter),
-      _current_state(NULL),
-      _thread(thread) {}
+class SharkBlock : public SharkTargetInvariants {
+ protected:
+  SharkBlock(const SharkTargetInvariants* parent)
+    : SharkTargetInvariants(parent),
+      _iter(target()),
+      _current_state(NULL) {}
+
+  SharkBlock(const SharkCompileInvariants* parent, ciMethod* target)
+    : SharkTargetInvariants(parent, target),
+      _iter(target),
+      _current_state(NULL) {}
 
  private:
-  SharkBuilder*     _builder;
-  ciMethod*         _target;
-  ciBytecodeStream* _iter;
-  SharkState*       _current_state;
-  llvm::Value*      _thread;
+  ciBytecodeStream _iter;
+  SharkState*      _current_state;
 
  public:
-  SharkBuilder* builder() const
-  {
-    return _builder;
-  }
-  ciMethod* target() const
+  ciBytecodeStream* iter()
   {
-    return _target;
-  }
-  ciBytecodeStream* iter() const
-  {
-    return _iter;
-  }
-  llvm::Value* thread() const
-  {
-    return _thread;
+    return &_iter;
   }
-
-  // Target properties
- public:
-  int max_locals() const
-  {
-    return target()->max_locals();
-  }
-  int max_stack() const
-  {
-    return target()->max_stack();
-  }  
-  
-  // Bytecode stream
- public:
-  Bytecodes::Code bc() const
+  Bytecodes::Code bc()
   {
     return iter()->cur_bc();
   }
-  int bci() const
+  int bci()
   {
     return iter()->cur_bci();
   }
--- a/ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -34,20 +34,20 @@
   _pc_offset = builder()->code_buffer()->create_unique_offset();
   _oopmap = new OopMap(
     oopmap_slot_munge(function()->oopmap_frame_size()),
-    oopmap_slot_munge(function()->arg_size()));
+    oopmap_slot_munge(arg_size()));
   debug_info()->add_safepoint(pc_offset(), oopmap());
 }
 
-void SharkDecacher::start_stack(int num_slots, int max_slots)
+void SharkDecacher::start_stack(int stack_depth)
 {
   // Create the array we'll record our stack slots in
-  _exparray = new GrowableArray<ScopeValue*>(num_slots);
+  _exparray = new GrowableArray<ScopeValue*>(stack_depth);
 
   // Set the stack pointer
   function()->CreateStoreZeroStackPointer(
     builder()->CreatePtrToInt(
       function()->CreateAddressOfFrameEntry(
-        function()->stack_slots_offset() + max_slots - num_slots),
+        function()->stack_slots_offset() + max_stack() - stack_depth),
       SharkType::intptr_type()));
 }
 
@@ -123,10 +123,10 @@
     function()->CreateAddressOfFrameEntry(offset));
 }
   
-void SharkDecacher::start_locals(int num_locals)
+void SharkDecacher::start_locals()
 {
   // Create the array we'll record our local variables in
-  _locarray = new GrowableArray<ScopeValue*>(num_locals);}
+  _locarray = new GrowableArray<ScopeValue*>(max_locals());}
 
 void SharkDecacher::process_local_slot(int          index,
                                        SharkValue** addr,
@@ -158,7 +158,7 @@
   // Record the scope
   debug_info()->describe_scope(
     pc_offset(),
-    function()->target(),
+    target(),
     bci(),
     debug_info()->create_scope_values(locarray()),
     debug_info()->create_scope_values(exparray()),
--- a/ports/hotspot/src/share/vm/shark/sharkCacheDecache.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkCacheDecache.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -40,12 +40,6 @@
   SharkCacherDecacher(SharkFunction* function)
     : SharkStateScanner(function) {}
 
- protected:
-  SharkBuilder* builder() const
-  {
-    return function()->builder();
-  }  
-
   // Helper
  protected:
   static int adjusted_offset(SharkValue* value, int offset)
@@ -71,12 +65,6 @@
   }
 
  private:
-  DebugInformationRecorder* debug_info() const
-  {
-    return function()->debug_info();
-  }
-
- private:
   int                           _pc_offset;
   OopMap*                       _oopmap;
   GrowableArray<ScopeValue*>*   _exparray;
@@ -109,7 +97,7 @@
  protected:
   void start_frame();
 
-  void start_stack(int num_slots, int max_slots);
+  void start_stack(int stack_depth);
   void process_stack_slot(int index, SharkValue** value, int offset);
 
   void start_monitors(int num_monitors);
@@ -119,7 +107,7 @@
   void process_method_slot(llvm::Value** value, int offset);
   void process_pc_slot(int offset);
   
-  void start_locals(int num_locals);
+  void start_locals();
   void process_local_slot(int index, SharkValue** value, int offset);
 
   void end_frame();
--- a/ports/hotspot/src/share/vm/shark/sharkCompiler.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkCompiler.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -120,8 +120,7 @@
   builder()->set_code_buffer(&cb);
 
   // Compile the method
-  ciBytecodeStream iter(target);
-  SharkFunction function(this, name, flow, &iter);
+  SharkFunction function(this, env, flow, name);
 
   // Unhook the code buffer
   builder()->set_code_buffer(NULL);  
--- a/ports/hotspot/src/share/vm/shark/sharkFunction.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkFunction.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -39,7 +39,7 @@
   // Create the function
   _function = builder()->CreateFunction(name());
   entry->set_llvm_function(function());
-  compiler()->memory_manager()->set_entry_for_function(function(), entry);
+  memory_manager()->set_entry_for_function(function(), entry);
 
   // Get our arguments
   Function::arg_iterator ai = function()->arg_begin();
@@ -48,12 +48,13 @@
   Argument *base_pc = ai++;
   base_pc->setName("base_pc");
   builder()->code_buffer()->set_base_pc(base_pc);
-  _thread = ai++;
-  _thread->setName("thread");
+  Argument *thread = ai++;
+  thread->setName("thread");
+  set_thread(thread);
 
   // Create the list of blocks
   set_block_insertion_point(NULL);
-  _blocks = NEW_RESOURCE_ARRAY(SharkTopLevelBlock*, flow()->block_count());
+  _blocks = NEW_RESOURCE_ARRAY(SharkTopLevelBlock*, block_count());
   for (int i = 0; i < block_count(); i++) {
     ciTypeFlow::Block *b = flow()->pre_order_at(i);
 
@@ -76,14 +77,6 @@
       block(i)->initialize();
   }
 
-  // Initialize the monitors
-  _max_monitors = 0;  
-  if (target()->is_synchronized() || target()->uses_monitors()) {
-    for (int i = 0; i < block_count(); i++)
-      _max_monitors = MAX2(
-        _max_monitors, block(i)->ciblock()->monitor_count());
-  }
-  
   // Create the method preamble
   set_block_insertion_point(&function()->front());
   builder()->SetInsertPoint(CreateBlock());
@@ -98,7 +91,7 @@
 
   // Lock if necessary
   SharkState *entry_state = new SharkEntryState(start_block, method);
-  if (target()->is_synchronized()) {
+  if (is_synchronized()) {
     SharkTopLevelBlock *locker =
       new SharkTopLevelBlock(this, start_block->ciblock());
     locker->add_incoming(entry_state);
@@ -291,10 +284,11 @@
   return result;
 }
 
-class DeferredZeroCheck : public ResourceObj {
+class DeferredZeroCheck : public SharkTargetInvariants {
  public:
   DeferredZeroCheck(SharkTopLevelBlock* block, SharkValue* value)
-    : _block(block),
+    : SharkTargetInvariants(block),
+      _block(block),
       _value(value),
       _bci(block->bci()),
       _state(block->current_state()->copy()),
@@ -339,10 +333,6 @@
   }
 
  public:
-  SharkBuilder* builder() const
-  {
-    return block()->builder();
-  }
   SharkFunction* function() const
   {
     return block()->function();
--- a/ports/hotspot/src/share/vm/shark/sharkFunction.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkFunction.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -24,105 +24,46 @@
  */
 
 class SharkTopLevelBlock;
-
 class DeferredZeroCheck;
 
-class SharkFunction : public StackObj {
+class SharkFunction : public SharkTargetInvariants {
  public:
-  SharkFunction(SharkCompiler*    compiler,
-                const char*       name,
-                ciTypeFlow*       flow,
-                ciBytecodeStream* iter)
-    : _compiler(compiler),
-      _name(name),
-      _flow(flow),
-      _iter(iter)
-  { initialize(); }
+  SharkFunction(SharkCompiler* compiler,
+                ciEnv*         env,
+                ciTypeFlow*    flow,
+                const char*    name)
+    : SharkTargetInvariants(compiler, env, flow), _name(name) { initialize(); }
 
  private:
   void initialize();
 
  private:
-  SharkCompiler*                    _compiler;
   const char*                       _name;
-  ciTypeFlow*                       _flow;
-  ciBytecodeStream*                 _iter;
   llvm::Function*                   _function;
   SharkTopLevelBlock**              _blocks;
-  llvm::Value*                      _thread;
-  int                               _max_monitors;
   GrowableArray<DeferredZeroCheck*> _deferred_zero_checks;
 
- public:  
-  SharkCompiler* compiler() const
-  {
-    return _compiler;
-  }
+ public:
   const char* name() const
   {
     return _name;
-  }
-  ciTypeFlow* flow() const
-  {
-    return _flow;
-  }
-  ciBytecodeStream* iter() const
-  {
-    return _iter;
-  }
+  }  
   llvm::Function* function() const
   {
     return _function;
   }
-  SharkTopLevelBlock* block(int i) const
-  {
-    return _blocks[i];
-  }
-  llvm::Value* thread() const
-  {
-    return _thread;
-  }
-  int max_monitors() const
-  {
-    return _max_monitors;
-  }
-  GrowableArray<DeferredZeroCheck*>* deferred_zero_checks()
-  {
-    return &_deferred_zero_checks;
-  }
-
- public:
-  SharkBuilder* builder() const
-  {
-    return compiler()->builder();
-  }
-  int arg_size() const
-  {
-    return target()->arg_size();
-  }
   int block_count() const
   {
     return flow()->block_count();
   }
-  DebugInformationRecorder *debug_info() const
-  {
-    return env()->debug_info();
-  }
-  ciEnv* env() const
-  {
-    return flow()->env();
-  }
-  int max_locals() const
+  SharkTopLevelBlock* block(int i) const
   {
-    return flow()->max_locals();
+    assert(i < block_count(), "should be");
+    return _blocks[i];
   }
-  int max_stack() const
+  GrowableArray<DeferredZeroCheck*>* deferred_zero_checks()
   {
-    return flow()->max_stack();
-  }
-  ciMethod* target() const
-  {
-    return flow()->method();
+    return &_deferred_zero_checks;
   }
 
   // Block management
--- a/ports/hotspot/src/share/vm/shark/sharkInliner.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkInliner.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -30,11 +30,8 @@
 
 class SharkInlineBlock : public SharkBlock {
  public:
-  SharkInlineBlock(ciMethod*         target,
-                   SharkState*       state,
-                   ciBytecodeStream* iter,
-                   Value*            thread)
-    : SharkBlock(state->builder(), target, iter, thread),
+  SharkInlineBlock(ciMethod* target, SharkState* state)
+    : SharkBlock(state, target),
       _outer_state(state),
       _entry_state(new SharkState(this))
   {
@@ -80,17 +77,15 @@
 
 class SharkInlinerHelper : public StackObj {
  public:
-  SharkInlinerHelper(ciMethod* target, SharkState* entry_state, Value* thread)
+  SharkInlinerHelper(ciMethod* target, SharkState* entry_state)
     : _target(target),
       _entry_state(entry_state),
-      _iter(target),
-      _thread(thread) {}
+      _iter(target) {}
 
  private:
   ciBytecodeStream _iter;
   SharkState*      _entry_state;
   ciMethod*        _target;
-  Value*           _thread;
   
  public:
   ciBytecodeStream* iter()
@@ -105,10 +100,6 @@
   {
     return _target;
   }
-  Value* thread() const
-  {
-    return _thread;
-  }
 
  public:
   Bytecodes::Code bc()
@@ -207,8 +198,7 @@
  public:
   void do_inline()
   {
-    (new SharkInlineBlock(
-           target(), entry_state(), iter(), thread()))->emit_IR();
+    (new SharkInlineBlock(target(), entry_state()))->emit_IR();
   }
 };
 
@@ -770,17 +760,15 @@
   return true;
 }
 
-bool SharkInliner::attempt_inline(ciMethod*   target,
-                                  SharkState* state,
-                                  Value*      thread)
+bool SharkInliner::attempt_inline(ciMethod *target, SharkState *state)
 {
   if (SharkIntrinsics::is_intrinsic(target)) {
-    SharkIntrinsics::inline_intrinsic(target, state, thread);
+    SharkIntrinsics::inline_intrinsic(target, state);
     return true;
   }
 
   if (may_be_inlinable(target)) {
-    SharkInlinerHelper inliner(target, state, thread);
+    SharkInlinerHelper inliner(target, state);
     if (inliner.is_inlinable()) {
       inliner.do_inline();
       return true;
--- a/ports/hotspot/src/share/vm/shark/sharkInliner.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkInliner.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -25,9 +25,7 @@
 
 class SharkInliner : public AllStatic {
  public:
-  static bool attempt_inline(ciMethod*    target,
-                             SharkState*  state,
-                             llvm::Value* thread);
+  static bool attempt_inline(ciMethod* target, SharkState* state);
                       
  private:
   static bool may_be_inlinable(ciMethod* target);
--- a/ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -75,67 +75,71 @@
   return false;
 }
 
-void SharkIntrinsics::inline_intrinsic(ciMethod*   target,
-                                       SharkState* state,
-                                       Value*      thread)
+void SharkIntrinsics::inline_intrinsic(ciMethod *target, SharkState *state)
 {
-  switch (target->intrinsic_id()) {
+  SharkIntrinsics intrinsic(state, target);
+  intrinsic.do_intrinsic();
+}
+
+void SharkIntrinsics::do_intrinsic()
+{
+  switch (target()->intrinsic_id()) {
     // java.lang.Math
   case vmIntrinsics::_min:
-    do_Math_minmax(state, llvm::ICmpInst::ICMP_SLE);
+    do_Math_minmax(llvm::ICmpInst::ICMP_SLE);
     break;
   case vmIntrinsics::_max:
-    do_Math_minmax(state, llvm::ICmpInst::ICMP_SGE);
+    do_Math_minmax(llvm::ICmpInst::ICMP_SGE);
     break;
   case vmIntrinsics::_dabs:
-    do_Math_1to1(state, SharkRuntime::fabs());
+    do_Math_1to1(SharkRuntime::fabs());
     break;
   case vmIntrinsics::_dsin:
-    do_Math_1to1(state, state->builder()->llvm_sin_fn());
+    do_Math_1to1(builder()->llvm_sin_fn());
     break;
   case vmIntrinsics::_dcos:
-    do_Math_1to1(state, state->builder()->llvm_cos_fn());
+    do_Math_1to1(builder()->llvm_cos_fn());
     break;
   case vmIntrinsics::_dtan:
-    do_Math_1to1(state, SharkRuntime::tan());
+    do_Math_1to1(SharkRuntime::tan());
     break;
   case vmIntrinsics::_datan2:
-    do_Math_2to1(state, SharkRuntime::atan2());
+    do_Math_2to1(SharkRuntime::atan2());
     break;
   case vmIntrinsics::_dsqrt:
-    do_Math_1to1(state, state->builder()->llvm_sqrt_fn());
+    do_Math_1to1(builder()->llvm_sqrt_fn());
     break;
   case vmIntrinsics::_dlog:
-    do_Math_1to1(state, state->builder()->llvm_log_fn());
+    do_Math_1to1(builder()->llvm_log_fn());
     break;
   case vmIntrinsics::_dlog10:
-    do_Math_1to1(state, state->builder()->llvm_log10_fn());
+    do_Math_1to1(builder()->llvm_log10_fn());
     break;
   case vmIntrinsics::_dpow:
-    do_Math_2to1(state, state->builder()->llvm_pow_fn());
+    do_Math_2to1(builder()->llvm_pow_fn());
     break;
   case vmIntrinsics::_dexp:
-    do_Math_1to1(state, state->builder()->llvm_exp_fn());
+    do_Math_1to1(builder()->llvm_exp_fn());
     break;
 
     // java.lang.Object
   case vmIntrinsics::_getClass:
-    do_Object_getClass(state);
+    do_Object_getClass();
     break;
 
     // java.lang.System
   case vmIntrinsics::_currentTimeMillis:
-    do_System_currentTimeMillis(state);
+    do_System_currentTimeMillis();
     break;
 
     // java.lang.Thread
   case vmIntrinsics::_currentThread:
-    do_Thread_currentThread(state, thread);
+    do_Thread_currentThread();
     break;
     
     // sun.misc.Unsafe
   case vmIntrinsics::_compareAndSwapInt:
-    do_Unsafe_compareAndSwapInt(state);
+    do_Unsafe_compareAndSwapInt();
     break;
 
   default:
@@ -143,85 +147,83 @@
   }
 }
 
-void SharkIntrinsics::do_Math_minmax(SharkState *state, ICmpInst::Predicate p)
+void SharkIntrinsics::do_Math_minmax(ICmpInst::Predicate p)
 {
-  SharkBuilder *builder = state->builder();
-
   // Pop the arguments
-  SharkValue *sb = state->pop();
-  SharkValue *sa = state->pop();
+  SharkValue *sb = state()->pop();
+  SharkValue *sa = state()->pop();
   Value *a = sa->jint_value();
   Value *b = sb->jint_value();  
 
   // Perform the test
-  BasicBlock *ip       = builder->GetBlockInsertionPoint();
-  BasicBlock *return_a = builder->CreateBlock(ip, "return_a");
-  BasicBlock *return_b = builder->CreateBlock(ip, "return_b");
-  BasicBlock *done     = builder->CreateBlock(ip, "done");
+  BasicBlock *ip       = builder()->GetBlockInsertionPoint();
+  BasicBlock *return_a = builder()->CreateBlock(ip, "return_a");
+  BasicBlock *return_b = builder()->CreateBlock(ip, "return_b");
+  BasicBlock *done     = builder()->CreateBlock(ip, "done");
 
-  builder->CreateCondBr(builder->CreateICmp(p, a, b), return_a, return_b);
+  builder()->CreateCondBr(builder()->CreateICmp(p, a, b), return_a, return_b);
 
-  builder->SetInsertPoint(return_a);
-  builder->CreateBr(done);
+  builder()->SetInsertPoint(return_a);
+  builder()->CreateBr(done);
 
-  builder->SetInsertPoint(return_b);
-  builder->CreateBr(done);
+  builder()->SetInsertPoint(return_b);
+  builder()->CreateBr(done);
 
-  builder->SetInsertPoint(done);
-  PHINode *phi = builder->CreatePHI(a->getType(), "result");
+  builder()->SetInsertPoint(done);
+  PHINode *phi = builder()->CreatePHI(a->getType(), "result");
   phi->addIncoming(a, return_a);
   phi->addIncoming(b, return_b);
 
   // Push the result
-  state->push(
+  state()->push(
     SharkValue::create_jint(
       phi,
       sa->zero_checked() && sb->zero_checked()));
 }
 
-void SharkIntrinsics::do_Math_1to1(SharkState *state, Constant *function)
+void SharkIntrinsics::do_Math_1to1(Constant *function)
 {
-  SharkValue *empty = state->pop();
+  SharkValue *empty = state()->pop();
   assert(empty == NULL, "should be");
-  state->push(
+  state()->push(
     SharkValue::create_jdouble(
-      state->builder()->CreateCall(function, state->pop()->jdouble_value())));
-  state->push(NULL);
+      builder()->CreateCall(
+        function, state()->pop()->jdouble_value())));
+  state()->push(NULL);
 }
 
-void SharkIntrinsics::do_Math_2to1(SharkState *state, Constant *function)
+void SharkIntrinsics::do_Math_2to1(Constant *function)
 {
-  SharkValue *empty = state->pop();
+  SharkValue *empty = state()->pop();
+  assert(empty == NULL, "should be");
+  Value *y = state()->pop()->jdouble_value();
+  empty = state()->pop();
   assert(empty == NULL, "should be");
-  Value *y = state->pop()->jdouble_value();
-  empty = state->pop();
-  assert(empty == NULL, "should be");
-  Value *x = state->pop()->jdouble_value();
+  Value *x = state()->pop()->jdouble_value();
 
-  state->push(
-    SharkValue::create_jdouble(state->builder()->CreateCall2(function, x, y)));
-  state->push(NULL);
+  state()->push(
+    SharkValue::create_jdouble(
+      builder()->CreateCall2(function, x, y)));
+  state()->push(NULL);
 }
 
-void SharkIntrinsics::do_Object_getClass(SharkState *state)
+void SharkIntrinsics::do_Object_getClass()
 {
-  SharkBuilder *builder = state->builder();
-
-  Value *klass = builder->CreateValueOfStructEntry(
-    state->pop()->jobject_value(),
+  Value *klass = builder()->CreateValueOfStructEntry(
+    state()->pop()->jobject_value(),
     in_ByteSize(oopDesc::klass_offset_in_bytes()),
     SharkType::jobject_type(),
     "klass");
 
-  Value *klass_part = builder->CreateAddressOfStructEntry(
+  Value *klass_part = builder()->CreateAddressOfStructEntry(
     klass,
     in_ByteSize(klassOopDesc::klass_part_offset_in_bytes()),
     SharkType::klass_type(),
     "klass_part");
 
-  state->push(
+  state()->push(
     SharkValue::create_jobject(
-      builder->CreateValueOfStructEntry(
+      builder()->CreateValueOfStructEntry(
         klass_part,
         in_ByteSize(Klass::java_mirror_offset_in_bytes()),
         SharkType::oop_type(),
@@ -229,59 +231,57 @@
       true));
 }
 
-void SharkIntrinsics::do_System_currentTimeMillis(SharkState *state)
+void SharkIntrinsics::do_System_currentTimeMillis()
 {
-  state->push(
+  state()->push(
     SharkValue::create_jlong(
-      state->builder()->CreateCall(SharkRuntime::current_time_millis()),
+      builder()->CreateCall(SharkRuntime::current_time_millis()),
       false));
-  state->push(NULL);
+  state()->push(NULL);
 }
 
-void SharkIntrinsics::do_Thread_currentThread(SharkState *state, Value *thread)
+void SharkIntrinsics::do_Thread_currentThread()
 {
-  state->push(
+  state()->push(
     SharkValue::create_jobject(
-      state->builder()->CreateValueOfStructEntry(
-        thread, JavaThread::threadObj_offset(),
+      builder()->CreateValueOfStructEntry(
+        thread(), JavaThread::threadObj_offset(),
         SharkType::jobject_type(),
         "threadObj"),
       true));
 }
 
-void SharkIntrinsics::do_Unsafe_compareAndSwapInt(SharkState *state)
+void SharkIntrinsics::do_Unsafe_compareAndSwapInt()
 {
-  SharkBuilder *builder = state->builder();
-
   // Pop the arguments
-  Value *x      = state->pop()->jint_value();
-  Value *e      = state->pop()->jint_value();
-  SharkValue *empty = state->pop();
+  Value *x      = state()->pop()->jint_value();
+  Value *e      = state()->pop()->jint_value();
+  SharkValue *empty = state()->pop();
   assert(empty == NULL, "should be");
-  Value *offset = state->pop()->jlong_value();
-  Value *object = state->pop()->jobject_value();
-  Value *unsafe = state->pop()->jobject_value();
+  Value *offset = state()->pop()->jlong_value();
+  Value *object = state()->pop()->jobject_value();
+  Value *unsafe = state()->pop()->jobject_value();
 
   // Convert the offset
-  offset = builder->CreateCall(
+  offset = builder()->CreateCall(
     SharkRuntime::unsafe_field_offset_to_byte_offset(),
     offset);
 
   // Locate the field
-  Value *addr = builder->CreateIntToPtr(
-    builder->CreateAdd(
-      builder->CreatePtrToInt(object, SharkType::intptr_type()),
-      builder->CreateIntCast(offset, SharkType::intptr_type(), true)),
+  Value *addr = builder()->CreateIntToPtr(
+    builder()->CreateAdd(
+      builder()->CreatePtrToInt(object, SharkType::intptr_type()),
+      builder()->CreateIntCast(offset, SharkType::intptr_type(), true)),
     PointerType::getUnqual(SharkType::jint_type()),
     "addr");
 
   // Perform the operation
-  Value *result = builder->CreateCmpxchgInt(x, addr, e);
+  Value *result = builder()->CreateCmpxchgInt(x, addr, e);
 
   // Push the result
-  state->push(
+  state()->push(
     SharkValue::create_jint(
-      builder->CreateIntCast(
-        builder->CreateICmpEQ(result, e), SharkType::jint_type(), true),
+      builder()->CreateIntCast(
+        builder()->CreateICmpEQ(result, e), SharkType::jint_type(), true),
       false));
 }
--- a/ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -23,19 +23,33 @@
  *
  */
 
-class SharkIntrinsics : public AllStatic {
+class SharkIntrinsics : public SharkTargetInvariants {
  public:
   static bool is_intrinsic(ciMethod* target);
-  static void inline_intrinsic(ciMethod*    target,
-                               SharkState*  state,
-                               llvm::Value* thread);
+  static void inline_intrinsic(ciMethod* target, SharkState* state);
+
+ private:
+  SharkIntrinsics(SharkState* state, ciMethod* target)
+    : SharkTargetInvariants(state, target), _state(state) {}
+
+ private:
+  SharkState* _state;
 
  private:
-  static void do_Math_minmax(SharkState* state, llvm::ICmpInst::Predicate p);
-  static void do_Math_1to1(SharkState* state, llvm::Constant* function);
-  static void do_Math_2to1(SharkState* state, llvm::Constant* function);
-  static void do_Object_getClass(SharkState* state);
-  static void do_System_currentTimeMillis(SharkState* state);
-  static void do_Thread_currentThread(SharkState* state, llvm::Value* thread);
-  static void do_Unsafe_compareAndSwapInt(SharkState* state);
+  SharkState* state() const
+  {
+    return _state;
+  }
+
+ private:
+  void do_intrinsic();
+
+ private:
+  void do_Math_minmax(llvm::ICmpInst::Predicate p);
+  void do_Math_1to1(llvm::Constant* function);
+  void do_Math_2to1(llvm::Constant* function);
+  void do_Object_getClass();
+  void do_System_currentTimeMillis();
+  void do_Thread_currentThread();
+  void do_Unsafe_compareAndSwapInt();
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ports/hotspot/src/share/vm/shark/sharkInvariants.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -0,0 +1,38 @@
+/*
+ * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2008, 2009 Red Hat, Inc.
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+
+#include "incls/_precompiled.incl"
+#include "incls/_sharkInvariants.cpp.incl"
+
+int SharkTargetInvariants::count_monitors()
+{
+  int result = 0;
+  if (is_synchronized() || target()->has_monitor_bytecodes()) {
+    for (int i = 0; i < flow()->block_count(); i++) {
+      result = MAX2(result, flow()->pre_order_at(i)->monitor_count());
+    }
+  }
+  return result;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ports/hotspot/src/share/vm/shark/sharkInvariants.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -0,0 +1,186 @@
+/*
+ * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2008, 2009 Red Hat, Inc.
+ * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+
+// Base classes used to track various values through the compilation.
+// SharkCompileInvariants is used to track values which remain the
+// same for the top-level method and any inlined methods it may have
+// (ie for the whole compilation).  SharkTargetInvariants is used to
+// track values which differ between methods.
+
+class SharkCompileInvariants : public ResourceObj {
+ protected:
+  SharkCompileInvariants(SharkCompiler* compiler, ciEnv* env)
+    : _compiler(compiler),
+      _env(env),
+      _thread(NULL) {}
+
+  SharkCompileInvariants(const SharkCompileInvariants* parent)
+    : _compiler(parent->_compiler),
+      _env(parent->_env),
+      _thread(parent->_thread) {}
+
+ private:
+  SharkCompiler* _compiler;
+  ciEnv*         _env;
+  llvm::Value*   _thread;
+
+  // The SharkCompiler that is compiling this method.  Holds the
+  // classes that form the interface with LLVM (the builder, the
+  // module, the memory manager, etc) and provides the compile()
+  // method to convert LLVM functions to native code.
+ protected:
+  SharkCompiler* compiler() const
+  {
+    return _compiler;
+  }
+
+  // Top-level broker for HotSpot's Compiler Interface.
+  //
+  // Its main purpose is to allow the various CI classes to access
+  // oops in the VM without having to worry about safepointing.  In
+  // addition to this it acts as a holder for various recorders and
+  // memory allocators.
+  //
+  // Accessing this directly is kind of ugly, so it's private.  Add
+  // new accessors below if you need something from it.
+ private:
+  ciEnv* env() const
+  {
+    return _env;
+  }
+
+  // Pointer to this thread's JavaThread object.  This is not
+  // available until a short way into SharkFunction creation
+  // so a setter is required.  Assertions are used to enforce
+  // invariance.
+ protected:
+  llvm::Value* thread() const
+  {
+    assert(_thread != NULL, "thread not available");
+    return _thread;
+  }
+  void set_thread(llvm::Value* thread)
+  {
+    assert(_thread == NULL, "thread already set");
+    _thread = thread;
+  }
+  
+  // Objects that handle various aspects of the compilation.
+ protected:
+  SharkBuilder* builder() const
+  {
+    return compiler()->builder();
+  }
+  SharkMemoryManager* memory_manager() const
+  {
+    return compiler()->memory_manager();
+  }  
+  DebugInformationRecorder* debug_info() const
+  {
+    return env()->debug_info();
+  }
+  Dependencies* dependencies() const
+  {
+    return env()->dependencies();
+  }
+
+  // That well-known class...
+ protected:
+  ciInstanceKlass* java_lang_Object_klass() const
+  {
+    return env()->Object_klass();
+  }
+};
+
+class SharkTargetInvariants : public SharkCompileInvariants {
+ protected:
+  SharkTargetInvariants(SharkCompiler* compiler, ciEnv* env, ciTypeFlow* flow)
+    : SharkCompileInvariants(compiler, env),
+      _target(flow->method()),
+      _flow(flow),
+      _max_monitors(count_monitors()) {}
+
+  SharkTargetInvariants(const SharkCompileInvariants* parent, ciMethod* target)
+    : SharkCompileInvariants(parent),
+      _target(target),
+      _flow(NULL),
+      _max_monitors(count_monitors()) {}
+
+  SharkTargetInvariants(const SharkTargetInvariants* parent)
+    : SharkCompileInvariants(parent),
+      _target(parent->_target),
+      _flow(parent->_flow),
+      _max_monitors(parent->_max_monitors) {}
+
+ private:
+  int count_monitors();
+
+ private:
+  ciMethod*   _target;
+  ciTypeFlow* _flow;
+  int         _max_monitors;
+
+  // The method being compiled.
+ protected:
+  ciMethod* target() const
+  {
+    return _target;
+  }
+
+  // Typeflow analysis of the method being compiled.
+ protected:
+  ciTypeFlow* flow() const
+  {
+    assert(_flow != NULL, "typeflow not available");
+    return _flow;
+  }
+
+  // Properties of the method.
+ protected:
+  int max_locals() const
+  {
+    return target()->max_locals();
+  }
+  int max_stack() const
+  {
+    return target()->max_stack();
+  }
+  int max_monitors() const
+  {
+    return _max_monitors;
+  }
+  int arg_size() const
+  {
+    return target()->arg_size();
+  }
+  bool is_static() const
+  {
+    return target()->is_static();
+  }
+  bool is_synchronized() const
+  {
+    return target()->is_synchronized();
+  }
+};
--- a/ports/hotspot/src/share/vm/shark/sharkState.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkState.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -28,26 +28,6 @@
 
 using namespace llvm;
 
-SharkState::SharkState(SharkBlock* block, SharkFunction* function)
-  : _block(block),
-    _function(function),
-    _method(NULL),
-    _oop_tmp(NULL),
-    _has_safepointed(false)
-{
-  initialize(NULL);
-}
-
-SharkState::SharkState(SharkBlock* block, const SharkState* state)
-  : _block(block),
-    _function(state->function()),
-    _method(state->method()),
-    _oop_tmp(state->oop_tmp()),
-    _has_safepointed(state->has_safepointed())
-{
-  initialize(state);
-}
-
 void SharkState::initialize(const SharkState *state)
 {
   _locals = NEW_RESOURCE_ARRAY(SharkValue*, max_locals());
@@ -78,10 +58,7 @@
 
 bool SharkState::equal_to(SharkState *other)
 {
-  if (block() != other->block())
-    return false;
-
-  if (function() != other->function())
+  if (target() != other->target())
     return false;
 
   if (method() != other->method())
@@ -216,57 +193,8 @@
   }
 }
 
-void SharkState::decache_for_Java_call(ciMethod* callee)
-{
-  assert(function() && method(), "you cannot decache here");
-  SharkJavaCallDecacher(function(), block()->bci(), callee).scan(this);
-  pop(callee->arg_size());
-}
-
-void SharkState::cache_after_Java_call(ciMethod* callee)
-{
-  assert(function() && method(), "you cannot cache here");
-  if (callee->return_type()->size()) {
-    ciType *type;
-    switch (callee->return_type()->basic_type()) {
-    case T_BOOLEAN:
-    case T_BYTE:
-    case T_CHAR:
-    case T_SHORT:
-      type = ciType::make(T_INT);
-      break;
-
-    default:
-      type = callee->return_type();
-    }
-
-    push(SharkValue::create_generic(type, NULL, false));
-    if (type->is_two_word())
-      push(NULL);
-  }
-  SharkJavaCallCacher(function(), callee).scan(this);
-}
-
-void SharkState::decache_for_VM_call()
-{
-  assert(function() && method(), "you cannot decache here");
-  SharkVMCallDecacher(function(), block()->bci()).scan(this);
-}
-
-void SharkState::cache_after_VM_call()
-{
-  assert(function() && method(), "you cannot cache here");
-  SharkVMCallCacher(function()).scan(this);
-}
-
-void SharkState::decache_for_trap()
-{
-  assert(function() && method(), "you cannot decache here");
-  SharkTrapDecacher(function(), block()->bci()).scan(this);
-}
-
 SharkEntryState::SharkEntryState(SharkTopLevelBlock* block, Value* method)
-  : SharkState(block, block->function())
+  : SharkState(block)
 {
   assert(!block->stack_depth_at_entry(), "entry block shouldn't have stack");
 
@@ -282,11 +210,10 @@
     case T_DOUBLE:
     case T_OBJECT:
     case T_ARRAY:
-      if (i >= function()->arg_size()) {
+      if (i >= arg_size()) {
         ShouldNotReachHere();
       }
-      value = SharkValue::create_generic(
-        type, NULL, i == 0 && !function()->target()->is_static());
+      value = SharkValue::create_generic(type, NULL, i == 0 && !is_static());
       break;
     
     case ciTypeFlow::StateVector::T_BOTTOM:
@@ -301,11 +228,11 @@
     }
     set_local(i, value);
   }
-  SharkFunctionEntryCacher(function(), method).scan(this);  
+  SharkFunctionEntryCacher(block->function(), method).scan(this);  
 }
 
 SharkPHIState::SharkPHIState(SharkTopLevelBlock* block)
-  : SharkState(block, block->function())
+  : SharkState(block), _block(block)
 {
   BasicBlock *saved_insert_point = builder()->GetInsertBlock();
   builder()->SetInsertPoint(block->entry_block());
@@ -407,7 +334,7 @@
   }
 
   // Expression stack
-  int stack_depth = ((SharkTopLevelBlock *) block())->stack_depth_at_entry();
+  int stack_depth = block()->stack_depth_at_entry();
   assert(stack_depth == incoming_state->stack_depth(), "should be");
   for (int i = 0; i < stack_depth; i++) {
     assert((stack(i) == NULL) == (incoming_state->stack(i) == NULL), "oops");
--- a/ports/hotspot/src/share/vm/shark/sharkState.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkState.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -23,44 +23,31 @@
  *
  */
 
-class SharkBlock;
-class SharkFunction;
-class SharkTopLevelBlock;
+class SharkState : public SharkTargetInvariants {
+ public:
+  SharkState(const SharkTargetInvariants* parent)
+    : SharkTargetInvariants(parent),
+      _method(NULL),
+      _oop_tmp(NULL),
+      _has_safepointed(false) { initialize(NULL); }
 
-class SharkState : public ResourceObj {
- public:
-  SharkState(SharkBlock* block, SharkFunction* function = NULL);
-  SharkState(SharkBlock* block, const SharkState* state);
+  SharkState(const SharkState* state)
+    : SharkTargetInvariants(state),
+      _method(state->_method),
+      _oop_tmp(state->_oop_tmp),
+      _has_safepointed(state->_has_safepointed) { initialize(state); }
 
  private:
   void initialize(const SharkState* state);
 
  private:
-  SharkBlock*      _block;
-  SharkFunction*   _function;
-  llvm::Value*     _method;
-  SharkValue**     _locals;
-  SharkValue**     _stack;
-  SharkValue**     _sp;
-  int              _num_monitors;
-  llvm::Value*     _oop_tmp;
-  bool             _has_safepointed;
-
- public:
-  SharkBlock *block() const
-  {
-    return _block;
-  }
-  SharkFunction *function() const
-  {
-    return _function;
-  }
-  
- public:
-  inline SharkBuilder* builder() const;
-  inline int max_locals() const;
-  inline int max_stack() const;
-  inline int max_monitors() const;
+  llvm::Value* _method;
+  SharkValue** _locals;
+  SharkValue** _stack;
+  SharkValue** _sp;
+  int          _num_monitors;
+  llvm::Value* _oop_tmp;
+  bool         _has_safepointed;
 
   // Method
  public:
@@ -125,11 +112,6 @@
     assert(stack_depth() > 0, "stack underrun");
     return *(--_sp);
   }
-  void pop(int slots)
-  {
-    assert(stack_depth() >= slots, "stack underrun");
-    _sp -= slots;
-  }
 
   // Monitors
  public:
@@ -176,7 +158,7 @@
  public:
   SharkState* copy() const
   {
-    return new SharkState(block(), this);
+    return new SharkState(this);
   }
   void merge(SharkState*       other,
              llvm::BasicBlock* other_block,
@@ -185,15 +167,9 @@
   // Value replacement
  public:
   void replace_all(SharkValue* old_value, SharkValue* new_value);
+};
 
-  // Cache and decache
- public:
-  void decache_for_Java_call(ciMethod* callee);
-  void cache_after_Java_call(ciMethod* callee);
-  void decache_for_VM_call();
-  void cache_after_VM_call();
-  void decache_for_trap();
-};
+class SharkTopLevelBlock;
 
 // SharkEntryState objects are used to manage the state
 // that the method will be entered with.
@@ -209,6 +185,15 @@
  public:
   SharkPHIState(SharkTopLevelBlock* block);
 
+ private:
+  SharkTopLevelBlock* _block;
+
+ private:
+  SharkTopLevelBlock* block() const
+  {
+    return _block;
+  }
+
  public:
   void add_incoming(SharkState* incoming_state); 
 };
--- a/ports/hotspot/src/share/vm/shark/sharkState.inline.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
- * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
- * Copyright 2008, 2009 Red Hat, Inc.
- * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- */
-
-inline SharkBuilder* SharkState::builder() const
-{
-  return block()->builder();
-}  
-  
-inline int SharkState::max_locals() const
-{
-  return block()->max_locals();
-}
-
-inline int SharkState::max_stack() const
-{
-  return block()->max_stack();
-}
-
-inline int SharkState::max_monitors() const
-{
-  return function()->max_monitors();
-}
--- a/ports/hotspot/src/share/vm/shark/sharkStateScanner.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkStateScanner.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -34,13 +34,13 @@
 
   // Expression stack
   stack_integrity_checks(state);
-  start_stack(state->stack_depth(), state->max_stack());
+  start_stack(state->stack_depth());
   for (int i = state->stack_depth() - 1; i >= 0; i--) {
     process_stack_slot(
       i,
       state->stack_addr(i),
       function()->stack_slots_offset() +
-        i + state->max_stack() - state->stack_depth());
+        i + max_stack() - state->stack_depth());
   }
   end_stack();
 
@@ -64,12 +64,12 @@
 
   // Local variables
   locals_integrity_checks(state);
-  start_locals(state->max_locals());
-  for (int i = 0; i < state->max_locals(); i++) {
+  start_locals();
+  for (int i = 0; i < max_locals(); i++) {
     process_local_slot(
       i,
       state->local_addr(i),
-      function()->locals_slots_offset() + state->max_locals() - 1 - i);
+      function()->locals_slots_offset() + max_locals() - 1 - i);
   }
   end_locals();
 
@@ -92,7 +92,7 @@
   
 void SharkStateScanner::locals_integrity_checks(SharkState* state)
 {
-  for (int i = 0; i < state->max_locals(); i++) {
+  for (int i = 0; i < max_locals(); i++) {
     if (state->local(i)) {
       if (state->local(i)->is_two_word())
         assert(state->local(i + 1) == NULL, "should be");
--- a/ports/hotspot/src/share/vm/shark/sharkStateScanner.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkStateScanner.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -25,10 +25,10 @@
 
 class SharkState;
 
-class SharkStateScanner : public StackObj {
+class SharkStateScanner : public SharkTargetInvariants {
  protected:
   SharkStateScanner(SharkFunction* function)
-    : _function(function) {}
+    : SharkTargetInvariants(function), _function(function) {}
 
  private:
   SharkFunction* _function;
@@ -49,7 +49,7 @@
  protected:
   virtual void start_frame()                                                 {}
 
-  virtual void start_stack(int num_slots, int max_slots)                     {}
+  virtual void start_stack(int stack_depth)                                  {}
   virtual void process_stack_slot(int index, SharkValue** value, int offset) {}
   virtual void end_stack()                                                   {}
 
@@ -63,7 +63,7 @@
   virtual void process_pc_slot(int offset)                                   {}
   virtual void end_frame_header()                                            {}
   
-  virtual void start_locals(int num_locals)                                  {}
+  virtual void start_locals()                                                {}
   virtual void process_local_slot(int index, SharkValue** value, int offset) {}
   virtual void end_locals()                                                  {}
 
@@ -71,6 +71,6 @@
 
   // Integrity checks
  private:
-  static void stack_integrity_checks(SharkState* state) PRODUCT_RETURN;
-  static void locals_integrity_checks(SharkState* state) PRODUCT_RETURN;
+  void stack_integrity_checks(SharkState* state) PRODUCT_RETURN;
+  void locals_integrity_checks(SharkState* state) PRODUCT_RETURN;
 };
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Thu Jun 18 12:00:59 2009 -0400
@@ -191,6 +191,49 @@
   _entry_block = function()->CreateBlock(name);
 }
 
+void SharkTopLevelBlock::decache_for_Java_call(ciMethod *callee)
+{
+  SharkJavaCallDecacher(function(), bci(), callee).scan(current_state());
+  for (int i = 0; i < callee->arg_size(); i++)
+    xpop();
+}
+
+void SharkTopLevelBlock::cache_after_Java_call(ciMethod *callee)
+{
+  if (callee->return_type()->size()) {
+    ciType *type;
+    switch (callee->return_type()->basic_type()) {
+    case T_BOOLEAN:
+    case T_BYTE:
+    case T_CHAR:
+    case T_SHORT:
+      type = ciType::make(T_INT);
+      break;
+
+    default:
+      type = callee->return_type();
+    }
+
+    push(SharkValue::create_generic(type, NULL, false));
+  }
+  SharkJavaCallCacher(function(), callee).scan(current_state());
+}
+
+void SharkTopLevelBlock::decache_for_VM_call()
+{
+  SharkVMCallDecacher(function(), bci()).scan(current_state());
+}
+
+void SharkTopLevelBlock::cache_after_VM_call()
+{
+  SharkVMCallCacher(function()).scan(current_state());
+}
+
+void SharkTopLevelBlock::decache_for_trap()
+{
+  SharkTrapDecacher(function(), bci()).scan(current_state());
+}
+
 void SharkTopLevelBlock::emit_IR()
 {
   builder()->SetInsertPoint(entry_block());
@@ -508,7 +551,7 @@
 
 void SharkTopLevelBlock::do_trap(int trap_request)
 {
-  current_state()->decache_for_trap();
+  decache_for_trap();
   builder()->CreateCall2(
     SharkRuntime::uncommon_trap(),
     thread(),
@@ -828,7 +871,7 @@
 
   // Array methods are all inherited from Object and are monomorphic
   if (receiver_type->is_array_klass() &&
-      dest_method->holder() == function()->env()->Object_klass())
+      dest_method->holder() == java_lang_Object_klass())
     return dest_method;
 
   // All other interesting cases are instance classes
@@ -876,7 +919,7 @@
   // us dependent on that target method not getting overridden
   // by dynamic class loading.
   if (monomorphic_target != NULL) {
-    function()->env()->dependencies()->assert_unique_concrete_method(
+    dependencies()->assert_unique_concrete_method(
       actual_receiver, monomorphic_target);
     return monomorphic_target;
   }
@@ -1077,7 +1120,7 @@
 
   // Try to inline the call
   if (!call_is_virtual) {
-    if (SharkInliner::attempt_inline(call_method, current_state(), thread()))
+    if (SharkInliner::attempt_inline(call_method, current_state()))
       return;
   }
 
@@ -1116,9 +1159,9 @@
     "entry_point");
 
   // Make the call
-  current_state()->decache_for_Java_call(call_method);
+  decache_for_Java_call(call_method);
   builder()->CreateCall3(entry_point, callee, base_pc, thread());
-  current_state()->cache_after_Java_call(call_method);
+  cache_after_Java_call(call_method);
 
   // Check for pending exceptions
   check_pending_exception(EX_CHECK_FULL);
@@ -1133,7 +1176,7 @@
   // If the class we're checking against is java.lang.Object
   // then this is a no brainer.  Apparently this can happen
   // in reflective code...
-  if (check_klass == function()->env()->Object_klass())
+  if (check_klass == java_lang_Object_klass())
     return true;
 
   // Perform a subtype check.  NB in opto's code for this
@@ -1690,13 +1733,13 @@
   // NB we use the entire stack, but JavaThread::is_lock_owned()
   // uses a more limited range.  I don't think it hurts though...
   Value *stack_limit = builder()->CreateValueOfStructEntry(
-    function()->thread(), Thread::stack_base_offset(),
+    thread(), Thread::stack_base_offset(),
     SharkType::intptr_type(),
     "stack_limit");
 
   assert(sizeof(size_t) == sizeof(intptr_t), "should be");
   Value *stack_size = builder()->CreateValueOfStructEntry(
-    function()->thread(), Thread::stack_size_offset(),
+    thread(), Thread::stack_size_offset(),
     SharkType::intptr_type(),
     "stack_size");
 
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp	Wed Jun 17 14:37:31 2009 +0100
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp	Thu Jun 18 12:00:59 2009 -0400
@@ -26,10 +26,7 @@
 class SharkTopLevelBlock : public SharkBlock {
  public:
   SharkTopLevelBlock(SharkFunction* function, ciTypeFlow::Block* ciblock)
-    : SharkBlock(function->builder(),
-                 function->target(),
-                 function->iter(),
-                 function->thread()),
+    : SharkBlock(function),
       _function(function),
       _ciblock(ciblock),
       _entered(false),
@@ -205,6 +202,14 @@
     return value;
   }
 
+  // Cache and decache
+ private:
+  void decache_for_Java_call(ciMethod* callee);
+  void cache_after_Java_call(ciMethod* callee);
+  void decache_for_VM_call();
+  void cache_after_VM_call();
+  void decache_for_trap();
+
   // Monitors
  private:
   int num_monitors()
@@ -256,11 +261,11 @@
                           llvm::Value**   args_end,
                           int             exception_action)
   {
-    current_state()->decache_for_VM_call();
+    decache_for_VM_call();
     function()->set_last_Java_frame();
     llvm::CallInst *res = builder()->CreateCall(callee, args_start, args_end);
     function()->reset_last_Java_frame();
-    current_state()->cache_after_VM_call();
+    cache_after_VM_call();
     if (exception_action & EAM_CHECK) {
       check_pending_exception(exception_action);
       current_state()->set_has_safepointed(true);