< prev index next >

src/hotspot/share/asm/codeBuffer.hpp

Print this page

 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  *
 23  */
 24 
 25 #ifndef SHARE_ASM_CODEBUFFER_HPP
 26 #define SHARE_ASM_CODEBUFFER_HPP
 27 
 28 #include "code/oopRecorder.hpp"
 29 #include "code/relocInfo.hpp"
 30 #include "compiler/compiler_globals.hpp"

 31 #include "utilities/align.hpp"
 32 #include "utilities/debug.hpp"
 33 #include "utilities/growableArray.hpp"
 34 #include "utilities/linkedlist.hpp"
 35 #include "utilities/resizeableResourceHash.hpp"
 36 #include "utilities/macros.hpp"
 37 
 38 template <typename T>
 39 static inline void put_native(address p, T x) {
 40     memcpy((void*)p, &x, sizeof x);
 41 }
 42 
 43 class PhaseCFG;
 44 class Compile;
 45 class BufferBlob;
 46 class CodeBuffer;
 47 class Label;
 48 class ciMethod;
 49 class SharedStubToInterpRequest;
 50 

274   // Slop between sections, used only when allocating temporary BufferBlob buffers.
275   static csize_t end_slop()         { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
276 
277   csize_t align_at_start(csize_t off) const {
278     return (csize_t) align_up(off, alignment());
279   }
280 
281   // Ensure there's enough space left in the current section.
282   // Return true if there was an expansion.
283   bool maybe_expand_to_ensure_remaining(csize_t amount);
284 
285 #ifndef PRODUCT
286   void decode();
287   void print_on(outputStream* st, const char* name);
288 #endif //PRODUCT
289 };
290 
291 
292 #ifndef PRODUCT
293 
294 class AsmRemarkCollection;
295 class DbgStringCollection;



































































296 
297 // The assumption made here is that most code remarks (or comments) added to
298 // the generated assembly code are unique, i.e. there is very little gain in
299 // trying to share the strings between the different offsets tracked in a
300 // buffer (or blob).
301 
302 class AsmRemarks {
303  public:
304   AsmRemarks();
305  ~AsmRemarks();
306 


307   const char* insert(uint offset, const char* remstr);
308 
309   bool is_empty() const;
310 
311   void share(const AsmRemarks &src);
312   void clear();
313   uint print(uint offset, outputStream* strm = tty) const;
314 
315   // For testing purposes only.
316   const AsmRemarkCollection* ref() const { return _remarks; }
317 



318 private:
319   AsmRemarkCollection* _remarks;
320 };
321 



















































322 // The assumption made here is that the number of debug strings (with a fixed
323 // address requirement) is a rather small set per compilation unit.
324 
325 class DbgStrings {
326  public:
327   DbgStrings();
328  ~DbgStrings();
329 


330   const char* insert(const char* dbgstr);
331 
332   bool is_empty() const;
333 
334   void share(const DbgStrings &src);
335   void clear();
336 
337   // For testing purposes only.
338   const DbgStringCollection* ref() const { return _strings; }
339 



340 private:
341   DbgStringCollection* _strings;
342 };
343 #endif // not PRODUCT
344 
345 
346 #ifdef ASSERT
347 #include "utilities/copy.hpp"
348 
349 class Scrubber {
350  public:
351   Scrubber(void* addr, size_t size) : _addr(addr), _size(size) {}
352  ~Scrubber() {
353     Copy::fill_to_bytes(_addr, _size, badResourceValue);
354   }
355  private:
356   void*  _addr;
357   size_t _size;
358 };
359 #endif // ASSERT

 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  *
 23  */
 24 
 25 #ifndef SHARE_ASM_CODEBUFFER_HPP
 26 #define SHARE_ASM_CODEBUFFER_HPP
 27 
 28 #include "code/oopRecorder.hpp"
 29 #include "code/relocInfo.hpp"
 30 #include "compiler/compiler_globals.hpp"
 31 #include "runtime/os.hpp"
 32 #include "utilities/align.hpp"
 33 #include "utilities/debug.hpp"
 34 #include "utilities/growableArray.hpp"
 35 #include "utilities/linkedlist.hpp"
 36 #include "utilities/resizeableResourceHash.hpp"
 37 #include "utilities/macros.hpp"
 38 
 39 template <typename T>
 40 static inline void put_native(address p, T x) {
 41     memcpy((void*)p, &x, sizeof x);
 42 }
 43 
 44 class PhaseCFG;
 45 class Compile;
 46 class BufferBlob;
 47 class CodeBuffer;
 48 class Label;
 49 class ciMethod;
 50 class SharedStubToInterpRequest;
 51 

