changeset 1919:9a952e506f16

2009-07-30 Gary Benson <gbenson@redhat.com> * ports/hotspot/src/share/vm/shark/sharkRuntime.hpp: * ports/hotspot/src/share/vm/shark/sharkRuntime.cpp: Moved everything except the actual methods called by JIT-compiled code into SharkBuilder. * ports/hotspot/src/share/vm/shark/sharkBuilder.hpp * ports/hotspot/src/share/vm/shark/sharkBuilder.cpp Merged code to create LLVM callable objects for runtime methods from SharkRuntime, and refactored it (and the existing code to create LLVM callable objects for LLVM intrinsics) to create such objects on the fly. * ports/hotspot/src/share/vm/shark/sharkCompiler.hpp (SharkCompiler::_builder): Removed. (SharkCompiler::builder): Likewise. * ports/hotspot/src/share/vm/shark/sharkInvariants.hpp (SharkCompileInvariants::SharkCompileInvariants): Take a new argument, builder, and store it. (SharkCompileInvariants::builder): Updated. (SharkCompileInvariants::code_buffer): New method. (SharkTargetInvariants::SharkTargetInvariants): Take a new argument, builder, and pass it along to SharkCompileInvariants constructor. * ports/hotspot/src/share/vm/shark/sharkFunction.hpp (SharkFunction::build): Take a new argument, builder, and pass it along to SharkFunction consructor. (SharkFunction::SharkFunction): Take a new argument, builder, and pass it along to SharkTargetInvariants consructor. * ports/hotspot/src/share/vm/shark/sharkCompiler.cpp (SharkCompiler::SharkCompiler): Remove builder creation and SharkRuntime initialization. (SharkCompiler::compile_method): Create builder and pass it to SharkFunction::build. * ports/hotspot/src/share/vm/shark/sharkBlock.cpp (SharkBlock::parse_bytecode): Updated for new style calls. * ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp (SharkIntrinsics::do_Math_1to1): Likewise. (SharkIntrinsics::do_Math_2to1): Likewise. * ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp (SharkIntrinsics::do_intrinsic): Likewise. (SharkIntrinsics::do_Math_1to1): Likewise. (SharkIntrinsics::do_Math_2to1): Likewise. (SharkIntrinsics::do_System_currentTimeMillis): Likewise. (SharkIntrinsics::do_Unsafe_compareAndSwapInt): Likewise. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp (SharkTopLevelBlock::call_vm): Likewise. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp (SharkTopLevelBlock::zero_check_value): Likewise. (SharkTopLevelBlock::check_bounds): Likewise. (SharkTopLevelBlock::maybe_add_safepoint): Likewise. (SharkTopLevelBlock::do_trap): Likewise. (SharkTopLevelBlock::call_register_finalizer): Likewise. (SharkTopLevelBlock::get_interface_callee): Likewise. (SharkTopLevelBlock::do_new): Likewise. (SharkTopLevelBlock::do_newarray): Likewise. (SharkTopLevelBlock::do_anewarray): Likewise. (SharkTopLevelBlock::do_multianewarray): Likewise. (SharkTopLevelBlock::acquire_lock): Likewise. (SharkTopLevelBlock::release_lock): Likewise. * ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp (SharkDecacher::start_frame): Updated for new style codebuffer access. * ports/hotspot/src/share/vm/shark/sharkFunction.cpp (SharkFunction::initialize): Likewise. * ports/hotspot/src/share/vm/shark/llvmValue.hpp (LLVMValue::bit_constant): New method. * ports/hotspot/src/share/vm/shark/sharkBlock.hpp (SharkBlock::call_vm_leaf): Removed. * ports/hotspot/src/share/vm/includeDB_shark: Updated.
author Gary Benson <gbenson@redhat.com>
date Thu, 30 Jul 2009 04:51:32 -0400
parents 1791126ef6df
children 9a93570b7b06
files ChangeLog ports/hotspot/src/share/vm/includeDB_shark ports/hotspot/src/share/vm/shark/llvmValue.hpp ports/hotspot/src/share/vm/shark/sharkBlock.cpp ports/hotspot/src/share/vm/shark/sharkBlock.hpp ports/hotspot/src/share/vm/shark/sharkBuilder.cpp ports/hotspot/src/share/vm/shark/sharkBuilder.hpp ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp ports/hotspot/src/share/vm/shark/sharkCompiler.cpp ports/hotspot/src/share/vm/shark/sharkCompiler.hpp ports/hotspot/src/share/vm/shark/sharkFunction.cpp ports/hotspot/src/share/vm/shark/sharkFunction.hpp ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp ports/hotspot/src/share/vm/shark/sharkInvariants.hpp ports/hotspot/src/share/vm/shark/sharkRuntime.cpp ports/hotspot/src/share/vm/shark/sharkRuntime.hpp ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
diffstat 19 files changed, 868 insertions(+), 1026 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Jul 17 06:04:59 2009 -0400
+++ b/ChangeLog	Thu Jul 30 04:51:32 2009 -0400
@@ -1,3 +1,79 @@
+2009-07-30  Gary Benson  <gbenson@redhat.com>
+
+	* ports/hotspot/src/share/vm/shark/sharkRuntime.hpp:
+	* ports/hotspot/src/share/vm/shark/sharkRuntime.cpp:
+	Moved everything except the actual methods called by
+	JIT-compiled code into SharkBuilder.
+	
+	* ports/hotspot/src/share/vm/shark/sharkBuilder.hpp
+	* ports/hotspot/src/share/vm/shark/sharkBuilder.cpp
+	Merged code to create LLVM callable objects for runtime
+	methods from SharkRuntime, and refactored it (and the
+	existing code to create LLVM callable objects for LLVM
+	intrinsics) to create such objects on the fly.
+
+	* ports/hotspot/src/share/vm/shark/sharkCompiler.hpp
+	(SharkCompiler::_builder): Removed.
+	(SharkCompiler::builder): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkInvariants.hpp
+	(SharkCompileInvariants::SharkCompileInvariants): Take a new
+	argument, builder, and store it.
+	(SharkCompileInvariants::builder): Updated.
+	(SharkCompileInvariants::code_buffer): New method.
+	(SharkTargetInvariants::SharkTargetInvariants): Take a new
+	argument, builder, and pass it along to SharkCompileInvariants
+	constructor.
+	* ports/hotspot/src/share/vm/shark/sharkFunction.hpp
+	(SharkFunction::build): Take a new argument, builder, and pass
+	it along to SharkFunction consructor.
+	(SharkFunction::SharkFunction): Take a new argument, builder,
+	and pass it along to SharkTargetInvariants consructor.	
+	* ports/hotspot/src/share/vm/shark/sharkCompiler.cpp
+	(SharkCompiler::SharkCompiler): Remove builder creation and
+	SharkRuntime initialization.
+	(SharkCompiler::compile_method): Create builder and pass it
+	to SharkFunction::build.
+	
+	* ports/hotspot/src/share/vm/shark/sharkBlock.cpp
+	(SharkBlock::parse_bytecode): Updated for new style calls.
+	* ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp
+	(SharkIntrinsics::do_Math_1to1): Likewise.
+	(SharkIntrinsics::do_Math_2to1): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp
+	(SharkIntrinsics::do_intrinsic): Likewise.
+	(SharkIntrinsics::do_Math_1to1): Likewise.
+	(SharkIntrinsics::do_Math_2to1): Likewise.
+	(SharkIntrinsics::do_System_currentTimeMillis): Likewise.
+	(SharkIntrinsics::do_Unsafe_compareAndSwapInt): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp
+	(SharkTopLevelBlock::call_vm): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
+	(SharkTopLevelBlock::zero_check_value): Likewise.
+	(SharkTopLevelBlock::check_bounds): Likewise.
+	(SharkTopLevelBlock::maybe_add_safepoint): Likewise.
+	(SharkTopLevelBlock::do_trap): Likewise.
+	(SharkTopLevelBlock::call_register_finalizer): Likewise.
+	(SharkTopLevelBlock::get_interface_callee): Likewise.
+	(SharkTopLevelBlock::do_new): Likewise.
+	(SharkTopLevelBlock::do_newarray): Likewise.
+	(SharkTopLevelBlock::do_anewarray): Likewise.
+	(SharkTopLevelBlock::do_multianewarray): Likewise.
+	(SharkTopLevelBlock::acquire_lock): Likewise.
+	(SharkTopLevelBlock::release_lock): Likewise.
+
+	* ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp
+	(SharkDecacher::start_frame): Updated for new style codebuffer access.
+	* ports/hotspot/src/share/vm/shark/sharkFunction.cpp
+	(SharkFunction::initialize): Likewise.
+
+	* ports/hotspot/src/share/vm/shark/llvmValue.hpp
+	(LLVMValue::bit_constant): New method.
+
+	* ports/hotspot/src/share/vm/shark/sharkBlock.hpp
+	(SharkBlock::call_vm_leaf): Removed.
+	
+	* ports/hotspot/src/share/vm/includeDB_shark: Updated.	
+
 2009-07-17  Gary Benson  <gbenson@redhat.com>
 
 	* ports/hotspot/src/share/vm/shark/sharkBuilder.hpp
--- a/ports/hotspot/src/share/vm/includeDB_shark	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/includeDB_shark	Thu Jul 30 04:51:32 2009 -0400
@@ -72,7 +72,6 @@
 sharkBlock.cpp                          sharkBlock.hpp
 sharkBlock.cpp                          sharkBuilder.hpp
 sharkBlock.cpp                          sharkConstant.hpp
-sharkBlock.cpp                          sharkRuntime.hpp
 sharkBlock.cpp                          sharkState.hpp
 sharkBlock.cpp                          sharkValue.hpp
 
@@ -149,7 +148,6 @@
 sharkCompiler.cpp                       sharkEntry.hpp
 sharkCompiler.cpp                       sharkFunction.hpp
 sharkCompiler.cpp                       sharkMemoryManager.hpp
-sharkCompiler.cpp                       sharkRuntime.hpp
 
 sharkCompiler.hpp                       abstractCompiler.hpp
 sharkCompiler.hpp                       ciEnv.hpp
@@ -212,7 +210,6 @@
 sharkIntrinsics.cpp                     llvmHeaders.hpp
 sharkIntrinsics.cpp                     shark_globals.hpp
 sharkIntrinsics.cpp                     sharkIntrinsics.hpp
-sharkIntrinsics.cpp                     sharkRuntime.hpp
 sharkIntrinsics.cpp                     sharkState.hpp
 sharkIntrinsics.cpp                     sharkValue.hpp
 
@@ -246,15 +243,12 @@
 sharkRuntime.cpp                        deoptimization.hpp
 sharkRuntime.cpp                        llvmHeaders.hpp
 sharkRuntime.cpp                        klassOop.hpp
-sharkRuntime.cpp                        sharkBuilder.hpp
 sharkRuntime.cpp                        sharkRuntime.hpp
-sharkRuntime.cpp                        sharkType.hpp
 sharkRuntime.cpp                        thread.hpp
 
 sharkRuntime.hpp                        allocation.hpp
 sharkRuntime.hpp                        llvmHeaders.hpp
 sharkRuntime.hpp                        klassOop.hpp
-sharkRuntime.hpp                        sharkBuilder.hpp
 sharkRuntime.hpp                        thread.hpp
 
 sharkState.cpp                          allocation.hpp
@@ -298,7 +292,6 @@
 sharkTopLevelBlock.cpp                  sharkBuilder.hpp
 sharkTopLevelBlock.cpp                  sharkConstant.hpp
 sharkTopLevelBlock.cpp                  sharkInliner.hpp
-sharkTopLevelBlock.cpp                  sharkRuntime.hpp
 sharkTopLevelBlock.cpp                  sharkState.hpp
 sharkTopLevelBlock.cpp                  sharkValue.hpp
 
