hotspot/src/share/vm/runtime/handles.hpp
changeset 17026 72b2233861f1
parent 14120 7d298141c258
child 17031 9a576749065b
equal deleted inserted replaced
17025:1cabc279ba46 17026:72b2233861f1
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   278 //   h()->print();       // WRONG, h destroyed by HandleMark destructor.
   278 //   h()->print();       // WRONG, h destroyed by HandleMark destructor.
   279 //
   279 //
   280 // If h has to be preserved, it can be converted to an oop or a local JNI handle
   280 // If h has to be preserved, it can be converted to an oop or a local JNI handle
   281 // across the HandleMark boundary.
   281 // across the HandleMark boundary.
   282 
   282 
   283 // The base class of HandleMark should have been StackObj but we also heap allocate
   283 // The only special case for HandleMark is when a Thread is created, the first
   284 // a HandleMark when a thread is created.
   284 // HandleMark of the Thread is allocated in heap.
   285 
   285 
   286 class HandleMark {
   286 class HandleMark : public StackObj {
   287  private:
   287  private:
   288   Thread *_thread;              // thread that owns this mark
   288   Thread *_thread;              // thread that owns this mark
   289   HandleArea *_area;            // saved handle area
   289   HandleArea *_area;            // saved handle area
   290   Chunk *_chunk;                // saved arena chunk
   290   Chunk *_chunk;                // saved arena chunk
   291   char *_hwm, *_max;            // saved arena info
   291   char *_hwm, *_max;            // saved arena info
   292   size_t _size_in_bytes;        // size of handle area
   292   size_t _size_in_bytes;        // size of handle area
   293   // Link to previous active HandleMark in thread
   293   // Link to previous active HandleMark in thread
   294   HandleMark* _previous_handle_mark;
   294   HandleMark* _previous_handle_mark;
   295 
   295 
   296   void initialize(Thread* thread);                // common code for constructors
       
   297   void set_previous_handle_mark(HandleMark* mark) { _previous_handle_mark = mark; }
   296   void set_previous_handle_mark(HandleMark* mark) { _previous_handle_mark = mark; }
   298   HandleMark* previous_handle_mark() const        { return _previous_handle_mark; }
   297   HandleMark* previous_handle_mark() const        { return _previous_handle_mark; }
   299 
   298 
   300   size_t size_in_bytes() const { return _size_in_bytes; }
   299   size_t size_in_bytes() const { return _size_in_bytes; }
   301  public:
   300  public:
   302   HandleMark();                            // see handles_inline.hpp
   301   HandleMark();                            // see handles_inline.hpp
   303   HandleMark(Thread* thread)                      { initialize(thread); }
   302   HandleMark(Thread* thread)                      { initialize(thread); }
   304   ~HandleMark();
   303   ~HandleMark();
   305 
   304 
       
   305   void initialize(Thread* thread);                // common code for constructors
   306   // Functions used by HandleMarkCleaner
   306   // Functions used by HandleMarkCleaner
   307   // called in the constructor of HandleMarkCleaner
   307   // called in the constructor of HandleMarkCleaner
   308   void push();
   308   void push();
   309   // called in the destructor of HandleMarkCleaner
   309   // called in the destructor of HandleMarkCleaner
   310   void pop_and_restore();
   310   void pop_and_restore();