src/share/vm/runtime/handles.hpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2009, 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  *
  23  */
  24 







  25 //------------------------------------------------------------------------------------------------------------------------
  26 // In order to preserve oops during garbage collection, they should be
  27 // allocated and passed around via Handles within the VM. A handle is
  28 // simply an extra indirection allocated in a thread local handle area.
  29 //
  30 // A handle is a ValueObj, so it can be passed around as a value, can
  31 // be used as a parameter w/o using &-passing, and can be returned as a
  32 // return value.
  33 //
  34 // oop parameters and return types should be Handles whenever feasible.
  35 //
  36 // Handles are declared in a straight-forward manner, e.g.
  37 //
  38 //   oop obj = ...;
  39 //   Handle h1(obj);              // allocate new handle
  40 //   Handle h2(thread, obj);      // faster allocation when current thread is known
  41 //   Handle h3;                   // declare handle only, no allocation occurs
  42 //   ...
  43 //   h3 = h1;                     // make h3 refer to same indirection as h1
  44 //   oop obj2 = h2();             // get handle value


 337   NoHandleMark();
 338   ~NoHandleMark();
 339 #else
 340   NoHandleMark()  {}
 341   ~NoHandleMark() {}
 342 #endif
 343 };
 344 
 345 
 346 class ResetNoHandleMark: public StackObj {
 347   int _no_handle_mark_nesting;
 348  public:
 349 #ifdef ASSERT
 350   ResetNoHandleMark();
 351   ~ResetNoHandleMark();
 352 #else
 353   ResetNoHandleMark()  {}
 354   ~ResetNoHandleMark() {}
 355 #endif
 356 };


   1 /*
   2  * Copyright (c) 1997, 2010, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_HANDLES_HPP
  26 #define SHARE_VM_RUNTIME_HANDLES_HPP
  27 
  28 #include "oops/klass.hpp"
  29 #include "oops/klassOop.hpp"
  30 #include "utilities/top.hpp"
  31 
  32 //------------------------------------------------------------------------------------------------------------------------
  33 // In order to preserve oops during garbage collection, they should be
  34 // allocated and passed around via Handles within the VM. A handle is
  35 // simply an extra indirection allocated in a thread local handle area.
  36 //
  37 // A handle is a ValueObj, so it can be passed around as a value, can
  38 // be used as a parameter w/o using &-passing, and can be returned as a
  39 // return value.
  40 //
  41 // oop parameters and return types should be Handles whenever feasible.
  42 //
  43 // Handles are declared in a straight-forward manner, e.g.
  44 //
  45 //   oop obj = ...;
  46 //   Handle h1(obj);              // allocate new handle
  47 //   Handle h2(thread, obj);      // faster allocation when current thread is known
  48 //   Handle h3;                   // declare handle only, no allocation occurs
  49 //   ...
  50 //   h3 = h1;                     // make h3 refer to same indirection as h1
  51 //   oop obj2 = h2();             // get handle value


 344   NoHandleMark();
 345   ~NoHandleMark();
 346 #else
 347   NoHandleMark()  {}
 348   ~NoHandleMark() {}
 349 #endif
 350 };
 351 
 352 
 353 class ResetNoHandleMark: public StackObj {
 354   int _no_handle_mark_nesting;
 355  public:
 356 #ifdef ASSERT
 357   ResetNoHandleMark();
 358   ~ResetNoHandleMark();
 359 #else
 360   ResetNoHandleMark()  {}
 361   ~ResetNoHandleMark() {}
 362 #endif
 363 };
 364 
 365 #endif // SHARE_VM_RUNTIME_HANDLES_HPP