--- a/ports/hotspot/src/share/vm/shark/llvmValue.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/llvmValue.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -1,6 +1,6 @@
 /*
  * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
- * Copyright 2008 Red Hat, Inc.
+ * 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
@@ -77,6 +77,14 @@
   }
 
  public:
+  static llvm::ConstantInt* bit_constant(int value)
+  {
+#if SHARK_LLVM_VERSION >= 26
+    return llvm::getGlobalContext().getConstantInt(llvm::Type::Int1Ty, value, false);
+#else
+    return llvm::ConstantInt::get(llvm::Type::Int1Ty, value, false);
+#endif
+  }
   static llvm::ConstantInt* intptr_constant(intptr_t value)
   {
 #if SHARK_LLVM_VERSION >= 26
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -694,11 +694,13 @@
 
     case Bytecodes::_f2i:
       push(SharkValue::create_jint(
-        call_vm_leaf(SharkRuntime::f2i(), pop()->jfloat_value()), false));
+        builder()->CreateCall(
+          builder()->f2i(), pop()->jfloat_value()), false));
       break;
     case Bytecodes::_f2l:
       push(SharkValue::create_jlong(
-        call_vm_leaf(SharkRuntime::f2l(), pop()->jfloat_value()), false));
+        builder()->CreateCall(
+          builder()->f2l(), pop()->jfloat_value()), false));
       break;
     case Bytecodes::_f2d:
       push(SharkValue::create_jdouble(
@@ -708,11 +710,13 @@
 
     case Bytecodes::_d2i:
       push(SharkValue::create_jint(
-        call_vm_leaf(SharkRuntime::d2i(), pop()->jdouble_value()), false));
+        builder()->CreateCall(
+          builder()->d2i(), pop()->jdouble_value()), false));
       break;
     case Bytecodes::_d2l:
       push(SharkValue::create_jlong(
-        call_vm_leaf(SharkRuntime::d2l(), pop()->jdouble_value()), false));
+        builder()->CreateCall(
+          builder()->d2l(), pop()->jdouble_value()), false));
       break;
     case Bytecodes::_d2f:
       push(SharkValue::create_jfloat(
--- a/ports/hotspot/src/share/vm/shark/sharkBlock.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkBlock.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -174,13 +174,6 @@
  protected:
   virtual void do_zero_check(SharkValue* value);
 
-  // Leaf calls
- protected:
-  llvm::CallInst* call_vm_leaf(llvm::Constant* callee, llvm::Value* arg1)
-  {
-    return builder()->CreateCall(callee, arg1);
-  }
-
   // Zero checking
  protected:
   void check_null(SharkValue* object)
--- a/ports/hotspot/src/share/vm/shark/sharkBuilder.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkBuilder.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -28,39 +28,7 @@
 
 using namespace llvm;
 
-#ifdef ARM
-/*
- * ARM lacks atomic operation implementation in LLVM
- * http://llvm.org/bugs/show_bug.cgi?id=3877
- * 
- * These two functions zero_cmpxchg_int_fn and zero_cmpxchg_ptr_fn
- * are defined so that they can be inserted into llvm as a workaround to
- * make shark reroute all atomic calls back to the implementation in zero. 
- * The actual insertion are done in SharkBuilder::init_external_functions().
- */
-
-extern "C" {
-  jint zero_cmpxchg_int_fn(volatile jint *ptr,
-                           jint          *oldval,
-                           jint          *newval)
-  {
-    return Atomic::cmpxchg(*newval,
-                           ptr,
-                           *oldval);
-  }
-
-  intptr_t* zero_cmpxchg_ptr_fn(volatile void* ptr,
-                                intptr_t*      oldval,
-                                intptr_t*      newval)
-  { 
-    return (intptr_t *) Atomic::cmpxchg_ptr((void *) newval,
-                                                     ptr,
-                                            (void *) oldval);
-  }
-};
-#endif
-
-SharkBuilder::SharkBuilder(SharkCompiler* compiler)
+SharkBuilder::SharkBuilder(Module* module, SharkCodeBuffer* code_buffer)
 #if SHARK_LLVM_VERSION >= 26
   // LLVM 2.6 requires a LLVMContext during IRBuilder construction.
   // getGlobalConext() returns one that can be used as long as the shark
@@ -68,149 +36,480 @@
   : IRBuilder<>(getGlobalContext()),
 #else
   : IRBuilder<>(),
-#endif
-    _compiler(compiler)
+#endif // SHARK_LLVM_VERSION >= 26
+    _module(module),
+    _code_buffer(code_buffer)
+{
+}
+
+// Helpers for accessing structures
+Value* SharkBuilder::CreateAddressOfStructEntry(Value*      base,
+                                                ByteSize    offset,
+                                                const Type* type,
+                                                const char* name)
+{
+  return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
+}
+
+LoadInst* SharkBuilder::CreateValueOfStructEntry(Value*      base,
+                                                 ByteSize    offset,
+                                                 const Type* type,
+                                                 const char* name)
+{
+  return CreateLoad(
+    CreateAddressOfStructEntry(
+      base, offset, PointerType::getUnqual(type)),
+    name);
+}
+
+// Helpers for accessing arrays
+
+LoadInst* SharkBuilder::CreateArrayLength(Value* arrayoop)
 {
-  init_external_functions();
+  return CreateValueOfStructEntry(
+    arrayoop, in_ByteSize(arrayOopDesc::length_offset_in_bytes()),
+    SharkType::jint_type(), "length");
+}
+
+Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
+                                        const Type* element_type,
+                                        int         element_bytes,
+                                        ByteSize    base_offset,
+                                        Value*      index,
+                                        const char* name)
+{
+  Value* offset = CreateIntCast(index, SharkType::intptr_type(), false);
+  if (element_bytes != 1)
+    offset = CreateShl(
+      offset,
+      LLVMValue::intptr_constant(exact_log2(element_bytes)));
+  offset = CreateAdd(
+    LLVMValue::intptr_constant(in_bytes(base_offset)), offset);
+
+  return CreateIntToPtr(
+    CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset),
+    PointerType::getUnqual(element_type),
+    name);
+}
+
+Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
+                                        BasicType   basic_type,
+                                        ByteSize    base_offset,
+                                        Value*      index,
+                                        const char* name)
+{
+  return CreateArrayAddress(
+    arrayoop,
+    SharkType::to_arrayType(basic_type),
+    type2aelembytes(basic_type),
+    base_offset, index, name);
+}
+
+Value* SharkBuilder::CreateArrayAddress(Value*      arrayoop,
+                                        BasicType   basic_type,
+                                        Value*      index,
+                                        const char* name)
+{
+  return CreateArrayAddress(
+    arrayoop, basic_type,
+    in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)),
+    index, name);
 }
 
-Constant* SharkBuilder::make_function(intptr_t            addr,
-                                      const FunctionType* sig,
-                                      const char*         name)
+// Helpers for creating intrinsics and external functions.
+
+const Type* SharkBuilder::make_type(char type, bool void_ok)
 {
-  Constant *func = make_pointer(addr, sig);
+  switch (type) {
+    // Primitive types
+  case 'c':
+    return SharkType::jbyte_type();
+  case 'i':
+    return SharkType::jint_type();
+  case 'l':
+    return SharkType::jlong_type();
+  case 'x':
+    return SharkType::intptr_type();
+  case 'f':
+    return SharkType::jfloat_type();
+  case 'd':
+    return SharkType::jdouble_type();
+
+    // Pointers to primitive types
+  case 'C':
+  case 'I':
+  case 'L':
+  case 'X':
+  case 'F':
+  case 'D':
+    return PointerType::getUnqual(make_type(tolower(type), false));
+    
+    // VM objects
+  case 'T':
+    return SharkType::thread_type();
+  case 'M':
+    return PointerType::getUnqual(SharkType::monitor_type());
+  case 'O':
+    return SharkType::oop_type();
 
-#ifndef PRODUCT
-  ResourceMark rm;
+    // Miscellaneous
+  case 'v':
+    assert(void_ok, "should be");
+    return Type::VoidTy;
+  case '1':
+    return Type::Int1Ty;
+
+  default:
+    ShouldNotReachHere();
+  }
+}
+
+const FunctionType* SharkBuilder::make_ftype(const char* params,
+                                             const char* ret)
+{
+  std::vector<const Type*> param_types;
+  for (const char* c = params; *c; c++)
+    param_types.push_back(make_type(*c, false));
 
-  // Use a trampoline to make dumped code more readable
-  Function *trampoline = (Function *) module()->getOrInsertFunction(name, sig);
-  SetInsertPoint(BasicBlock::Create("", trampoline));
+  assert(strlen(ret) == 1, "should be");
+  const Type *return_type = make_type(*ret, true);
+
+  return FunctionType::get(return_type, param_types, false);
+}
+
+// Create an object representing an intrinsic or external function by
+// referencing the symbol by name.  This is the LLVM-style approach,
+// but it cannot be used on functions within libjvm.so its symbols
+// are not exported.  Note that you cannot make this work simply by
+// exporting the symbols, as some symbols have the same names as
+// symbols in the standard libraries (eg, atan2, fabs) and would
+// obscure them were they visible.
+Value* SharkBuilder::make_function(const char* name,
+                                   const char* params,
+                                   const char* ret)
+{
+  return module()->getOrInsertFunction(name, make_ftype(params, ret));
+}
 
-  Value **args = NEW_RESOURCE_ARRAY(Value*, trampoline->arg_size());
-  Function::arg_iterator ai = trampoline->arg_begin();
-  for (unsigned i = 0; i < trampoline->arg_size(); i++)
-    args[i] = ai++;
+// Create an object representing an external function by inlining a
+// function pointer in the code.  This is not the LLVM way, but it's
+// the only way to access functions in libjvm.so and functions like
+// __kernel_dmb on ARM which is accessed via an absolute address.
+Value* SharkBuilder::make_function(address     func,
+                                   const char* params,
+                                   const char* ret)
+{
+  return CreateIntToPtr(
+    LLVMValue::intptr_constant((intptr_t) func),
+    PointerType::getUnqual(make_ftype(params, ret)));
+}
+
+// VM calls
+
+Value* SharkBuilder::find_exception_handler()
+{
+  return make_function(
+    (address) SharkRuntime::find_exception_handler, "TIi", "i");
+}
+
+Value* SharkBuilder::monitorenter()
+{
+  return make_function((address) SharkRuntime::monitorenter, "TM", "v");
+}
+
+Value* SharkBuilder::monitorexit()
+{
+  return make_function((address) SharkRuntime::monitorexit, "TM", "v");
+}
+
+Value* SharkBuilder::new_instance()
+{
+  return make_function((address) SharkRuntime::new_instance, "Ti", "v");
+}
 
-  Value *result = CreateCall(func, args, args + trampoline->arg_size());
-  if (sig->getReturnType() == Type::VoidTy)
-    CreateRetVoid();
-  else
-    CreateRet(result);
+Value* SharkBuilder::newarray()
+{
+  return make_function((address) SharkRuntime::newarray, "Tii", "v");
+}
+
+Value* SharkBuilder::anewarray()
+{
+  return make_function((address) SharkRuntime::anewarray, "Tii", "v");
+}
+
+Value* SharkBuilder::multianewarray()
+{
+  return make_function((address) SharkRuntime::multianewarray, "TiiI", "v");
+}
+
+Value* SharkBuilder::register_finalizer()
+{
+  return make_function((address) SharkRuntime::register_finalizer, "TO", "v");
+}
 
-  func = trampoline;
-#endif // !PRODUCT
+Value* SharkBuilder::safepoint()
+{
+  return make_function((address) SafepointSynchronize::block, "T", "v");
+}
+
+Value* SharkBuilder::throw_ArrayIndexOutOfBoundsException()
+{
+  return make_function(
+    (address) SharkRuntime::throw_ArrayIndexOutOfBoundsException, "TCii", "v");
+}
 
-  return func;
+Value* SharkBuilder::throw_NullPointerException()
+{
+  return make_function(
+    (address) SharkRuntime::throw_NullPointerException, "TCi", "v");
+}
+
+// High-level non-VM calls
+
+Value* SharkBuilder::f2i()
+{
+  return make_function((address) SharedRuntime::f2i, "f", "i");
 }
 
