< prev index next >

hotspot/src/share/vm/asm/codeBuffer.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 232   // Ensure there's enough space left in the current section.
 233   // Return true if there was an expansion.
 234   bool maybe_expand_to_ensure_remaining(csize_t amount);
 235 
 236 #ifndef PRODUCT
 237   void decode();
 238   void dump();
 239   void print(const char* name);
 240 #endif //PRODUCT
 241 };
 242 
 243 class CodeString;
 244 class CodeStrings VALUE_OBJ_CLASS_SPEC {
 245 private:
 246 #ifndef PRODUCT
 247   CodeString* _strings;
 248 #ifdef ASSERT
 249   // Becomes true after copy-out, forbids further use.
 250   bool _defunct; // Zero bit pattern is "valid", see memset call in decode_env::decode_env
 251 #endif

 252 #endif
 253 
 254   CodeString* find(intptr_t offset) const;
 255   CodeString* find_last(intptr_t offset) const;
 256 
 257   void set_null_and_invalidate() {
 258 #ifndef PRODUCT
 259     _strings = NULL;
 260 #ifdef ASSERT
 261     _defunct = true;
 262 #endif
 263 #endif
 264   }
 265 















 266 public:
 267   CodeStrings() {
 268 #ifndef PRODUCT
 269     _strings = NULL;
 270 #ifdef ASSERT
 271     _defunct = false;
 272 #endif
 273 #endif
 274   }
 275 
 276   bool is_null() {
 277 #ifdef ASSERT
 278     return _strings == NULL;
 279 #else
 280     return true;
 281 #endif
 282   }
 283 
 284   const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;);
 285 
 286   void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
 287   void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN;
 288   // MOVE strings from other to this; invalidate other.
 289   void assign(CodeStrings& other)  PRODUCT_RETURN;
 290   // COPY strings from other to this; leave other valid.
 291   void copy(CodeStrings& other)  PRODUCT_RETURN;

 292   void free() PRODUCT_RETURN;
 293   // Guarantee that _strings are used at most once; assign invalidates a buffer.
 294   inline void check_valid() const {
 295 #ifdef ASSERT
 296     assert(!_defunct, "Use of invalid CodeStrings");
 297 #endif
 298   }






 299 };
 300 
 301 // A CodeBuffer describes a memory space into which assembly
 302 // code is generated.  This memory space usually occupies the
 303 // interior of a single BufferBlob, but in some cases it may be
 304 // an arbitrary span of memory, even outside the code cache.
 305 //
 306 // A code buffer comes in two variants:
 307 //
 308 // (1) A CodeBuffer referring to an already allocated piece of memory:
 309 //     This is used to direct 'static' code generation (e.g. for interpreter
 310 //     or stubroutine generation, etc.).  This code comes with NO relocation
 311 //     information.
 312 //
 313 // (2) A CodeBuffer referring to a piece of memory allocated when the
 314 //     CodeBuffer is allocated.  This is used for nmethod generation.
 315 //
 316 // The memory can be divided up into several parts called sections.
 317 // Each section independently accumulates code (or data) an relocations.
 318 // Sections can grow (at the expense of a reallocation of the BufferBlob


 362   address      _total_start;    // first address of combined memory buffer
 363   csize_t      _total_size;     // size in bytes of combined memory buffer
 364 
 365   OopRecorder* _oop_recorder;
 366   CodeStrings  _code_strings;
 367   OopRecorder  _default_oop_recorder;  // override with initialize_oop_recorder
 368   Arena*       _overflow_arena;
 369 
 370   address      _decode_begin;   // start address for decode
 371   address      decode_begin();
 372 
 373   void initialize_misc(const char * name) {
 374     // all pointers other than code_start/end and those inside the sections
 375     assert(name != NULL, "must have a name");
 376     _name            = name;
 377     _before_expand   = NULL;
 378     _blob            = NULL;
 379     _oop_recorder    = NULL;
 380     _decode_begin    = NULL;
 381     _overflow_arena  = NULL;

 382   }
 383 
 384   void initialize(address code_start, csize_t code_size) {
 385     _consts.initialize_outer(this,  SECT_CONSTS);
 386     _insts.initialize_outer(this,   SECT_INSTS);
 387     _stubs.initialize_outer(this,   SECT_STUBS);
 388     _total_start = code_start;
 389     _total_size  = code_size;
 390     // Initialize the main section:
 391     _insts.initialize(code_start, code_size);
 392     assert(!_stubs.is_allocated(),  "no garbage here");
 393     assert(!_consts.is_allocated(), "no garbage here");
 394     _oop_recorder = &_default_oop_recorder;
 395   }
 396 
 397   void initialize_section_size(CodeSection* cs, csize_t size);
 398 
 399   void freeze_section(CodeSection* cs);
 400 
 401   // helper for CodeBuffer::expand()


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 232   // Ensure there's enough space left in the current section.
 233   // Return true if there was an expansion.
 234   bool maybe_expand_to_ensure_remaining(csize_t amount);
 235 
 236 #ifndef PRODUCT
 237   void decode();
 238   void dump();
 239   void print(const char* name);
 240 #endif //PRODUCT
 241 };
 242 
 243 class CodeString;
 244 class CodeStrings VALUE_OBJ_CLASS_SPEC {
 245 private:
 246 #ifndef PRODUCT
 247   CodeString* _strings;
 248 #ifdef ASSERT
 249   // Becomes true after copy-out, forbids further use.
 250   bool _defunct; // Zero bit pattern is "valid", see memset call in decode_env::decode_env
 251 #endif
 252   static const char* _prefix; // defaults to " ;; "
 253 #endif
 254 
 255   CodeString* find(intptr_t offset) const;
 256   CodeString* find_last(intptr_t offset) const;
 257 
 258   void set_null_and_invalidate() {
 259 #ifndef PRODUCT
 260     _strings = NULL;
 261 #ifdef ASSERT
 262     _defunct = true;
 263 #endif
 264 #endif
 265   }
 266 
 267   void set_null() {
 268 #ifndef PRODUCT
 269     _strings = NULL;
 270 #endif
 271   }
 272 
 273   void invalidate() {
 274 #ifndef PRODUCT
 275     assert(is_null(), "Should not invalidate non-empty CodeStrings");
 276 #ifdef ASSERT
 277     _defunct = true;
 278 #endif
 279 #endif
 280   }
 281 
 282 public:
 283   CodeStrings() {
 284 #ifndef PRODUCT
 285     _strings = NULL;
 286 #ifdef ASSERT
 287     _defunct = false;
 288 #endif
 289 #endif
 290   }
 291 
 292   bool is_null() {
 293 #ifdef ASSERT
 294     return _strings == NULL;
 295 #else
 296     return true;
 297 #endif
 298   }
 299 
 300   const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;);
 301 
 302   void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
 303   void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN;
 304   // MOVE strings from other to this; invalidate other.
 305   void assign(CodeStrings& other)  PRODUCT_RETURN;
 306   // COPY strings from other to this; leave other valid.
 307   void copy(CodeStrings& other)  PRODUCT_RETURN;
 308   // FREE strings; invalidate this.
 309   void free() PRODUCT_RETURN;
 310   // Guarantee that _strings are used at most once; assign and free invalidate a buffer.
 311   inline void check_valid() const {
 312 #ifdef ASSERT
 313     assert(!_defunct, "Use of invalid CodeStrings");
 314 #endif
 315   }
 316 
 317   static void set_prefix(const char *prefix) {
 318 #ifndef PRODUCT
 319     _prefix = prefix;
 320 #endif
 321   }
 322 };
 323 
 324 // A CodeBuffer describes a memory space into which assembly
 325 // code is generated.  This memory space usually occupies the
 326 // interior of a single BufferBlob, but in some cases it may be
 327 // an arbitrary span of memory, even outside the code cache.
 328 //
 329 // A code buffer comes in two variants:
 330 //
 331 // (1) A CodeBuffer referring to an already allocated piece of memory:
 332 //     This is used to direct 'static' code generation (e.g. for interpreter
 333 //     or stubroutine generation, etc.).  This code comes with NO relocation
 334 //     information.
 335 //
 336 // (2) A CodeBuffer referring to a piece of memory allocated when the
 337 //     CodeBuffer is allocated.  This is used for nmethod generation.
 338 //
 339 // The memory can be divided up into several parts called sections.
 340 // Each section independently accumulates code (or data) an relocations.
 341 // Sections can grow (at the expense of a reallocation of the BufferBlob


 385   address      _total_start;    // first address of combined memory buffer
 386   csize_t      _total_size;     // size in bytes of combined memory buffer
 387 
 388   OopRecorder* _oop_recorder;
 389   CodeStrings  _code_strings;
 390   OopRecorder  _default_oop_recorder;  // override with initialize_oop_recorder
 391   Arena*       _overflow_arena;
 392 
 393   address      _decode_begin;   // start address for decode
 394   address      decode_begin();
 395 
 396   void initialize_misc(const char * name) {
 397     // all pointers other than code_start/end and those inside the sections
 398     assert(name != NULL, "must have a name");
 399     _name            = name;
 400     _before_expand   = NULL;
 401     _blob            = NULL;
 402     _oop_recorder    = NULL;
 403     _decode_begin    = NULL;
 404     _overflow_arena  = NULL;
 405     _code_strings    = CodeStrings();
 406   }
 407 
 408   void initialize(address code_start, csize_t code_size) {
 409     _consts.initialize_outer(this,  SECT_CONSTS);
 410     _insts.initialize_outer(this,   SECT_INSTS);
 411     _stubs.initialize_outer(this,   SECT_STUBS);
 412     _total_start = code_start;
 413     _total_size  = code_size;
 414     // Initialize the main section:
 415     _insts.initialize(code_start, code_size);
 416     assert(!_stubs.is_allocated(),  "no garbage here");
 417     assert(!_consts.is_allocated(), "no garbage here");
 418     _oop_recorder = &_default_oop_recorder;
 419   }
 420 
 421   void initialize_section_size(CodeSection* cs, csize_t size);
 422 
 423   void freeze_section(CodeSection* cs);
 424 
 425   // helper for CodeBuffer::expand()


< prev index next >