275   // Slop between sections, used only when allocating temporary BufferBlob buffers.
276   static csize_t end_slop()         { return MAX2((int)sizeof(jdouble), (int)CodeEntryAlignment); }
277 
278   csize_t align_at_start(csize_t off) const {
279     return (csize_t) align_up(off, alignment());
280   }
281 
282   // Ensure there's enough space left in the current section.
283   // Return true if there was an expansion.
284   bool maybe_expand_to_ensure_remaining(csize_t amount);
285 
286 #ifndef PRODUCT
287   void decode();
288   void print_on(outputStream* st, const char* name);
289 #endif //PRODUCT
290 };
291 
292 
293 #ifndef PRODUCT
294 
295 class CHeapString : public CHeapObj<mtCode> {
296  public:
297   CHeapString(const char* str) : _string(os::strdup(str)) {}
298  ~CHeapString() {
299     os::free((void*)_string);
300     _string = nullptr;
301   }
302   const char* string() const { return _string; }
303 
304  private:
305   const char* _string;
306 };
307 
308 class AsmRemarkCollection : public CHeapObj<mtCode> {
309  public:
310   AsmRemarkCollection() : _ref_cnt(1), _remarks(nullptr), _next(nullptr) {}
311  ~AsmRemarkCollection() {
312     assert(is_empty(), "Must 'clear()' before deleting!");
313     assert(_ref_cnt == 0, "No uses must remain when deleting!");
314   }
315   AsmRemarkCollection* reuse() {
316     precond(_ref_cnt > 0);
317     return _ref_cnt++, this;
318   }
319 
320   const char* insert(uint offset, const char* remark);
321   const char* lookup(uint offset) const;
322   const char* next(uint offset) const;
323 
324   bool is_empty() const { return _remarks == nullptr; }
325   uint clear();
326 
327   template<typename Function>
328   bool iterate(Function function) const { // lambda enabled API
329     if (_remarks != nullptr) {
330       Cell* tmp = _remarks;
331       do {
332         if(!function(tmp->offset, tmp->string())) {
333           return false;
334         }
335         tmp = tmp->next;
336       } while (tmp != _remarks);
337     }
338     return true;
339   }
340 
341  private:
342   struct Cell : CHeapString {
343     Cell(const char* remark, uint offset) :
344         CHeapString(remark), offset(offset), prev(nullptr), next(nullptr) {}
345     void push_back(Cell* cell) {
346       Cell* head = this;
347       Cell* tail = prev;
348       tail->next = cell;
349       cell->next = head;
350       cell->prev = tail;
351       prev = cell;
352     }
353     uint offset;
354     Cell* prev;
355     Cell* next;
356   };
357   uint  _ref_cnt;
358   Cell* _remarks;
359   // Using a 'mutable' iteration pointer to allow 'const' on lookup/next (that
360   // does not change the state of the list per se), supportig a simplistic
361   // iteration scheme.
362   mutable Cell* _next;
363 };
364 
365 // The assumption made here is that most code remarks (or comments) added to
366 // the generated assembly code are unique, i.e. there is very little gain in
367 // trying to share the strings between the different offsets tracked in a
368 // buffer (or blob).
369 
370 class AsmRemarks {
371  public:
372   AsmRemarks();
373  ~AsmRemarks();
374 
375   static void init(AsmRemarks& asm_remarks);
376 
377   const char* insert(uint offset, const char* remstr);
378 
379   bool is_empty() const;
380 
381   void share(const AsmRemarks &src);
382   void clear();
383   uint print(uint offset, outputStream* strm = tty) const;
384 
385   // For testing purposes only.
386   const AsmRemarkCollection* ref() const { return _remarks; }
387 
388   template<typename Function>
389   bool iterate(Function function) const { return _remarks->iterate(function); }
390 
391 private:
392   AsmRemarkCollection* _remarks;
393 };
394 
395 class DbgStringCollection : public CHeapObj<mtCode> {
396  public:
397   DbgStringCollection() : _ref_cnt(1), _strings(nullptr) {}
398  ~DbgStringCollection() {
399     assert(is_empty(), "Must 'clear()' before deleting!");
400     assert(_ref_cnt == 0, "No uses must remain when deleting!");
401   }
402   DbgStringCollection* reuse() {
403     precond(_ref_cnt > 0);
404     return _ref_cnt++, this;
405   }
406 
407   const char* insert(const char* str);
408   const char* lookup(const char* str) const;
409 
410   bool is_empty() const { return _strings == nullptr; }
411   uint clear();
412 
413   template<typename Function>
414   bool iterate(Function function) const { // lambda enabled API
415     if (_strings != nullptr) {
416       Cell* tmp = _strings;
417       do {
418         if (!function(tmp->string())) {
419           return false;
420         }
421         tmp = tmp->next;
422       } while (tmp != _strings);
423     }
424     return true;
425   }
426 
427  private:
428   struct Cell : CHeapString {
429     Cell(const char* dbgstr) :
430         CHeapString(dbgstr), prev(nullptr), next(nullptr) {}
431     void push_back(Cell* cell) {
432       Cell* head = this;
433       Cell* tail = prev;
434       tail->next = cell;
435       cell->next = head;
436       cell->prev = tail;
437       prev = cell;
438     }
439     Cell* prev;
440     Cell* next;
441   };
442   uint  _ref_cnt;
443   Cell* _strings;
444 };
445 
446 // The assumption made here is that the number of debug strings (with a fixed
447 // address requirement) is a rather small set per compilation unit.
448 
449 class DbgStrings {
450  public:
451   DbgStrings();
452  ~DbgStrings();
453 
454   static void init(DbgStrings& dbg_strings);
455 
456   const char* insert(const char* dbgstr);
457 
458   bool is_empty() const;
459 
460   void share(const DbgStrings &src);
461   void clear();
462 
463   // For testing purposes only.
464   const DbgStringCollection* ref() const { return _strings; }
465 
466   template<typename Function>
467   bool iterate(Function function) const { return _strings->iterate(function); }
468 
469 private:
470   DbgStringCollection* _strings;
471 };
472 #endif // not PRODUCT
473 
474 
475 #ifdef ASSERT
476 #include "utilities/copy.hpp"
477 
478 class Scrubber {
479  public:
480   Scrubber(void* addr, size_t size) : _addr(addr), _size(size) {}
481  ~Scrubber() {
482     Copy::fill_to_bytes(_addr, _size, badResourceValue);
483   }
484  private:
485   void*  _addr;
486   size_t _size;
487 };
488 #endif // ASSERT
< prev index next >