-void SharkBuilder::init_external_functions()
+Value* SharkBuilder::f2l()
+{
+  return make_function((address) SharedRuntime::f2l, "f", "l");
+}
+
+Value* SharkBuilder::d2i()
 {
-  std::vector<const Type*> params;
-  params.push_back(PointerType::getUnqual(SharkType::jbyte_type()));
-  params.push_back(SharkType::jbyte_type());
-  params.push_back(SharkType::jint_type());
-  params.push_back(SharkType::jint_type());
-  FunctionType *type = FunctionType::get(Type::VoidTy, params, false);
-  set_llvm_memset_fn(module()->getOrInsertFunction("llvm.memset.i32", type));
+  return make_function((address) SharedRuntime::d2i, "d", "i");
+}
+
+Value* SharkBuilder::d2l()
+{
+  return make_function((address) SharedRuntime::d2l, "d", "l");
+}
+
+Value* SharkBuilder::is_subtype_of()
+{
+  return make_function((address) SharkRuntime::is_subtype_of, "OO", "c");
+}
 
-  params.clear();
-  params.push_back(PointerType::getUnqual(SharkType::jint_type()));
-  params.push_back(SharkType::jint_type());
-  params.push_back(SharkType::jint_type());
-  type = FunctionType::get(SharkType::jint_type(), params, false);
-  set_llvm_cmpxchg_int_fn(
-#ifdef ARM
-    make_function(
-      (intptr_t) zero_cmpxchg_int_fn,
-      type,
-      "zero_cmpxchg_int_fn"));
-#else
-    module()->getOrInsertFunction("llvm.atomic.cmp.swap.i32", type));
-#endif
+Value* SharkBuilder::current_time_millis()
+{
+  return make_function((address) os::javaTimeMillis, "", "l");
+}
+
+Value* SharkBuilder::sin()
+{
+  return make_function("llvm.sin.f64", "d", "d");
+}
+
+Value* SharkBuilder::cos()
+{
+  return make_function("llvm.cos.f64", "d", "d");
+}
+
+Value* SharkBuilder::tan()
+{
+  return make_function((address) ::tan, "d", "d");
+}
 
-  params.clear();
-  params.push_back(PointerType::getUnqual(SharkType::intptr_type()));
-  params.push_back(SharkType::intptr_type());
-  params.push_back(SharkType::intptr_type());
-  type = FunctionType::get(SharkType::intptr_type(), params, false);
-  set_llvm_cmpxchg_ptr_fn(
-#ifdef ARM
-    make_function(
-      (intptr_t) zero_cmpxchg_ptr_fn,
-      type,
-      "zero_cmpxchg_ptr_fn"));
-#else
-    module()->getOrInsertFunction(
-      "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32"), type));
-#endif
+Value* SharkBuilder::atan2()
+{
+  return make_function((address) ::atan2, "dd", "d");
+}
+
+Value* SharkBuilder::sqrt()
+{
+  return make_function("llvm.sqrt.f64", "d", "d");
+}
+
+Value* SharkBuilder::log()
+{
+  return make_function("llvm.log.f64", "d", "d");
+}
+
+Value* SharkBuilder::log10()
+{
+  return make_function("llvm.log10.f64", "d", "d");
+}
 
- /* 
-  *  The five booleans passed to llvm.memory.barrier are used like this:
-  *  The first four arguments enables a specific barrier in this order:
-  *  load-load, load-store, store-load and store-store.
-  *  The fith argument specifies that the barrier applies to io or device
-  *  or uncached memory.
-  */
-  params.clear();
-  for (int i = 0; i < 5; i++)
-    params.push_back(Type::Int1Ty);
-  type = FunctionType::get(Type::VoidTy, params, false);
-  set_llvm_memory_barrier_fn(
-#ifdef ARM
-    make_function(
-      0xffff0fa0, // __kernel_dmb
-      type,
-      "__kernel_dmb"));
-#else
-    module()->getOrInsertFunction("llvm.memory.barrier", type));
-#endif
+Value* SharkBuilder::pow()
+{
+  return make_function("llvm.pow.f64", "dd", "d");
+}
+
+Value* SharkBuilder::exp()
+{
+  return make_function("llvm.exp.f64", "d", "d");
+}
 
-  params.clear();
-  params.push_back(SharkType::jdouble_type());
-  type = FunctionType::get(SharkType::jdouble_type(), params, false);
-  set_llvm_sin_fn  (module()->getOrInsertFunction("llvm.sin.f64",   type));
-  set_llvm_cos_fn  (module()->getOrInsertFunction("llvm.cos.f64",   type));
-  set_llvm_sqrt_fn (module()->getOrInsertFunction("llvm.sqrt.f64",  type));
-  set_llvm_log_fn  (module()->getOrInsertFunction("llvm.log.f64",   type));
-  set_llvm_log10_fn(module()->getOrInsertFunction("llvm.log10.f64", type));
-  set_llvm_exp_fn  (module()->getOrInsertFunction("llvm.exp.f64",   type));  
+Value* SharkBuilder::fabs()
+{
+  return make_function((address) ::fabs, "d", "d");
+}
 
-  params.clear();
-  params.push_back(SharkType::jdouble_type());
-  params.push_back(SharkType::jdouble_type());
-  type = FunctionType::get(SharkType::jdouble_type(), params, false);
-  set_llvm_pow_fn(module()->getOrInsertFunction("llvm.pow.f64", type));  
+Value* SharkBuilder::unsafe_field_offset_to_byte_offset()
+{
+  extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
+  return make_function((address) Unsafe_field_offset_to_byte_offset, "l", "l");
+}
+
+// Uncommon trap
+
+Value* SharkBuilder::uncommon_trap()
+{
+  return make_function((address) SharkRuntime::uncommon_trap, "Ti", "v");
 }
 
-CallInst* SharkBuilder::CreateDump(llvm::Value* value)
+// Low-level non-VM calls
+
+// The ARM-specific code here is to work around unimplemented
+// atomic exchange and memory barrier intrinsics in LLVM.
+//
+// Delegating to external functions for these would normally
+// incur a speed penalty, but Linux on ARM is a special case
+// in that atomic operations on that platform are handled by
+// external functions anyway.  It would be *preferable* for
+// the calls to be hidden away in LLVM, but it's not hurting
+// performance so having the calls here is acceptable.
+//
+// If you are building Shark on a platform without atomic
+// exchange and/or memory barrier intrinsics then it is only
+// acceptable to mimic this approach if your platform cannot
+// perform these operations without delegating to a function.
+
+#ifdef ARM
+static jint zero_cmpxchg_int(volatile jint *ptr, jint *oldval, jint newval)
+{
+  return Atomic::cmpxchg(*newval, ptr, *oldval);
+}
+#endif // ARM
+
+Value* SharkBuilder::cmpxchg_int()
 {
-  Constant *const_name;
-  if (value->hasName())
-#if SHARK_LLVM_VERSION >= 26
-    const_name = getGlobalContext().getConstantArray(value->getName());
-  else
-    const_name = getGlobalContext().getConstantArray("unnamed_value");
+  return make_function(
+#ifdef ARM
+    (address) zero_cmpxchg_int,
+#else
+    "llvm.atomic.cmp.swap.i32",
+#endif // ARM
+    "Iii", "i");
+}
+
+#ifdef ARM
+static intptr_t zero_cmpxchg_ptr(volatile intptr_t* ptr,
+                                 intptr_t*          oldval,
+                                 intptr_t*          newval)
+{
+  return Atomic::cmpxchg_ptr(*newval, ptr, *oldval);
+}
+#endif // ARM
+
+Value* SharkBuilder::cmpxchg_ptr()
+{
+  return make_function(
+#ifdef ARM
+    (address) zero_cmpxchg_ptr,
 #else
-    const_name = ConstantArray::get(value->getName());
-  else
-    const_name = ConstantArray::get("unnamed_value");
-#endif
+    "llvm.atomic.cmp.swap.i" LP64_ONLY("64") NOT_LP64("32"),
+#endif // ARM
+    "Xxx", "x");
+}
+
+Value* SharkBuilder::memory_barrier()
+{
+  return make_function(
+#ifdef ARM
+    (address) 0xffff0fa0, // __kernel_dmb
+#else
+    "llvm.memory.barrier",
+#endif // ARM
+    "11111", "v");
+}
+
+Value* SharkBuilder::memset()
+{
+  return make_function("llvm.memset.i32", "Ccii", "v");
+}
+
+Value* SharkBuilder::unimplemented()
+{
+  return make_function((address) report_unimplemented, "Ci", "v");
+}
 
-  Value *name = CreatePtrToInt(
-    CreateStructGEP(
-      new GlobalVariable(
-#if SHARK_LLVM_VERSION >= 26
-        // LLVM 2.6 requires a LLVMContext during GlobalVariable construction.
-        // getGlobalConext() returns one that can be used as long as the shark
-        // compiler are single-threaded.
-        getGlobalContext(),
-#endif
-        const_name->getType(),
-        true, GlobalValue::InternalLinkage,
-        const_name, "dump", module()),
-      0),
-    SharkType::intptr_type());
+Value* SharkBuilder::should_not_reach_here()
+{
+  return make_function((address) report_should_not_reach_here, "Ci", "v");
+}
+
+Value* SharkBuilder::dump()
+{
+  return make_function((address) SharkRuntime::dump, "Cx", "v");
+}
+
+// Public interface to low-level non-VM calls
+
+CallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
+                                         Value* dst,
+                                         Value* compare_value)
+{
+  return CreateCall3(cmpxchg_int(), dst, compare_value, exchange_value);
+}
+
+CallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
+                                         Value* dst,
+                                         Value* compare_value)
+{
+  return CreateCall3(cmpxchg_ptr(), dst, compare_value, exchange_value);
+}
+
+CallInst *SharkBuilder::CreateMemoryBarrier(int flags)
+{
+  Value *args[] = {
+    LLVMValue::bit_constant((flags & BARRIER_LOADLOAD) ? 1 : 0),
+    LLVMValue::bit_constant((flags & BARRIER_LOADSTORE) ? 1 : 0),
+    LLVMValue::bit_constant((flags & BARRIER_STORELOAD) ? 1 : 0),
+    LLVMValue::bit_constant((flags & BARRIER_STORESTORE) ? 1 : 0),
+    LLVMValue::bit_constant(0)};
+
+  return CreateCall(memory_barrier(), args, args + 5);
+}
+
+CallInst* SharkBuilder::CreateMemset(Value* dst,
+                                     Value* value,
+                                     Value* len,
+                                     Value* align)
+{
+  return CreateCall4(memset(), dst, value, len, align);
+}
+
+CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line)
+{
+  return CreateCall2(
+    unimplemented(),
+    CreateIntToPtr(
+      LLVMValue::intptr_constant((intptr_t) file),
+      PointerType::getUnqual(SharkType::jbyte_type())),
+    LLVMValue::jint_constant(line));
+}
+
+CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line)
+{
+  return CreateCall2(
+    should_not_reach_here(),
+    CreateIntToPtr(
+      LLVMValue::intptr_constant((intptr_t) file),
+      PointerType::getUnqual(SharkType::jbyte_type())),
+    LLVMValue::jint_constant(line));
+}
+
+#ifndef PRODUCT
+CallInst* SharkBuilder::CreateDump(Value* value)
+{
+  const char *name;
+  if (value->hasName())
+    // XXX this leaks, but it's only debug code
+    name = strdup(value->getName().c_str());
+  else
+    name = "unnamed_value";
 
   if (isa<PointerType>(value->getType()))
     value = CreatePtrToInt(value, SharkType::intptr_type());
@@ -219,65 +518,77 @@
   else
     Unimplemented();
 
-  Value *args[] = {name, value};
-  return CreateCall2(SharkRuntime::dump(), name, value);
+  return CreateCall2(
+    dump(),
+    CreateIntToPtr(
+      LLVMValue::intptr_constant((intptr_t) name),
+      PointerType::getUnqual(SharkType::jbyte_type())),
+    value);
 }
+#endif // PRODUCT
+
+// HotSpot memory barriers
 
