Patch: make block_comment work everywhere

Gary Benson gbenson at redhat.com
Wed Dec 5 03:34:31 PST 2007


Hi all,

I've been writing the disassembler for my PPC stuff and I noticed that
while block_comment worked in some places (stubs) it did not work in
others (the interpreter).  Looking into it I found that there are two
places where comment lists are maintained: in CodeBlobs, and in the
CodeBuffers that are created from them.  The assembler stores comments
in its CodeBuffer, but the disassembler looks for them in the parent
CodeBlob.  block_comment works in some places because those places
copy the comments over to the CodeBlob.

It seemed a little strange to be storing in one place and looking
in another, so rather than add something to copy the comments in the
interpreter generator I altered the assembler to store directly into
the CodeBlob, and stripped the comment code from CodeBuffer.

Does the attached patch look ok?

Cheers,
Gary
-------------- next part --------------
diff -r 9c4940256a46 openjdk/hotspot/src/share/vm/asm/assembler.cpp
--- openjdk/hotspot/src/share/vm/asm/assembler.cpp
+++ openjdk/hotspot/src/share/vm/asm/assembler.cpp
@@ -241,9 +241,10 @@ void Label::patch_instructions(MacroAsse
 
 
 void AbstractAssembler::block_comment(const char* comment) {
-  if (sect() == CodeBuffer::SECT_INSTS) {
-    code_section()->outer()->block_comment(offset(), comment);
-  }
+  CodeBlob *cb = CodeCache::find_blob_unsafe(pc());
+  assert(cb != NULL, "unable to locate CodeBlob");
+  intptr_t offset = (intptr_t) pc() - (intptr_t) cb->instructions_begin();
+  cb->add_comment(offset, comment);
 }
 
 
diff -r 9c4940256a46 openjdk/hotspot/src/share/vm/code/codeBlob.hpp
--- openjdk/hotspot/src/share/vm/code/codeBlob.hpp
+++ openjdk/hotspot/src/share/vm/code/codeBlob.hpp
@@ -198,14 +198,12 @@ class CodeBlob VALUE_OBJ_CLASS_SPEC {
   virtual void print() const                     PRODUCT_RETURN;
   virtual void print_value_on(outputStream* st) const PRODUCT_RETURN;
 
+  // Associate a comment with an offset on the stream
+  void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;  
+  
   // Print the comment associated with offset on stream, if there is one
   void print_block_comment(outputStream* stream, intptr_t offset) {
     _comments.print_block_comment(stream, offset);
-  }
-
-  // Transfer ownership of comments to this CodeBlob
-  void set_comments(CodeComments& comments) {
-    _comments.assign(comments);
   }
 };
 
diff -r 9c4940256a46 openjdk/hotspot/src/share/vm/code/codeBlob.cpp
--- openjdk/hotspot/src/share/vm/code/codeBlob.cpp
+++ openjdk/hotspot/src/share/vm/code/codeBlob.cpp
@@ -638,6 +638,10 @@ void CodeBlob::print_value_on(outputStre
   st->print_cr("[CodeBlob]");
 }
 
+void CodeBlob::add_comment(intptr_t offset, const char * comment) {
+  _comments.add_comment(offset, comment);
+}
+
 #endif
 
 void BufferBlob::verify() {
diff -r 9c4940256a46 openjdk/hotspot/src/share/vm/asm/codeBuffer.cpp
--- openjdk/hotspot/src/share/vm/asm/codeBuffer.cpp
+++ openjdk/hotspot/src/share/vm/asm/codeBuffer.cpp
@@ -617,9 +617,6 @@ void CodeBuffer::copy_code_to(CodeBlob* 
   this->compute_final_layout(&dest);
   relocate_code_to(&dest);
 
-  // transfer comments from buffer to blob
-  dest_blob->set_comments(_comments);
-
   // Done moving code bytes; were they the right size?
   assert(round_to(dest.total_code_size(), oopSize) == dest_blob->instructions_size(), "sanity");
 
@@ -875,11 +872,6 @@ void CodeSection::decode() {
 }
 
 
-void CodeBuffer::block_comment(intptr_t offset, const char * comment) {
-  _comments.add_comment(offset, comment);
-}
-
-
 class CodeComment: public CHeapObj {
  private:
   friend class CodeComments;
diff -r 9c4940256a46 openjdk/hotspot/src/share/vm/asm/codeBuffer.hpp
--- openjdk/hotspot/src/share/vm/asm/codeBuffer.hpp
+++ openjdk/hotspot/src/share/vm/asm/codeBuffer.hpp
@@ -304,7 +304,6 @@ class CodeBuffer: public StackObj {
   csize_t      _total_size;     // size in bytes of combined memory buffer
 
   OopRecorder* _oop_recorder;
-  CodeComments _comments;
   OopRecorder  _default_oop_recorder;  // override with initialize_oop_recorder
   Arena*       _overflow_arena;
 
@@ -486,7 +485,6 @@ class CodeBuffer: public StackObj {
   void initialize_oop_recorder(OopRecorder* r);
 
   OopRecorder* oop_recorder() const   { return _oop_recorder; }
-  CodeComments& comments()            { return _comments; }
 
   // Code generation
   void relocate(address at, RelocationHolder const& rspec, int format = 0) {
@@ -513,8 +511,6 @@ class CodeBuffer: public StackObj {
 
   // Transform an address from the code in this code buffer to a specified code buffer
   address transform_address(const CodeBuffer &cb, address addr) const;
-
-  void block_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
 
 #ifndef PRODUCT
  public:
diff -r 9c4940256a46 openjdk/hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
--- openjdk/hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
+++ openjdk/hotspot/src/share/vm/runtime/stubCodeGenerator.cpp
@@ -83,10 +83,6 @@ StubCodeGenerator::~StubCodeGenerator() 
 #ifndef PRODUCT
   if (PrintStubCode) {
     CodeBuffer* cbuf = _masm->code();
-    CodeBlob*   blob = CodeCache::find_blob_unsafe(cbuf->insts()->start());
-    if (blob != NULL) {
-      blob->set_comments(cbuf->comments());
-    }
     bool saw_first = false;
     StubCodeDesc* toprint[1000];
     int toprint_len = 0;


More information about the hotspot-dev mailing list