changeset 1578:724f230eea38

2009-06-03 Gary Benson <gbenson@redhat.com> * ports/hotspot/src/share/vm/shark/sharkCodeBuffer.hpp: New file. * ports/hotspot/src/share/vm/shark/sharkBuilder.hpp (SharkBuilder::_code_buffer): New field. (SharkBuilder::code_buffer): New method. (SharkBuilder::set_code_buffer): Likewise. (SharkBuilder::code_buffer_address): Likewise. (SharkBuilder::CreateInlineOop): Likewise. * ports/hotspot/src/share/vm/shark/sharkCompiler.cpp (SharkCompiler::compile_method): Use a SharkCodeBuffer instead of a normal CodeBuffer and MacroAssembler, and hook it into the SharkBuilder. * ports/hotspot/src/share/vm/shark/sharkFunction.hpp (SharkFunction::SharkFunction): Removed masm argument and initialization. (SharkFunction::_masm): Removed. (SharkFunction::_base_pc): Likewise. (SharkFunction::masm): Likewise. (SharkFunction::base_pc): Likewise. (SharkFunction::create_unique_pc_offset): Likewise. (SharkFunction::CreateAddressOfCodeBufferEntry): Likewise. (SharkFunction::CreateAddressOfOopInCodeBuffer): Likewise. * ports/hotspot/src/share/vm/shark/sharkFunction.cpp (SharkFunction::initialize): Use the new code to allocate the SharkEntry, and set the base_pc for the SharkCodeBuffer. * ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp (SharkTopLevelBlock::get_direct_callee): Use new code. * ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp (SharkDecacher::start_frame): Use new code. (SharkDecacher::start_stack): Likewise. * ports/hotspot/src/share/vm/includeDB_shark: Updated.
author Gary Benson <gbenson@redhat.com>
date Wed, 03 Jun 2009 11:15:36 -0400
parents d50608f15874
children 89bd8e0f38c5
files ChangeLog ports/hotspot/src/share/vm/includeDB_shark ports/hotspot/src/share/vm/shark/sharkBuilder.hpp ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp ports/hotspot/src/share/vm/shark/sharkCodeBuffer.hpp ports/hotspot/src/share/vm/shark/sharkCompiler.cpp ports/hotspot/src/share/vm/shark/sharkFunction.cpp ports/hotspot/src/share/vm/shark/sharkFunction.hpp ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
diffstat 9 files changed, 193 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 03 09:37:51 2009 -0400
+++ b/ChangeLog	Wed Jun 03 11:15:36 2009 -0400
@@ -1,3 +1,43 @@
+2009-06-03  Gary Benson  <gbenson@redhat.com>
+
+	* ports/hotspot/src/share/vm/shark/sharkCodeBuffer.hpp:
+	New file.
+
+	* ports/hotspot/src/share/vm/shark/sharkBuilder.hpp
+	(SharkBuilder::_code_buffer): New field.
+	(SharkBuilder::code_buffer): New method.
+	(SharkBuilder::set_code_buffer): Likewise.
+	(SharkBuilder::code_buffer_address): Likewise.
+	(SharkBuilder::CreateInlineOop): Likewise.
+
+	* ports/hotspot/src/share/vm/shark/sharkCompiler.cpp
+	(SharkCompiler::compile_method):  Use a SharkCodeBuffer
+	instead of a normal CodeBuffer and MacroAssembler, and
+	hook it into the SharkBuilder.
+
+	* ports/hotspot/src/share/vm/shark/sharkFunction.hpp
+	(SharkFunction::SharkFunction): Removed masm argument
+	and initialization.
+	(SharkFunction::_masm): Removed.
+	(SharkFunction::_base_pc): Likewise.
+	(SharkFunction::masm): Likewise.
+	(SharkFunction::base_pc): Likewise.
+	(SharkFunction::create_unique_pc_offset): Likewise.
+	(SharkFunction::CreateAddressOfCodeBufferEntry): Likewise.
+	(SharkFunction::CreateAddressOfOopInCodeBuffer): Likewise.
+	* ports/hotspot/src/share/vm/shark/sharkFunction.cpp
+	(SharkFunction::initialize): Use the new code to allocate
+	the SharkEntry, and set the base_pc for the SharkCodeBuffer.
+
+	* ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp
+	(SharkTopLevelBlock::get_direct_callee): Use new code.
+
+	* ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp
+	(SharkDecacher::start_frame): Use new code.
+	(SharkDecacher::start_stack): Likewise.
+
+	* ports/hotspot/src/share/vm/includeDB_shark: Updated.
+
 2009-06-03  Gary Benson  <gbenson@redhat.com>
 
 	* ports/hotspot/src/cpu/zero/vm/assembler_zero.cpp:
--- a/ports/hotspot/src/share/vm/includeDB_shark	Wed Jun 03 09:37:51 2009 -0400
+++ b/ports/hotspot/src/share/vm/includeDB_shark	Wed Jun 03 11:15:36 2009 -0400
@@ -107,6 +107,7 @@
 sharkBuilder.hpp                        llvmHeaders.hpp
 sharkBuilder.hpp                        llvmValue.hpp
 sharkBuilder.hpp                        sizes.hpp
+sharkBuilder.hpp                        sharkCodeBuffer.hpp
 sharkBuilder.hpp                        sharkCompiler.hpp
 sharkBuilder.hpp                        sharkType.hpp
 sharkBuilder.hpp                        sharkValue.hpp
@@ -128,10 +129,13 @@
 sharkCacheDecache.hpp                   sharkFunction.hpp
 sharkCacheDecache.hpp                   sharkStateScanner.hpp
 
+sharkCodeBuffer.hpp                     allocation.hpp
+sharkCodeBuffer.hpp                     codeBuffer.hpp
+sharkCodeBuffer.hpp                     llvmHeaders.hpp
+
 sharkCompiler.cpp                       abstractCompiler.hpp
 sharkCompiler.cpp                       ciEnv.hpp
 sharkCompiler.cpp                       ciMethod.hpp
-sharkCompiler.cpp                       codeBuffer.hpp
 sharkCompiler.cpp                       debug.hpp
 sharkCompiler.cpp                       debugInfoRec.hpp
 sharkCompiler.cpp                       dependencies.hpp
@@ -141,6 +145,7 @@
 sharkCompiler.cpp                       oopRecorder.hpp
 sharkCompiler.cpp                       shark_globals.hpp
 sharkCompiler.cpp                       sharkBuilder.hpp
+sharkCompiler.cpp                       sharkCodeBuffer.hpp
 sharkCompiler.cpp                       sharkCompiler.hpp
 sharkCompiler.cpp                       sharkEntry.hpp
 sharkCompiler.cpp                       sharkFunction.hpp
--- a/ports/hotspot/src/share/vm/shark/sharkBuilder.hpp	Wed Jun 03 09:37:51 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkBuilder.hpp	Wed Jun 03 11:15:36 2009 -0400
@@ -360,4 +360,35 @@
       LLVMValue::intptr_constant(~(s - 1)),
       name);
   }
+
+  // CodeBuffer interface
+ private:
+  SharkCodeBuffer* _code_buffer;
+
+ public:
+  SharkCodeBuffer* code_buffer() const
+  {
+    return _code_buffer;
+  }
+  void set_code_buffer(SharkCodeBuffer* code_buffer)
+  {
+    _code_buffer = code_buffer;
+  }
+
+ 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);
+  }
 };