-CallInst* SharkBuilder::CreateCmpxchgInt(Value* exchange_value,
-                                         Value* dst,
-                                         Value* compare_value)
+void SharkBuilder::CreateUpdateBarrierSet(BarrierSet* bs, Value* field)
 {
-  return CreateCall3(
-    llvm_cmpxchg_int_fn(), dst, compare_value, exchange_value);
+  if (bs->kind() != BarrierSet::CardTableModRef)
+    Unimplemented();
+
+  CreateStore(
+    LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card),
+    CreateIntToPtr(
+      CreateAdd(
+        LLVMValue::intptr_constant(
+          (intptr_t) ((CardTableModRefBS *) bs)->byte_map_base),
+        CreateLShr(
+          CreatePtrToInt(field, SharkType::intptr_type()),
+          LLVMValue::intptr_constant(CardTableModRefBS::card_shift))),
+      PointerType::getUnqual(SharkType::jbyte_type())));
 }
 
-CallInst* SharkBuilder::CreateCmpxchgPtr(Value* exchange_value,
-                                         Value* dst,
-                                         Value* compare_value)
+// Helpers for accessing the code buffer
+
+Value* SharkBuilder::code_buffer_address(int offset)
 {
-  return CreateCall3(
-    llvm_cmpxchg_ptr_fn(), dst, compare_value, exchange_value);
-}
-
-CallInst* SharkBuilder::CreateMemset(Value* dst,
-                                     Value* value,
-                                     Value* len,
-                                     Value* align)
-{
-  return CreateCall4(llvm_memset_fn(), dst, value, len, align);
+  return CreateAdd(
+    code_buffer()->base_pc(),
+    LLVMValue::intptr_constant(offset));
 }
 
-CallInst* SharkBuilder::CreateUnimplemented(const char* file, int line)
+Value* SharkBuilder::CreateInlineOop(ciObject* object, const char* name)
 {
-  return CreateCall2(
-    SharkRuntime::unimplemented(),
-    pointer_constant(file),
-    LLVMValue::jint_constant(line));
-}
-
-CallInst* SharkBuilder::CreateShouldNotReachHere(const char* file, int line)
-{
-  return CreateCall2(
-    SharkRuntime::should_not_reach_here(),
-    pointer_constant(file),
-    LLVMValue::jint_constant(line));
+  return CreateLoad(
+    CreateIntToPtr(
+      code_buffer_address(code_buffer()->inline_oop(object)),
+      PointerType::getUnqual(SharkType::jobject_type())),
+    name);
 }
 
-CallInst *SharkBuilder::CreateMemoryBarrier(BarrierFlags flags)
+// Helpers for creating basic blocks.
+
+BasicBlock* SharkBuilder::GetBlockInsertionPoint() const
 {
-  Value *args[] = {
-#if SHARK_LLVM_VERSION >= 26
-    getGlobalContext().getConstantInt(Type::Int1Ty, (flags & BARRIER_LOADLOAD) ? 1 : 0),
-    getGlobalContext().getConstantInt(Type::Int1Ty, (flags & BARRIER_LOADSTORE) ? 1 : 0),
-    getGlobalContext().getConstantInt(Type::Int1Ty, (flags & BARRIER_STORELOAD) ? 1 : 0),
-    getGlobalContext().getConstantInt(Type::Int1Ty, (flags & BARRIER_STORESTORE) ? 1 : 0),
-    getGlobalContext().getConstantInt(Type::Int1Ty, 0)};
-#else
-    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_LOADLOAD) ? 1 : 0),
-    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_LOADSTORE) ? 1 : 0),
-    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_STORELOAD) ? 1 : 0),
-    ConstantInt::get(Type::Int1Ty, (flags & BARRIER_STORESTORE) ? 1 : 0),
-    ConstantInt::get(Type::Int1Ty, 0)};
-#endif
-  return CreateCall(llvm_memory_barrier_fn(), args, args + 5);
+  BasicBlock *cur = GetInsertBlock();
+
+  // BasicBlock::Create takes an insertBefore argument, so
+  // we need to find the block _after_ the current block
+  Function::iterator iter = cur->getParent()->begin();
+  Function::iterator end  = cur->getParent()->end();
+  while (iter != end) {
+    iter++;
+    if (&*iter == cur) {
+      iter++;
+      break;
+    }
+  }
+
+  if (iter == end)
+    return NULL;
+  else
+    return iter;
 }
+
+BasicBlock* SharkBuilder::CreateBlock(BasicBlock* ip, const char* name) const
+{
+  return BasicBlock::Create(name, GetInsertBlock()->getParent(), ip);
+}  
--- a/ports/hotspot/src/share/vm/shark/sharkBuilder.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkBuilder.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -24,322 +24,150 @@
  */
 
 class SharkBuilder : public llvm::IRBuilder<> {
- public:
-  SharkBuilder(SharkCompiler* compiler);
-
- private:
-  SharkCompiler* _compiler;
+  friend class SharkCompileInvariants;
 
  public:
-  SharkCompiler* compiler() const
-  {
-    return _compiler;
-  }
+  SharkBuilder(llvm::Module* module, SharkCodeBuffer* code_buffer);
+
+  // The LLVM module and Shark code buffer we are building into.
+ private:
+  llvm::Module*    _module;
+  SharkCodeBuffer* _code_buffer;
 
  private:
   llvm::Module* module() const
   {
-    return compiler()->module();
+    return _module;
   }
-  llvm::ExecutionEngine* execution_engine() const
+ protected:
+  SharkCodeBuffer* code_buffer() const
   {
-    return compiler()->execution_engine();
+    return _code_buffer;
   }
 
-  // Helpers for creating basic blocks
-  // NB don't use unless SharkFunction::CreateBlock is unavailable
- public:
-  llvm::BasicBlock* GetBlockInsertionPoint() const
-  {
-    llvm::BasicBlock *cur = GetInsertBlock();
-
-    // BasicBlock::Create takes an insertBefore argument, so
-    // we need to find the block _after_ the current block
-    llvm::Function::iterator iter = cur->getParent()->begin();
-    llvm::Function::iterator end  = cur->getParent()->end();
-    while (iter != end) {
-      iter++;
-      if (&*iter == cur) {
-        iter++;
-        break;
-      }
-    }
-
-    if (iter == end)
-      return NULL;
-    else
-      return iter;
-  }
-  llvm::BasicBlock* CreateBlock(llvm::BasicBlock* ip, const char* name="") const
-  {
-    return llvm::BasicBlock::Create(name, GetInsertBlock()->getParent(), ip);
-  }
-  
-  // Helpers for accessing structures and arrays
+  // Helpers for accessing structures.
  public:
   llvm::Value* CreateAddressOfStructEntry(llvm::Value* base,
                                           ByteSize offset,
                                           const llvm::Type* type,
-                                          const char *name = "")
-  {
-    return CreateBitCast(CreateStructGEP(base, in_bytes(offset)), type, name);
-  }
-
+                                          const char *name = "");
   llvm::LoadInst* CreateValueOfStructEntry(llvm::Value* base,
                                            ByteSize offset,
                                            const llvm::Type* type,
-                                           const char *name = "")
-  {
-    return CreateLoad(
-      CreateAddressOfStructEntry(
-        base, offset, llvm::PointerType::getUnqual(type)),
-      name);
-  }
+                                           const char *name = "");
 
-  llvm::LoadInst* CreateArrayLength(llvm::Value* array)
-  {
-    return CreateValueOfStructEntry(
-      array, in_ByteSize(arrayOopDesc::length_offset_in_bytes()),
-      SharkType::jint_type(), "length");
-  }
-
+  // Helpers for accessing arrays.
+ public:
+  llvm::LoadInst* CreateArrayLength(llvm::Value* arrayoop);
   llvm::Value* CreateArrayAddress(llvm::Value*      arrayoop,
                                   const llvm::Type* element_type,
                                   int               element_bytes,
                                   ByteSize          base_offset,
                                   llvm::Value*      index,
-                                  const char*       name = "")
-  {
-    llvm::Value* offset = CreateIntCast(index, SharkType::intptr_type(), false);
-    if (element_bytes != 1)
-      offset = CreateShl(
-        offset,
-        LLVMValue::intptr_constant(exact_log2(element_bytes)));
-    offset = CreateAdd(
-      LLVMValue::intptr_constant(in_bytes(base_offset)), offset);
-
-    return CreateIntToPtr(
-      CreateAdd(CreatePtrToInt(arrayoop, SharkType::intptr_type()), offset),
-      llvm::PointerType::getUnqual(element_type),
-      name);
-  }
-
+                                  const char*       name = "");
   llvm::Value* CreateArrayAddress(llvm::Value* arrayoop,
                                   BasicType    basic_type,
                                   ByteSize     base_offset,
                                   llvm::Value* index,
-                                  const char*  name = "")
-  {
-    return CreateArrayAddress(
-      arrayoop,
-      SharkType::to_arrayType(basic_type),
-      type2aelembytes(basic_type),
-      base_offset, index, name);
-  }
-
+                                  const char*  name = "");
   llvm::Value* CreateArrayAddress(llvm::Value* arrayoop,
                                   BasicType    basic_type,
                                   llvm::Value* index,
-                                  const char*  name = "")
-  {
-    return CreateArrayAddress(
-      arrayoop, basic_type,
-      in_ByteSize(arrayOopDesc::base_offset_in_bytes(basic_type)),
-      index, name);
-  }
-
-  // Helper for making function pointers
- public:
-  llvm::Constant* make_function(intptr_t                  addr,
-                                const llvm::FunctionType* sig,
-                                const char*               name);
+                                  const char*  name = "");
 
-  llvm::Constant* pointer_constant(const void *ptr)
-  {
-#if SHARK_LLVM_VERSION >= 25 || !defined(AMD64)
-    return LLVMValue::intptr_constant((intptr_t) ptr);
-#else
-    // Create a pointer constant that points at PTR.  We do this by
-    // creating a GlobalVariable mapped at PTR.  This is a workaround
-    // for http://www.llvm.org/bugs/show_bug.cgi?id=2920
-
-    using namespace llvm;
-
-    // This might be useful but it returns a const pointer that can't
-    // be used for anything.  Go figure...
-//     {
-//       const GlobalValue *value
-// 	= execution_engine()->getGlobalValueAtAddress(const_cast<void*>(ptr));
-//       if (value)
-// 	return ConstantExpr::getPtrToInt(value, SharkType::intptr_type());
-//     }
+  // Helpers for creating intrinsics and external functions.
+ private:
+  static const llvm::Type* make_type(char type, bool void_ok);
+  static const llvm::FunctionType* make_ftype(const char* params,
+                                              const char* ret);
+  llvm::Value* make_function(const char* name,
+                             const char* params,
+                             const char* ret);
+  llvm::Value* make_function(address     func,
+                             const char* params,
+                             const char* ret);
 
-    char name[128];
-    snprintf(name, sizeof name - 1, "pointer_constant_%p", ptr);
-
-    GlobalVariable *value = new GlobalVariable(
-      SharkType::intptr_type(),
-      false, GlobalValue::ExternalLinkage,
-      NULL, name, module());
-    execution_engine()->addGlobalMapping(value, const_cast<void*>(ptr));
-
-    return ConstantExpr::getPtrToInt(value, SharkType::intptr_type());
-#endif // SHARK_LLVM_VERSION >= 25 || !AMD64
-  }
-
-  // Helper for making pointers
+  // Intrinsics and external functions, part 1: VM calls.
+  //   These are functions declared with JRT_ENTRY and JRT_EXIT,
+  //   macros which flip the thread from _thread_in_Java to
+  //   _thread_in_vm and back.  VM calls always safepoint, and can
+  //   therefore throw exceptions.  VM calls require of setup and
+  //   teardown, and must be called with SharkTopLevelBlock::call_vm.
  public:
-  llvm::Constant* make_pointer(intptr_t addr, const llvm::Type* type)
-  {
-    return llvm::ConstantExpr::getIntToPtr(
-      LLVMValue::intptr_constant(addr),
-      llvm::PointerType::getUnqual(type));
-  }
-
-  // External functions (and intrinsics)
- private:
-  llvm::Constant* _llvm_cmpxchg_int_fn;
-  llvm::Constant* _llvm_cmpxchg_ptr_fn;  
-  llvm::Constant* _llvm_memory_barrier_fn;
-  llvm::Constant* _llvm_memset_fn;  
-  llvm::Constant* _llvm_sin_fn;
-  llvm::Constant* _llvm_cos_fn;
-  llvm::Constant* _llvm_sqrt_fn;
-  llvm::Constant* _llvm_log_fn;
-  llvm::Constant* _llvm_log10_fn;
-  llvm::Constant* _llvm_pow_fn;
-  llvm::Constant* _llvm_exp_fn;
+  llvm::Value* find_exception_handler();
+  llvm::Value* monitorenter();
+  llvm::Value* monitorexit();
+  llvm::Value* new_instance();
+  llvm::Value* newarray();
+  llvm::Value* anewarray();
+  llvm::Value* multianewarray();
+  llvm::Value* register_finalizer();
+  llvm::Value* safepoint();
+  llvm::Value* throw_ArrayIndexOutOfBoundsException();
+  llvm::Value* throw_NullPointerException();
 
-  void set_llvm_cmpxchg_int_fn(llvm::Constant* llvm_cmpxchg_int_fn)
-  {
-    _llvm_cmpxchg_int_fn = llvm_cmpxchg_int_fn;
-  }
-  void set_llvm_cmpxchg_ptr_fn(llvm::Constant* llvm_cmpxchg_ptr_fn)
-  {
-    _llvm_cmpxchg_ptr_fn = llvm_cmpxchg_ptr_fn;
-  }
-  void set_llvm_memory_barrier_fn(llvm::Constant* llvm_memory_barrier_fn)
-  {
-    _llvm_memory_barrier_fn = llvm_memory_barrier_fn;
-  }
-  void set_llvm_memset_fn(llvm::Constant* llvm_memset_fn)
-  {
-    _llvm_memset_fn = llvm_memset_fn;
-  }
-  void set_llvm_sin_fn(llvm::Constant* llvm_sin_fn)
-  {
-    _llvm_sin_fn = llvm_sin_fn;
-  }
-  void set_llvm_cos_fn(llvm::Constant* llvm_cos_fn)
-  {
-    _llvm_cos_fn = llvm_cos_fn;
-  }
-  void set_llvm_sqrt_fn(llvm::Constant* llvm_sqrt_fn)
-  {
-    _llvm_sqrt_fn = llvm_sqrt_fn;
-  }
-  void set_llvm_log_fn(llvm::Constant* llvm_log_fn)
-  {
-    _llvm_log_fn = llvm_log_fn;
-  }
-  void set_llvm_log10_fn(llvm::Constant* llvm_log10_fn)
-  {
-    _llvm_log10_fn = llvm_log10_fn;
-  }
-  void set_llvm_pow_fn(llvm::Constant* llvm_pow_fn)
-  {
-    _llvm_pow_fn = llvm_pow_fn;
-  }
-  void set_llvm_exp_fn(llvm::Constant* llvm_exp_fn)
-  {
-    _llvm_exp_fn = llvm_exp_fn;
-  }
-
-  void init_external_functions();
+  // Intrinsics and external functions, part 2: High-level non-VM calls.
+  //   These are called like normal functions.  The stack is not set
+  //   up for walking so they must not safepoint or throw exceptions,
+  //   or call anything that might.
+ public:
+  llvm::Value* f2i();
+  llvm::Value* f2l();
+  llvm::Value* d2i();
+  llvm::Value* d2l();
+  llvm::Value* is_subtype_of();
+  llvm::Value* current_time_millis();
+  llvm::Value* sin();
+  llvm::Value* cos();
+  llvm::Value* tan();
+  llvm::Value* atan2();
+  llvm::Value* sqrt();
+  llvm::Value* log();
+  llvm::Value* log10();
+  llvm::Value* pow();
+  llvm::Value* exp();
+  llvm::Value* fabs();
+  llvm::Value* unsafe_field_offset_to_byte_offset();
 
- protected:
-  llvm::Constant* llvm_cmpxchg_int_fn() const
-  {
-    return _llvm_cmpxchg_int_fn;
-  }
-  llvm::Constant* llvm_cmpxchg_ptr_fn() const
-  {
-    return _llvm_cmpxchg_ptr_fn;
-  }
-  llvm::Constant* llvm_memory_barrier_fn() const
-  {
-    return _llvm_memory_barrier_fn;
-  }
-  llvm::Constant* llvm_memset_fn() const
-  {
-    return _llvm_memset_fn;
-  }
-
+  // Intrinsics and external functions, part 3: Uncommon trap.
+  //   This is a special case in that it is invoked like a non-VM
+  //   call but it does VM call stuff.  This is acceptable so long
+  //   as the method that calls uncommon_trap returns to its caller
+  //   immediately that uncommon_trap returns.
  public:
-  llvm::Constant* llvm_sin_fn() const
-  {
-    return _llvm_sin_fn;
-  }
-  llvm::Constant* llvm_cos_fn() const
-  {
-    return _llvm_cos_fn;
-  }
-  llvm::Constant* llvm_sqrt_fn() const
-  {
-    return _llvm_sqrt_fn;
-  }
-  llvm::Constant* llvm_log_fn() const
-  {
-    return _llvm_log_fn;
-  }
-  llvm::Constant* llvm_log10_fn() const
-  {
-    return _llvm_log10_fn;
-  }
-  llvm::Constant* llvm_pow_fn() const
-  {
-    return _llvm_pow_fn;
-  }
-  llvm::Constant* llvm_exp_fn() const
-  {
-    return _llvm_exp_fn;
-  }
+  llvm::Value* uncommon_trap();
 
+  // Intrinsics and external functions, part 4: Low-level non-VM calls.
+  //   These have the same caveats as the high-level non-VM calls
+  //   above.  They are not accessed directly; rather, you should
+  //   access them via the various Create* methods below.
+ private:
+  llvm::Value* cmpxchg_int();
+  llvm::Value* cmpxchg_ptr();
+  llvm::Value* memory_barrier();
+  llvm::Value* memset();
+  llvm::Value* unimplemented();
+  llvm::Value* should_not_reach_here();
+  llvm::Value* dump();  
+
+  // Public interface to low-level non-VM calls.
  public:
-  llvm::CallInst* CreateDump(llvm::Value* value);
+  llvm::CallInst* CreateCmpxchgInt(llvm::Value* exchange_value,
+                                   llvm::Value* dst,
+                                   llvm::Value* compare_value);
+  llvm::CallInst* CreateCmpxchgPtr(llvm::Value* exchange_value,
+                                   llvm::Value* dst,
+                                   llvm::Value* compare_value);
+  llvm::CallInst* CreateMemoryBarrier(int flags);
   llvm::CallInst* CreateMemset(llvm::Value* dst,
                                llvm::Value* value,
                                llvm::Value* len,
                                llvm::Value* align);
-  llvm::CallInst* CreateCmpxchgInt(llvm::Value* exchange_value,
-                                    llvm::Value* dst,
-                                    llvm::Value* compare_value);
-  llvm::CallInst* CreateCmpxchgPtr(llvm::Value* exchange_value,
-                                   llvm::Value* dst,
-                                   llvm::Value* compare_value);
+  llvm::CallInst* CreateUnimplemented(const char* file, int line);  
   llvm::CallInst* CreateShouldNotReachHere(const char* file, int line);  
-  llvm::CallInst* CreateUnimplemented(const char* file, int line);  
-
-  // HotSpot memory barriers
- public:
-  void CreateUpdateBarrierSet(BarrierSet* bs, llvm::Value* field)
-  {
-    if (bs->kind() != BarrierSet::CardTableModRef) {
-      Unimplemented();
-    }
-
-    CreateStore(
-      LLVMValue::jbyte_constant(CardTableModRefBS::dirty_card),
-      CreateIntToPtr(
-        CreateAdd(
-          pointer_constant(((CardTableModRefBS *) bs)->byte_map_base),
-          CreateLShr(
-            CreatePtrToInt(field, SharkType::intptr_type()),
-            LLVMValue::intptr_constant(CardTableModRefBS::card_shift))),
-        llvm::PointerType::getUnqual(SharkType::jbyte_type())));
-  }
-
-  // Hardware memory barriers
+  NOT_PRODUCT(llvm::CallInst* CreateDump(llvm::Value* value));
+  
+  // Flags for CreateMemoryBarrier.
  public:
   enum BarrierFlags {
     BARRIER_LOADLOAD   = 1,
@@ -348,48 +176,20 @@
     BARRIER_STORESTORE = 8
   };
 
- public:
-  llvm::CallInst* CreateMemoryBarrier(BarrierFlags flags);
-
-  // Alignment
+  // HotSpot memory barriers
  public:
-  llvm::Value* CreateAlign(llvm::Value* x, intptr_t s, const char* name = "")
-  {
-    assert(is_power_of_2(s), "should be");
-    return CreateAnd(
-      CreateAdd(x, LLVMValue::intptr_constant(s - 1)),
-      LLVMValue::intptr_constant(~(s - 1)),
-      name);
-  }
+  void CreateUpdateBarrierSet(BarrierSet* bs, llvm::Value* field);
 
-  // CodeBuffer interface
- private:
-  SharkCodeBuffer* _code_buffer;
-
+  // Helpers for accessing the code buffer.
  public:
-  SharkCodeBuffer* code_buffer() const
-  {
-    return _code_buffer;
-  }
-  void set_code_buffer(SharkCodeBuffer* code_buffer)
-  {
-    _code_buffer = code_buffer;
-  }
+  llvm::Value* code_buffer_address(int offset);
+  llvm::Value* CreateInlineOop(ciObject* object, const char* name = "");
 
+  // Helpers for creating basic blocks.
+  // NB don't use unless SharkFunction::CreateBlock is unavailable.
+  // XXX these are hacky and should be removed.
  public:
-  llvm::Value* code_buffer_address(int offset)
-  {
-    return CreateAdd(
-      code_buffer()->base_pc(), LLVMValue::intptr_constant(offset));
-  }
-
- public:
-  llvm::Value* CreateInlineOop(ciObject* object, const char* name = "")
-  {
-    return CreateLoad(
-      CreateIntToPtr(
-        code_buffer_address(code_buffer()->inline_oop(object)),
-        llvm::PointerType::getUnqual(SharkType::jobject_type())),
-      name);
-  }
+  llvm::BasicBlock* GetBlockInsertionPoint() const;
+  llvm::BasicBlock* CreateBlock(llvm::BasicBlock* ip,
+                                const char*       name="") const;
 };
--- a/ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -31,7 +31,7 @@
 void SharkDecacher::start_frame()
 {
   // Start recording the debug information
-  _pc_offset = builder()->code_buffer()->create_unique_offset();
+  _pc_offset = code_buffer()->create_unique_offset();
   _oopmap = new OopMap(
     oopmap_slot_munge(function()->oopmap_frame_size()),
     oopmap_slot_munge(arg_size()));
--- a/ports/hotspot/src/share/vm/shark/sharkCompiler.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkCompiler.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -53,9 +53,6 @@
   _module = new Module("shark");
 #endif
 
-  // Create the builder to build our functions
-  _builder = new SharkBuilder(this);
-
 #if SHARK_LLVM_VERSION >= 26
   // If we have a native target, initialize it to ensure it is linked in and
   // usable by the JIT.
@@ -82,7 +79,6 @@
 
   // Initialize Shark components that need it
   SharkType::initialize();
-  SharkRuntime::initialize(builder());
   mark_initialized();
 }
 
@@ -137,23 +133,20 @@
   env->debug_info()->set_oopmaps(&oopmaps);
   env->set_dependencies(new Dependencies(env));
 
-  // Create the code buffer and hook it into the builder
+  // Create the code buffer and builder
   SharkCodeBuffer cb(env->oop_recorder());
-  builder()->set_code_buffer(&cb);
+  SharkBuilder builder(module(), &cb);
 
   // Emit the entry point
   SharkEntry *entry = (SharkEntry *) cb.malloc(sizeof(SharkEntry));
   
   // Build the LLVM IR for the method
-  Function *function = SharkFunction::build(this, env, flow, name);
+  Function *function = SharkFunction::build(this, env, &builder, flow, name);
   if (SharkPrintBitcodeOf != NULL) {
     if (!fnmatch(SharkPrintBitcodeOf, name, 0))
       function->dump();
   }
 
-  // Unhook the code buffer
-  builder()->set_code_buffer(NULL);  
-
   // Compile to native code
 #ifndef PRODUCT
 #ifdef X86