--- a/ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp	Wed Jun 03 09:37:51 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkCacheDecache.cpp	Wed Jun 03 11:15:36 2009 -0400
@@ -31,7 +31,7 @@
 void SharkDecacher::start_frame()
 {
   // Start recording the debug information
-  _pc_offset = function()->create_unique_pc_offset();
+  _pc_offset = builder()->code_buffer()->create_unique_offset();
   _oopmap = new OopMap(
     oopmap_slot_munge(function()->oopmap_frame_size()),
     oopmap_slot_munge(function()->arg_size()));
@@ -119,7 +119,7 @@
 {
   // Record the PC
   builder()->CreateStore(
-    function()->CreateAddressOfCodeBufferEntry(pc_offset()),
+    builder()->code_buffer_address(pc_offset()),
     function()->CreateAddressOfFrameEntry(offset));
 }
   
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ports/hotspot/src/share/vm/shark/sharkCodeBuffer.hpp	Wed Jun 03 11:15:36 2009 -0400
@@ -0,0 +1,94 @@
+/*
+ * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2009 Red Hat, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ */
+
+class SharkCodeBuffer : public StackObj {
+ public:
+  SharkCodeBuffer(OopRecorder* oop_recorder)
+    : _cb("Shark", 256 * K, 64 * K),
+      _masm(new MacroAssembler(&_cb)),
+      _base_pc(NULL)
+  {
+    cb()->initialize_oop_recorder(oop_recorder);
+  }
+
+ private:
+  CodeBuffer      _cb;
+  MacroAssembler* _masm;
+  llvm::Value*    _base_pc;
+
+ public:
+  CodeBuffer* cb()
+  {
+    return &_cb;
+  }
+
+ private:
+  MacroAssembler* masm() const
+  {
+    return _masm;
+  }
+
+ public:
+  llvm::Value* base_pc() const
+  {
+    return _base_pc;
+  }
+  void set_base_pc(llvm::Value* base_pc)
+  {
+    assert(_base_pc == NULL, "only do this once");
+    _base_pc = base_pc;
+  }
+
+  // Allocate some space in the buffer and return its address.
+  // This buffer will have been relocated by the time the method
+  // is installed, so you can't inline the result in code.
+ public:
+  void* malloc(size_t size) const
+  {
+    masm()->align(BytesPerWord);
+    void *result = masm()->pc();
+    masm()->advance(size);
+    return result;
+  }
+
+  // Create a unique offset in the buffer.
+ public:
+  int create_unique_offset() const
+  {
+    int offset = masm()->offset();
+    masm()->advance(1);
+    return offset;
+  }
+
+  // Inline an oop into the buffer and return its offset.
+ public:
+  int inline_oop(ciObject* object) const
+  {
+    masm()->align(BytesPerWord);
+    int offset = masm()->offset();
+    masm()->store_oop(object->encoding());
+    return offset;
+  }
+};
--- a/ports/hotspot/src/share/vm/shark/sharkCompiler.cpp	Wed Jun 03 09:37:51 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkCompiler.cpp	Wed Jun 03 11:15:36 2009 -0400
@@ -115,14 +115,16 @@
   env->debug_info()->set_oopmaps(&oopmaps);
   env->set_dependencies(new Dependencies(env));
 
-  // Create the CodeBuffer and MacroAssembler
-  CodeBuffer cb("Shark", 256 * K, 64 * K);
-  cb.initialize_oop_recorder(env->oop_recorder());
-  MacroAssembler *masm = new MacroAssembler(&cb);
+  // Create the code buffer and hook it into the builder
+  SharkCodeBuffer cb(env->oop_recorder());
+  builder()->set_code_buffer(&cb);
 
-  // Compile the method into the CodeBuffer
+  // Compile the method
   ciBytecodeStream iter(target);
-  SharkFunction function(this, name, flow, &iter, masm);
+  SharkFunction function(this, name, flow, &iter);
+
+  // Unhook the code buffer
+  builder()->set_code_buffer(NULL);  
 
   // Install the method into the VM
   CodeOffsets offsets;
@@ -138,7 +140,7 @@
                        entry_bci,
                        &offsets,
                        0,
-                       &cb,
+                       cb.cb(),
                        0,
                        &oopmaps,
                        &handler_table,
--- a/ports/hotspot/src/share/vm/shark/sharkFunction.cpp	Wed Jun 03 09:37:51 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkFunction.cpp	Wed Jun 03 11:15:36 2009 -0400
@@ -33,8 +33,8 @@
 void SharkFunction::initialize()
 {
   // Emit the entry point
-  SharkEntry *entry = (SharkEntry *) masm()->pc();
-  masm()->advance(sizeof(SharkEntry));
+  SharkEntry *entry =
+    (SharkEntry *) builder()->code_buffer()->malloc(sizeof(SharkEntry));
 
   // Create the function
   _function = builder()->CreateFunction(name());
@@ -45,8 +45,9 @@
   Function::arg_iterator ai = function()->arg_begin();
   Argument *method = ai++;
   method->setName("method");
-  _base_pc = ai++;
-  _base_pc->setName("base_pc");
+  Argument *base_pc = ai++;
+  base_pc->setName("base_pc");
+  builder()->code_buffer()->set_base_pc(base_pc);
   _thread = ai++;
   _thread->setName("thread");
 
--- a/ports/hotspot/src/share/vm/shark/sharkFunction.hpp	Wed Jun 03 09:37:51 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkFunction.hpp	Wed Jun 03 11:15:36 2009 -0400
@@ -32,13 +32,11 @@
   SharkFunction(SharkCompiler*    compiler,
                 const char*       name,
                 ciTypeFlow*       flow,
-                ciBytecodeStream* iter,
-                MacroAssembler*   masm)
+                ciBytecodeStream* iter)
     : _compiler(compiler),
       _name(name),
       _flow(flow),
-      _iter(iter),
-      _masm(masm)
+      _iter(iter)
   { initialize(); }
 
  private:
@@ -49,10 +47,8 @@
   const char*                       _name;
   ciTypeFlow*                       _flow;
   ciBytecodeStream*                 _iter;
-  MacroAssembler*                   _masm;
   llvm::Function*                   _function;
   SharkTopLevelBlock**              _blocks;
-  llvm::Value*                      _base_pc;
   llvm::Value*                      _thread;
   int                               _max_monitors;
   GrowableArray<DeferredZeroCheck*> _deferred_zero_checks;
@@ -74,10 +70,6 @@
   {
     return _iter;
   }
-  MacroAssembler* masm() const
-  {
-    return _masm;
-  }
   llvm::Function* function() const
   {
     return _function;
@@ -86,10 +78,6 @@
   {
     return _blocks[i];
   }
-  llvm::Value* base_pc() const
-  {
-    return _base_pc;
-  }
   llvm::Value* thread() const
   {
     return _thread;
@@ -137,28 +125,6 @@
     return flow()->method();
   }
 
-  // CodeBuffer interface
- public:
-  int create_unique_pc_offset() const
-  {
-    int offset = masm()->offset();
-    masm()->advance(1);
-    return offset;
-  }
-  llvm::Value* CreateAddressOfCodeBufferEntry(int offset) const
-  {
-    return builder()->CreateAdd(base_pc(), LLVMValue::intptr_constant(offset));
-  }
-  llvm::Value* CreateAddressOfOopInCodeBuffer(ciObject* object) const
-  {
-    masm()->align(BytesPerWord);
-    int offset = masm()->offset();
-    masm()->store_oop(object->encoding());
-    return builder()->CreateIntToPtr(
-      CreateAddressOfCodeBufferEntry(offset),
-      llvm::PointerType::getUnqual(SharkType::jobject_type()));
-  }
-
   // Block management
  private:
   llvm::BasicBlock* _block_insertion_point;
--- a/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Wed Jun 03 09:37:51 2009 -0400
+++ b/ports/hotspot/src/share/vm/shark/sharkTopLevelBlock.cpp	Wed Jun 03 11:15:36 2009 -0400
@@ -895,10 +895,10 @@
 // invokevirtual is direct in some circumstances.
 Value *SharkTopLevelBlock::get_direct_callee(ciMethod* method)
 {
-  return builder()->CreateLoad(
-    builder()->CreateBitCast(
-      function()->CreateAddressOfOopInCodeBuffer(method),
-      PointerType::getUnqual(SharkType::methodOop_type())), "callee");
+  return builder()->CreateBitCast(
+    builder()->CreateInlineOop(method),
+    SharkType::methodOop_type(),
+    "callee");
 }
 
 // Non-direct virtual calls are handled here