--- a/ports/hotspot/src/share/vm/shark/sharkCompiler.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkCompiler.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -23,8 +23,6 @@
  *
  */
 
-class SharkBuilder;
-
 class SharkCompiler : public AbstractCompiler {
  public:
   // Creation
@@ -50,7 +48,6 @@
   // LLVM interface
  private:
   llvm::Module*          _module;
-  SharkBuilder*          _builder;
   SharkMemoryManager*    _memory_manager;
   llvm::ExecutionEngine* _execution_engine;
 
@@ -59,10 +56,6 @@
   {
     return _module;
   }
-  SharkBuilder* builder() const
-  {
-    return _builder;
-  }
   SharkMemoryManager* memory_manager() const
   {
     return _memory_manager;
--- a/ports/hotspot/src/share/vm/shark/sharkFunction.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkFunction.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -42,7 +42,7 @@
   method->setName("method");
   Argument *base_pc = ai++;
   base_pc->setName("base_pc");
-  builder()->code_buffer()->set_base_pc(base_pc);
+  code_buffer()->set_base_pc(base_pc);
   Argument *thread = ai++;
   thread->setName("thread");
   set_thread(thread);
--- a/ports/hotspot/src/share/vm/shark/sharkFunction.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkFunction.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -30,19 +30,21 @@
  public:
   static llvm::Function* build(SharkCompiler* compiler,
                                ciEnv*         env,
+                               SharkBuilder*  builder,
                                ciTypeFlow*    flow,
                                const char*    name)
   {
-    SharkFunction function(compiler, env, flow, name);
+    SharkFunction function(compiler, env, builder, flow, name);
     return function.function();
   }
 
  private:
   SharkFunction(SharkCompiler* compiler,
                 ciEnv*         env,
+                SharkBuilder*  builder,
                 ciTypeFlow*    flow,
                 const char*    name)
-    : SharkTargetInvariants(compiler, env, flow) { initialize(name); }
+    : SharkTargetInvariants(compiler, env, builder, flow) { initialize(name); }
 
  private:
   void initialize(const char* name);
--- a/ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkIntrinsics.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -92,34 +92,34 @@
     do_Math_minmax(llvm::ICmpInst::ICMP_SGE);
     break;
   case vmIntrinsics::_dabs:
-    do_Math_1to1(SharkRuntime::fabs());
+    do_Math_1to1(builder()->fabs());
     break;
   case vmIntrinsics::_dsin:
-    do_Math_1to1(builder()->llvm_sin_fn());
+    do_Math_1to1(builder()->sin());
     break;
   case vmIntrinsics::_dcos:
-    do_Math_1to1(builder()->llvm_cos_fn());
+    do_Math_1to1(builder()->cos());
     break;
   case vmIntrinsics::_dtan:
-    do_Math_1to1(SharkRuntime::tan());
+    do_Math_1to1(builder()->tan());
     break;
   case vmIntrinsics::_datan2:
-    do_Math_2to1(SharkRuntime::atan2());
+    do_Math_2to1(builder()->atan2());
     break;
   case vmIntrinsics::_dsqrt:
-    do_Math_1to1(builder()->llvm_sqrt_fn());
+    do_Math_1to1(builder()->sqrt());
     break;
   case vmIntrinsics::_dlog:
-    do_Math_1to1(builder()->llvm_log_fn());
+    do_Math_1to1(builder()->log());
     break;
   case vmIntrinsics::_dlog10:
-    do_Math_1to1(builder()->llvm_log10_fn());
+    do_Math_1to1(builder()->log10());
     break;
   case vmIntrinsics::_dpow:
-    do_Math_2to1(builder()->llvm_pow_fn());
+    do_Math_2to1(builder()->pow());
     break;
   case vmIntrinsics::_dexp:
-    do_Math_1to1(builder()->llvm_exp_fn());
+    do_Math_1to1(builder()->exp());
     break;
 
     // java.lang.Object
@@ -181,7 +181,7 @@
       sa->zero_checked() && sb->zero_checked()));
 }
 
-void SharkIntrinsics::do_Math_1to1(Constant *function)
+void SharkIntrinsics::do_Math_1to1(Value *function)
 {
   SharkValue *empty = state()->pop();
   assert(empty == NULL, "should be");
@@ -192,7 +192,7 @@
   state()->push(NULL);
 }
 
-void SharkIntrinsics::do_Math_2to1(Constant *function)
+void SharkIntrinsics::do_Math_2to1(Value *function)
 {
   SharkValue *empty = state()->pop();
   assert(empty == NULL, "should be");
@@ -235,7 +235,7 @@
 {
   state()->push(
     SharkValue::create_jlong(
-      builder()->CreateCall(SharkRuntime::current_time_millis()),
+      builder()->CreateCall(builder()->current_time_millis()),
       false));
   state()->push(NULL);
 }
@@ -264,7 +264,7 @@
 
   // Convert the offset
   offset = builder()->CreateCall(
-    SharkRuntime::unsafe_field_offset_to_byte_offset(),
+    builder()->unsafe_field_offset_to_byte_offset(),
     offset);
 
   // Locate the field
--- a/ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkIntrinsics.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -46,8 +46,8 @@
 
  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_Math_1to1(llvm::Value* function);
+  void do_Math_2to1(llvm::Value* function);
   void do_Object_getClass();
   void do_System_currentTimeMillis();
   void do_Thread_currentThread();
--- a/ports/hotspot/src/share/vm/shark/sharkInvariants.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkInvariants.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -31,25 +31,30 @@
 
 class SharkCompileInvariants : public ResourceObj {
  protected:
-  SharkCompileInvariants(SharkCompiler* compiler, ciEnv* env)
+  SharkCompileInvariants(SharkCompiler* compiler,
+                         ciEnv*         env,
+                         SharkBuilder*  builder)
     : _compiler(compiler),
       _env(env),
+      _builder(builder),
       _thread(NULL) {}
 
   SharkCompileInvariants(const SharkCompileInvariants* parent)
     : _compiler(parent->_compiler),
       _env(parent->_env),
+      _builder(parent->_builder),
       _thread(parent->_thread) {}
 
  private:
   SharkCompiler* _compiler;
   ciEnv*         _env;
+  SharkBuilder*  _builder;
   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.
+  // classes that form the interface with LLVM (the module, the
+  // memory manager, etc) and provides the compile() method to
+  // convert LLVM functions to native code.
  protected:
   SharkCompiler* compiler() const
   {
@@ -71,6 +76,13 @@
     return _env;
   }
 
+  // The SharkBuilder that is used to build LLVM IR.
+ protected:
+  SharkBuilder* builder() const
+  {
+    return _builder;
+  }
+
   // 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
@@ -89,10 +101,6 @@
   
   // Objects that handle various aspects of the compilation.
  protected:
-  SharkBuilder* builder() const
-  {
-    return compiler()->builder();
-  }
   DebugInformationRecorder* debug_info() const
   {
     return env()->debug_info();
@@ -101,6 +109,10 @@
   {
     return env()->dependencies();
   }
+  SharkCodeBuffer* code_buffer() const
+  {
+    return builder()->code_buffer();
+  }
 
   // That well-known class...
  protected:
@@ -112,8 +124,11 @@
 
 class SharkTargetInvariants : public SharkCompileInvariants {
  protected:
-  SharkTargetInvariants(SharkCompiler* compiler, ciEnv* env, ciTypeFlow* flow)
-    : SharkCompileInvariants(compiler, env),
+  SharkTargetInvariants(SharkCompiler* compiler,
+                        ciEnv*         env,
+                        SharkBuilder*  builder,
+                        ciTypeFlow*    flow)
+    : SharkCompileInvariants(compiler, env, builder),
       _target(flow->method()),
       _flow(flow),
       _max_monitors(count_monitors()) {}
--- a/ports/hotspot/src/share/vm/shark/sharkRuntime.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkRuntime.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -28,222 +28,9 @@
 
 using namespace llvm;
 
-// VM calls
-Constant* SharkRuntime::_find_exception_handler;
-Constant* SharkRuntime::_monitorenter;
-Constant* SharkRuntime::_monitorexit;
-Constant* SharkRuntime::_new_instance;
-Constant* SharkRuntime::_newarray;
-Constant* SharkRuntime::_anewarray;
-Constant* SharkRuntime::_multianewarray;
-Constant* SharkRuntime::_register_finalizer;
-Constant* SharkRuntime::_safepoint;
-Constant* SharkRuntime::_throw_ArrayIndexOutOfBoundsException;
-Constant* SharkRuntime::_throw_NullPointerException;
-
-// Leaf calls
-Constant* SharkRuntime::_f2i;
-Constant* SharkRuntime::_f2l;
-Constant* SharkRuntime::_d2i;
-Constant* SharkRuntime::_d2l;
-
-// Non-VM calls
-Constant* SharkRuntime::_dump;
-Constant* SharkRuntime::_is_subtype_of;
-Constant* SharkRuntime::_should_not_reach_here;
-Constant* SharkRuntime::_unimplemented;
-Constant* SharkRuntime::_uncommon_trap;
-Constant* SharkRuntime::_current_time_millis;
-Constant* SharkRuntime::_fabs;
-Constant* SharkRuntime::_tan;
-Constant* SharkRuntime::_atan2;
-Constant* SharkRuntime::_unsafe_field_offset_to_byte_offset;
-
-extern jlong Unsafe_field_offset_to_byte_offset(jlong field_offset);
-
-void SharkRuntime::initialize(SharkBuilder* builder)
-{
-  // VM calls
-  std::vector<const Type*> params;
-  params.push_back(SharkType::thread_type());
-  params.push_back(PointerType::getUnqual(SharkType::jint_type()));
-  params.push_back(SharkType::jint_type());
-  _find_exception_handler = builder->make_function(
-    (intptr_t) find_exception_handler_C,
-    FunctionType::get(SharkType::jint_type(), params, false),
-    "SharkRuntime__find_exception_handler");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(PointerType::getUnqual(SharkType::monitor_type()));
-  _monitorenter = builder->make_function(
-    (intptr_t) monitorenter_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__monitorenter");
-  _monitorexit = builder->make_function(
-    (intptr_t) monitorexit_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__monitorexit");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(SharkType::jint_type());
-  _new_instance = builder->make_function(
-    (intptr_t) new_instance_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__new_instance");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(SharkType::jint_type());
-  params.push_back(SharkType::jint_type());
-  _newarray = builder->make_function(
-    (intptr_t) newarray_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__newarray");
-  _anewarray = builder->make_function(
-    (intptr_t) anewarray_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__anewarray");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(SharkType::jint_type());
-  params.push_back(SharkType::jint_type());
-  params.push_back(PointerType::getUnqual(SharkType::jint_type()));
-  _multianewarray = builder->make_function(
-    (intptr_t) multianewarray_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__multianewarray");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(SharkType::oop_type());
-  _register_finalizer = builder->make_function(
-    (intptr_t) register_finalizer_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__register_finalizer");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  _safepoint = builder->make_function(
-    (intptr_t) SafepointSynchronize::block,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SafepointSynchronize__block");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(SharkType::intptr_type());
-  params.push_back(SharkType::jint_type());
-  params.push_back(SharkType::jint_type());
-  _throw_ArrayIndexOutOfBoundsException = builder->make_function(
-    (intptr_t) throw_ArrayIndexOutOfBoundsException_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__throw_ArrayIndexOutOfBoundsException");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(SharkType::intptr_type());
-  params.push_back(SharkType::jint_type());
-  _throw_NullPointerException = builder->make_function(
-    (intptr_t) throw_NullPointerException_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__throw_NullPointerException");
-
-  // Leaf calls
-  params.clear();
-  params.push_back(SharkType::jfloat_type());
-  _f2i = builder->make_function(
-    (intptr_t) SharedRuntime::f2i,
-    FunctionType::get(SharkType::jint_type(), params, false),
-    "SharedRuntime__f2i");  
-  _f2l = builder->make_function(
-    (intptr_t) SharedRuntime::f2l,
-    FunctionType::get(SharkType::jlong_type(), params, false),
-    "SharedRuntime__f2l");  
-
-  params.clear();
-  params.push_back(SharkType::jdouble_type());
-  _d2i = builder->make_function(
-    (intptr_t) SharedRuntime::d2i,
-    FunctionType::get(SharkType::jint_type(), params, false),
-    "SharedRuntime__d2i");  
-  _d2l = builder->make_function(
-    (intptr_t) SharedRuntime::d2l,
-    FunctionType::get(SharkType::jlong_type(), params, false),
-    "SharedRuntime__d2l");  
-  
-  // Non-VM calls
-  params.clear();
-  params.push_back(SharkType::intptr_type());
-  params.push_back(SharkType::intptr_type());
-  _dump = builder->make_function(
-    (intptr_t) dump_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__dump");
-
-  params.clear();
-  params.push_back(SharkType::oop_type());
-  params.push_back(SharkType::oop_type());
-  assert(sizeof(bool) == 1, "fix this");
-  _is_subtype_of = builder->make_function(
-    (intptr_t) is_subtype_of_C,
-    FunctionType::get(Type::Int8Ty, params, false),
-    "SharkRuntime__is_subtype_of");
-
-  params.clear();
-  params.push_back(SharkType::intptr_type());
-  params.push_back(SharkType::jint_type());
-  _should_not_reach_here = builder->make_function(
-    (intptr_t) report_should_not_reach_here,
-    FunctionType::get(Type::VoidTy, params, false),
-    "report_should_not_reach_here");
-  _unimplemented = builder->make_function(
-    (intptr_t) report_unimplemented,
-    FunctionType::get(Type::VoidTy, params, false),
-    "report_unimplemented");
-
-  params.clear();
-  params.push_back(SharkType::thread_type());
-  params.push_back(SharkType::jint_type());
-  _uncommon_trap = builder->make_function(
-    (intptr_t) uncommon_trap_C,
-    FunctionType::get(Type::VoidTy, params, false),
-    "SharkRuntime__uncommon_trap");
-
-  params.clear();
-  _current_time_millis = builder->make_function(
-    (intptr_t) os::javaTimeMillis,
-    FunctionType::get(SharkType::jlong_type(), params, false),
-    "os__javaTimeMillis");
-
-  params.clear();
-  params.push_back(SharkType::jdouble_type());
-  _fabs = builder->make_function(
-    (intptr_t) ::fabs,
-    FunctionType::get(SharkType::jdouble_type(), params, false),
-    "fabs");
-  _tan = builder->make_function(
-    (intptr_t) ::tan,
-    FunctionType::get(SharkType::jdouble_type(), params, false),
-    "tan");
-  params.push_back(SharkType::jdouble_type());
-  _atan2 = builder->make_function(
-    (intptr_t) ::atan2,
-    FunctionType::get(SharkType::jdouble_type(), params, false),
-    "atan2");
-
-  params.clear();
-  params.push_back(SharkType::jlong_type());
-  _unsafe_field_offset_to_byte_offset = builder->make_function(
-    (intptr_t) Unsafe_field_offset_to_byte_offset,
-    FunctionType::get(SharkType::jlong_type(), params, false),
-    "Unsafe_field_offset_to_byte_offset");
-}
-
-JRT_ENTRY(int, SharkRuntime::find_exception_handler_C(JavaThread* thread,
-                                                      int*        indexes,
-                                                      int         num_indexes))
+JRT_ENTRY(int, SharkRuntime::find_exception_handler(JavaThread* thread,
+                                                    int*        indexes,
+                                                    int         num_indexes))
 {
   constantPoolHandle pool(thread, method(thread)->constants());
   KlassHandle exc_klass(thread, ((oop) tos_at(thread, 0))->klass());
@@ -263,8 +50,8 @@
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::monitorenter_C(JavaThread*      thread,
-                                             BasicObjectLock* lock))
+JRT_ENTRY(void, SharkRuntime::monitorenter(JavaThread*      thread,
+                                           BasicObjectLock* lock))
 {
   if (PrintBiasedLockingStatistics)
     Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
@@ -281,8 +68,8 @@
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::monitorexit_C(JavaThread*      thread,
-                                            BasicObjectLock* lock))
+JRT_ENTRY(void, SharkRuntime::monitorexit(JavaThread*      thread,
+                                          BasicObjectLock* lock))
 {
   Handle object(thread, lock->obj());  
   assert(Universe::heap()->is_in_reserved_or_null(object()), "should be");
@@ -293,7 +80,7 @@
 }
 JRT_END
   
-JRT_ENTRY(void, SharkRuntime::new_instance_C(JavaThread* thread, int index))
+JRT_ENTRY(void, SharkRuntime::new_instance(JavaThread* thread, int index))
 {
   klassOop k_oop = method(thread)->constants()->klass_at(index, CHECK);
   instanceKlassHandle klass(THREAD, k_oop);
@@ -323,18 +110,18 @@
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::newarray_C(JavaThread* thread,
-                                         BasicType   type,
-                                         int         size))
+JRT_ENTRY(void, SharkRuntime::newarray(JavaThread* thread,
+                                       BasicType   type,
+                                       int         size))
 {
   oop obj = oopFactory::new_typeArray(type, size, CHECK);
   thread->set_vm_result(obj);
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::anewarray_C(JavaThread* thread,
-                                          int         index,
-                                          int         size))
+JRT_ENTRY(void, SharkRuntime::anewarray(JavaThread* thread,
+                                        int         index,
+                                        int         size))
 {
   klassOop klass = method(thread)->constants()->klass_at(index, CHECK);
   objArrayOop obj = oopFactory::new_objArray(klass, size, CHECK);
@@ -342,10 +129,10 @@
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::multianewarray_C(JavaThread* thread,
-                                               int         index,
-                                               int         ndims,
-                                               int*        dims))
+JRT_ENTRY(void, SharkRuntime::multianewarray(JavaThread* thread,
+                                             int         index,
+                                             int         ndims,
+                                             int*        dims))
 {
   klassOop klass = method(thread)->constants()->klass_at(index, CHECK);
   oop obj = arrayKlass::cast(klass)->multi_allocate(ndims, dims, CHECK);
@@ -353,8 +140,8 @@
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::register_finalizer_C(JavaThread* thread,
-                                                   oop         object))
+JRT_ENTRY(void, SharkRuntime::register_finalizer(JavaThread* thread,
+                                                 oop         object))
 {
   assert(object->is_oop(), "should be");
   assert(object->klass()->klass_part()->has_finalizer(), "should have");
@@ -362,7 +149,7 @@
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::throw_ArrayIndexOutOfBoundsException_C(
+JRT_ENTRY(void, SharkRuntime::throw_ArrayIndexOutOfBoundsException(
                                                      JavaThread* thread,
                                                      const char* file,
                                                      int         line,
@@ -377,9 +164,9 @@
 }
 JRT_END
 
-JRT_ENTRY(void, SharkRuntime::throw_NullPointerException_C(JavaThread* thread,
-                                                           const char* file,
-                                                           int         line))
+JRT_ENTRY(void, SharkRuntime::throw_NullPointerException(JavaThread* thread,
+                                                         const char* file,
+                                                         int         line))
 {
   Exceptions::_throw_msg(
     thread, file, line, 
@@ -391,7 +178,7 @@
 // Non-VM calls
 // Nothing in these must ever GC!
 
-void SharkRuntime::dump_C(const char *name, intptr_t value)
+void SharkRuntime::dump(const char *name, intptr_t value)
 {
   oop valueOop = (oop) value;
   tty->print("%s = ", name);
@@ -404,12 +191,12 @@
   tty->print_cr("");
 }
 
-bool SharkRuntime::is_subtype_of_C(klassOop check_klass, klassOop object_klass)
+bool SharkRuntime::is_subtype_of(klassOop check_klass, klassOop object_klass)
 {
   return object_klass->klass_part()->is_subtype_of(check_klass);
 }
 
-void SharkRuntime::uncommon_trap_C(JavaThread* thread, int trap_request)
+void SharkRuntime::uncommon_trap(JavaThread* thread, int trap_request)
 {
   // In C2, uncommon_trap_blob creates a frame, so all the various
   // deoptimization functions expect to find the frame of the method
--- a/ports/hotspot/src/share/vm/shark/sharkRuntime.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkRuntime.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -24,94 +24,32 @@
  */
 
 class SharkRuntime : public AllStatic {
- public:
-  static void initialize(SharkBuilder* builder);
-
   // VM calls
- private:
-  static llvm::Constant* _find_exception_handler;
-  static llvm::Constant* _monitorenter;
-  static llvm::Constant* _monitorexit;
-  static llvm::Constant* _new_instance;
-  static llvm::Constant* _newarray;
-  static llvm::Constant* _anewarray;
-  static llvm::Constant* _multianewarray;
-  static llvm::Constant* _register_finalizer;
-  static llvm::Constant* _safepoint;
-  static llvm::Constant* _throw_ArrayIndexOutOfBoundsException;
-  static llvm::Constant* _throw_NullPointerException;
-
  public:
-  static llvm::Constant* find_exception_handler()
-  {
-    return _find_exception_handler;
-  }
-  static llvm::Constant* monitorenter()
-  {
-    return _monitorenter;
-  }
-  static llvm::Constant* monitorexit()
-  {
-    return _monitorexit;
-  }
-  static llvm::Constant* new_instance()
-  {
-    return _new_instance;
-  }
-  static llvm::Constant* newarray()
-  {
-    return _newarray;
-  }
-  static llvm::Constant* anewarray()
-  {
-    return _anewarray;
-  }
-  static llvm::Constant* multianewarray()
-  {
-    return _multianewarray;
-  }
-  static llvm::Constant* register_finalizer()
-  {
-    return _register_finalizer;
-  }
-  static llvm::Constant* safepoint()
-  {
-    return _safepoint;
-  }
-  static llvm::Constant* throw_ArrayIndexOutOfBoundsException()
-  {
-    return _throw_ArrayIndexOutOfBoundsException;
-  }
-  static llvm::Constant* throw_NullPointerException()
-  {
-    return _throw_NullPointerException;
-  }  
+  static int find_exception_handler(JavaThread* thread,
+                                    int*        indexes,
+                                    int         num_indexes);
+
+  static void monitorenter(JavaThread* thread, BasicObjectLock* lock);
+  static void monitorexit(JavaThread* thread, BasicObjectLock* lock);
 
- private:
-  static int find_exception_handler_C(JavaThread* thread,
-                                      int*        indexes,
-                                      int         num_indexes);
-
-  static void monitorenter_C(JavaThread* thread, BasicObjectLock* lock);
-  static void monitorexit_C(JavaThread* thread, BasicObjectLock* lock);
+  static void new_instance(JavaThread* thread, int index);
+  static void newarray(JavaThread* thread, BasicType type, int size);
+  static void anewarray(JavaThread* thread, int index, int size);
+  static void multianewarray(JavaThread* thread,
+                             int         index,
+                             int         ndims,
+                             int*        dims);
 
-  static void new_instance_C(JavaThread* thread, int index);
-  static void newarray_C(JavaThread* thread, BasicType type, int size);
-  static void anewarray_C(JavaThread* thread, int index, int size);
-  static void multianewarray_C(JavaThread* thread,
-                               int         index,
-                               int         ndims,
-                               int*        dims);
+  static void register_finalizer(JavaThread* thread, oop object);
 
-  static void register_finalizer_C(JavaThread* thread, oop object);
-
-  static void throw_ArrayIndexOutOfBoundsException_C(JavaThread* thread,
-                                                     const char* file,
-                                                     int         line,
-                                                     int         index);
-  static void throw_NullPointerException_C(JavaThread* thread,
-                                           const char* file,
-                                           int         line);
+  static void throw_ArrayIndexOutOfBoundsException(JavaThread* thread,
+                                                   const char* file,
+                                                   int         line,
+                                                   int         index);
+  static void throw_NullPointerException(JavaThread* thread,
+                                         const char* file,
+                                         int         line);
 
   // Helpers for VM calls
  private:
@@ -136,88 +74,9 @@
     return *(thread->zero_stack()->sp() + offset);
   }  
 
-  // Leaf calls
- private:
-  static llvm::Constant* _f2i;
-  static llvm::Constant* _f2l;
-  static llvm::Constant* _d2i;
-  static llvm::Constant* _d2l;
-
- public:
-  static llvm::Constant* f2i()
-  {
-    return _f2i;
-  }  
-  static llvm::Constant* f2l()
-  {
-    return _f2l;
-  }  
-  static llvm::Constant* d2i()
-  {
-    return _d2i;
-  }  
-  static llvm::Constant* d2l()
-  {
-    return _d2l;
-  }  
-  
   // Non-VM calls
- private:
-  static llvm::Constant* _dump;
-  static llvm::Constant* _is_subtype_of;
-  static llvm::Constant* _should_not_reach_here;
-  static llvm::Constant* _unimplemented;
-  static llvm::Constant* _uncommon_trap;
-  static llvm::Constant* _current_time_millis;
-  static llvm::Constant* _fabs;
-  static llvm::Constant* _tan;
-  static llvm::Constant* _atan2;
-  static llvm::Constant* _unsafe_field_offset_to_byte_offset;
-
  public:
-  static llvm::Constant* dump()
-  {
-    return _dump;
-  }
-  static llvm::Constant* is_subtype_of()
-  {
-    return _is_subtype_of;
-  }
-  static llvm::Constant* should_not_reach_here()
-  {
-    return _should_not_reach_here;
-  }
-  static llvm::Constant* unimplemented()
-  {
-    return _unimplemented;
-  }
-  static llvm::Constant* uncommon_trap()
-  {
-    return _uncommon_trap;
-  }
-  static llvm::Constant* current_time_millis()
-  {
-    return _current_time_millis;
-  }
-  static llvm::Constant* fabs()
-  {
-    return _fabs;
-  }
-  static llvm::Constant* tan()
-  {
-    return _tan;
-  }
-  static llvm::Constant* atan2()
-  {
-    return _atan2;
-  }
-  static llvm::Constant* unsafe_field_offset_to_byte_offset()
-  {
-    return _unsafe_field_offset_to_byte_offset;
-  }  
-
- private:
-  static void dump_C(const char *name, intptr_t value);
-  static bool is_subtype_of_C(klassOop check_klass, klassOop object_klass); 
-  static void uncommon_trap_C(JavaThread* thread, int trap_request);
+  static void dump(const char *name, intptr_t value);
+  static bool is_subtype_of(klassOop check_klass, klassOop object_klass); 
+  static void uncommon_trap(JavaThread* thread, int trap_request);
 };
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Thu Jul 30 04:51:32 2009 -0400
@@ -324,8 +324,10 @@
   builder()->SetInsertPoint(zero_block);
   if (value->is_jobject()) {
     call_vm(
-      SharkRuntime::throw_NullPointerException(),
-      builder()->pointer_constant(__FILE__),
+      builder()->throw_NullPointerException(),
+      builder()->CreateIntToPtr(
+        LLVMValue::intptr_constant((intptr_t) __FILE__),
+        PointerType::getUnqual(SharkType::jbyte_type())),
       LLVMValue::jint_constant(__LINE__),
       EX_CHECK_NONE);
   }
@@ -349,8 +351,10 @@
   builder()->SetInsertPoint(out_of_bounds);
   SharkState *saved_state = current_state()->copy();
   call_vm(
-    SharkRuntime::throw_ArrayIndexOutOfBoundsException(),
-    builder()->pointer_constant(__FILE__),
+    builder()->throw_ArrayIndexOutOfBoundsException(),
+    builder()->CreateIntToPtr(
+      LLVMValue::intptr_constant((intptr_t) __FILE__),
+      PointerType::getUnqual(SharkType::jbyte_type())),
     LLVMValue::jint_constant(__LINE__),
     index->jint_value(),
     EX_CHECK_NONE);
@@ -433,7 +437,7 @@
           builder()->CreateStructGEP(options, i));
 
       Value *index = call_vm(
-        SharkRuntime::find_exception_handler(),
+        builder()->find_exception_handler(),
         builder()->CreateStructGEP(options, 0),
         LLVMValue::jint_constant(num_options),
         EX_CHECK_NO_CATCH);
@@ -483,7 +487,8 @@
 
   Value *state = builder()->CreateLoad(
     builder()->CreateIntToPtr(
-      builder()->pointer_constant(SafepointSynchronize::address_of_state()),
+      LLVMValue::intptr_constant(
+        (intptr_t) SafepointSynchronize::address_of_state()),
       PointerType::getUnqual(SharkType::jint_type())),
     "state");
 
@@ -494,7 +499,7 @@
     do_safepoint, safepointed);
 
   builder()->SetInsertPoint(do_safepoint);
-  call_vm(SharkRuntime::safepoint(), EX_CHECK_FULL);
+  call_vm(builder()->safepoint(), EX_CHECK_FULL);
   BasicBlock *safepointed_block = builder()->GetInsertBlock();  
   builder()->CreateBr(safepointed);
 
@@ -553,7 +558,7 @@
 {
   decache_for_trap();
   builder()->CreateCall2(
-    SharkRuntime::uncommon_trap(),
+    builder()->uncommon_trap(),
     thread(),
     LLVMValue::jint_constant(trap_request));
   builder()->CreateRetVoid();
@@ -594,7 +599,7 @@
     do_call, done);
 
   builder()->SetInsertPoint(do_call);
-  call_vm(SharkRuntime::register_finalizer(), receiver, EX_CHECK_FULL);
+  call_vm(builder()->register_finalizer(), receiver, EX_CHECK_FULL);
   BasicBlock *branch_block = builder()->GetInsertBlock();  
   builder()->CreateBr(done);
 
@@ -989,16 +994,19 @@
     builder()->CreateIntCast(vtable_length, SharkType::intptr_type(), false);
 
   bool needs_aligning = HeapWordsPerLong > 1;
-  const char *itable_start_name = "itable_start";
   Value *itable_start = builder()->CreateAdd(
     vtable_start,
     builder()->CreateShl(
       vtable_length,
       LLVMValue::intptr_constant(exact_log2(vtableEntry::size() * wordSize))),
-    needs_aligning ? "" : itable_start_name);
-  if (needs_aligning)
-    itable_start = builder()->CreateAlign(
-      itable_start, BytesPerLong, itable_start_name);
+    needs_aligning ? "" : "itable_start");
+  if (needs_aligning) {
+    itable_start = builder()->CreateAnd(
+      builder()->CreateAdd(
+        itable_start, LLVMValue::intptr_constant(BytesPerLong - 1)),
+      LLVMValue::intptr_constant(~(BytesPerLong - 1)),
+      "itable_start");
+  }
 
   // Locate this interface's entry in the table
   Value *iklass = builder()->CreateInlineOop(method->holder());
@@ -1327,7 +1335,7 @@
   builder()->CreateCondBr(
     builder()->CreateICmpNE(
       builder()->CreateCall2(
-        SharkRuntime::is_subtype_of(), check_klass, object_klass),
+        builder()->is_subtype_of(), check_klass, object_klass),
       LLVMValue::jbyte_constant(0)),
     is_instance, not_instance);
 
@@ -1483,13 +1491,13 @@
 
     // Heap allocation
     Value *top_addr = builder()->CreateIntToPtr(
-	builder()->pointer_constant(Universe::heap()->top_addr()),
+	LLVMValue::intptr_constant((intptr_t) Universe::heap()->top_addr()),
       PointerType::getUnqual(SharkType::intptr_type()),
       "top_addr");
 
     Value *end = builder()->CreateLoad(
       builder()->CreateIntToPtr(
-        builder()->pointer_constant(Universe::heap()->end_addr()),
+        LLVMValue::intptr_constant((intptr_t) Universe::heap()->end_addr()),
         PointerType::getUnqual(SharkType::intptr_type())),
       "end");
 
@@ -1565,7 +1573,7 @@
 
   // The slow path
   call_vm(
-    SharkRuntime::new_instance(),
+    builder()->new_instance(),
     LLVMValue::jint_constant(iter()->get_klass_index()),
     EX_CHECK_FULL);
   slow_object = function()->CreateGetVMResult();
@@ -1595,7 +1603,7 @@
   BasicType type = (BasicType) iter()->get_index();
 
   call_vm(
-    SharkRuntime::newarray(),
+    builder()->newarray(),
     LLVMValue::jint_constant(type),
     pop()->jint_value(),
     EX_CHECK_FULL);
@@ -1618,7 +1626,7 @@
   }
 
   call_vm(
-    SharkRuntime::anewarray(),
+    builder()->anewarray(),
     LLVMValue::jint_constant(iter()->get_klass_index()),
     pop()->jint_value(),
     EX_CHECK_FULL);
@@ -1650,7 +1658,7 @@
   }
 
   call_vm(
-    SharkRuntime::multianewarray(),
+    builder()->multianewarray(),
     LLVMValue::jint_constant(iter()->get_klass_index()),
     LLVMValue::jint_constant(ndims),
     builder()->CreateStructGEP(dimensions, 0),
@@ -1764,7 +1772,7 @@
   // It's not a recursive case so we need to drop into the runtime
   builder()->SetInsertPoint(not_recursive);
   call_vm(
-    SharkRuntime::monitorenter(), monitor_addr,
+    builder()->monitorenter(), monitor_addr,
     exception_action | EAM_MONITOR_FUDGE);
   BasicBlock *acquired_slow = builder()->GetInsertBlock();
   builder()->CreateBr(lock_acquired);  
@@ -1817,7 +1825,7 @@
 
   // Need to drop into the runtime to release this one
   builder()->SetInsertPoint(slow_path);
-  call_vm(SharkRuntime::monitorexit(), monitor_addr, exception_action);
+  call_vm(builder()->monitorexit(), monitor_addr, exception_action);
   BasicBlock *released_slow = builder()->GetInsertBlock();
   builder()->CreateBr(lock_released);  
 
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp	Fri Jul 17 06:04:59 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.hpp	Thu Jul 30 04:51:32 2009 -0400
@@ -256,10 +256,10 @@
 
   // VM calls
  private:
-  llvm::CallInst* call_vm(llvm::Constant* callee,
-                          llvm::Value**   args_start,
-                          llvm::Value**   args_end,
-                          int             exception_action)
+  llvm::CallInst* call_vm(llvm::Value*  callee,
+                          llvm::Value** args_start,
+                          llvm::Value** args_end,
+                          int           exception_action)
   {
     decache_for_VM_call();
     function()->set_last_Java_frame();
@@ -274,32 +274,32 @@
   }
 
  public:
-  llvm::CallInst* call_vm(llvm::Constant* callee,
-                          int             exception_action)
+  llvm::CallInst* call_vm(llvm::Value* callee,
+                          int          exception_action)
   {
     llvm::Value *args[] = {thread()};
     return call_vm(callee, args, args + 1, exception_action);
   }
-  llvm::CallInst* call_vm(llvm::Constant* callee,
-                          llvm::Value*    arg1,
-                          int             exception_action)
+  llvm::CallInst* call_vm(llvm::Value* callee,
+                          llvm::Value* arg1,
+                          int          exception_action)
   {
     llvm::Value *args[] = {thread(), arg1};
     return call_vm(callee, args, args + 2, exception_action);
   }
-  llvm::CallInst* call_vm(llvm::Constant* callee,
-                          llvm::Value*    arg1,
-                          llvm::Value*    arg2,
-                          int             exception_action)
+  llvm::CallInst* call_vm(llvm::Value* callee,
+                          llvm::Value* arg1,
+                          llvm::Value* arg2,
+                          int          exception_action)
   {
     llvm::Value *args[] = {thread(), arg1, arg2};
     return call_vm(callee, args, args + 3, exception_action);
   }
-  llvm::CallInst* call_vm(llvm::Constant* callee,
-                          llvm::Value*    arg1,
-                          llvm::Value*    arg2,
-                          llvm::Value*    arg3,
-                          int             exception_action)
+  llvm::CallInst* call_vm(llvm::Value* callee,
+                          llvm::Value* arg1,
+                          llvm::Value* arg2,
+                          llvm::Value* arg3,
+                          int          exception_action)
   {
     llvm::Value *args[] = {thread(), arg1, arg2, arg3};
     return call_vm(callee, args, args + 4, exception_action);