src/hotspot/share/runtime/handles.hpp
author coleenp
Wed, 13 Nov 2019 08:23:23 -0500
changeset 59056 15936b142f86
parent 58177 4932dce35882
permissions -rw-r--r--
8233913: Remove implicit conversion from Method* to methodHandle Summary: Fix call sites to use existing THREAD local or pass down THREAD local for shallower callsites. Make linkResolver methods return Method* for caller to handleize if needed. Reviewed-by: iklam, thartmann, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49658
diff changeset
     2
 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2332
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49658
diff changeset
    25
#ifndef SHARE_RUNTIME_HANDLES_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49658
diff changeset
    26
#define SHARE_RUNTIME_HANDLES_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46475
diff changeset
    28
#include "memory/arena.hpp"
29199
db7ae483ecb2 8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents: 29081
diff changeset
    29
#include "oops/oop.hpp"
db7ae483ecb2 8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents: 29081
diff changeset
    30
#include "oops/oopsHierarchy.hpp"
db7ae483ecb2 8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents: 29081
diff changeset
    31
db7ae483ecb2 8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents: 29081
diff changeset
    32
class InstanceKlass;
db7ae483ecb2 8073388: Get rid of the depenecy from handles.hpp to oop.inline.hpp
stefank
parents: 29081
diff changeset
    33
class Klass;
53582
881c5fbeb849 8218041: Assorted wrong/missing includes
rehn
parents: 53244
diff changeset
    34
class Thread;
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// In order to preserve oops during garbage collection, they should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// allocated and passed around via Handles within the VM. A handle is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// simply an extra indirection allocated in a thread local handle area.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 49364
diff changeset
    41
// A handle is a value object, so it can be passed around as a value, can
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// be used as a parameter w/o using &-passing, and can be returned as a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// return value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// oop parameters and return types should be Handles whenever feasible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// Handles are declared in a straight-forward manner, e.g.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
//   oop obj = ...;
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 29199
diff changeset
    50
//   Handle h2(thread, obj);      // allocate a new handle in thread
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//   Handle h3;                   // declare handle only, no allocation occurs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//   ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//   h3 = h1;                     // make h3 refer to same indirection as h1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//   oop obj2 = h2();             // get handle value
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//   h1->print();                 // invoking operation on oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
// Handles are specialized for different oop types to provide extra type
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
// information and avoid unnecessary casting. For each oop type xxxOop
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 29199
diff changeset
    59
// there is a corresponding handle called xxxHandle.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// Base class for all handles. Provides overloading of frequently
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
// used operators for ease of use.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
49364
601146c66cad 8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents: 47216
diff changeset
    65
class Handle {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  oop* _handle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  oop     obj() const                            { return _handle == NULL ? (oop)NULL : *_handle; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  oop     non_null_obj() const                   { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // Constructors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  Handle()                                       { _handle = NULL; }
49393
93fe2fc5c093 8199472: Fix non-PCH build after JDK-8199319
simonis
parents: 49392
diff changeset
    76
  inline Handle(Thread* thread, oop obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // General access
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  oop     operator () () const                   { return obj(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  oop     operator -> () const                   { return non_null_obj(); }
49658
8237a91c1cca 8199781: Don't use naked == for comparing oops
rkennke
parents: 49449
diff changeset
    81
58177
4932dce35882 8230841: Remove oopDesc::equals()
pliden
parents: 53682
diff changeset
    82
  bool operator == (oop o) const                 { return obj() == o; }
4932dce35882 8230841: Remove oopDesc::equals()
pliden
parents: 53682
diff changeset
    83
  bool operator == (const Handle& h) const       { return obj() == h.obj(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Null checks
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  bool    is_null() const                        { return _handle == NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  bool    not_null() const                       { return _handle != NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  void    print()                                { obj()->print(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Direct interface, use very sparingly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Used by JavaCalls to quickly convert handles and to create handles static data structures.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  Handle(oop *handle, bool dummy)                { _handle = handle; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // since duplicates is only valid as long as original handle is alive.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  oop* raw_value()                               { return _handle; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  static oop raw_resolve(oop *handle)            { return handle == NULL ? (oop)NULL : *handle; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
// Specific Handles for different oop types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
#define DEF_HANDLE(type, is_a)                   \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  class type##Handle: public Handle {            \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
   protected:                                    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    type##Oop    obj() const                     { return (type##Oop)Handle::obj(); } \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    type##Oop    non_null_obj() const            { return (type##Oop)Handle::non_null_obj(); } \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
                                                 \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
   public:                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    /* Constructors */                           \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    type##Handle ()                              : Handle()                 {} \
49393
93fe2fc5c093 8199472: Fix non-PCH build after JDK-8199319
simonis
parents: 49392
diff changeset
   113
    inline type##Handle (Thread* thread, type##Oop obj); \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    /* Operators for ease of use */              \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    type##Oop    operator () () const            { return obj(); } \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    type##Oop    operator -> () const            { return non_null_obj(); } \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
29081
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 25946
diff changeset
   121
DEF_HANDLE(instance         , is_instance_noinline         )
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 25946
diff changeset
   122
DEF_HANDLE(array            , is_array_noinline            )
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 25946
diff changeset
   123
DEF_HANDLE(objArray         , is_objArray_noinline         )
c61eb4914428 8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents: 25946
diff changeset
   124
DEF_HANDLE(typeArray        , is_typeArray_noinline        )
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
//------------------------------------------------------------------------------------------------------------------------
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   127
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   128
// Metadata Handles.  Unlike oop Handles these are needed to prevent metadata
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   129
// from being reclaimed by RedefineClasses.
46475
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46329
diff changeset
   130
// Metadata Handles should be passed around as const references to avoid copy construction
75902cea18af 8166848: Performance bug: SystemDictionary - optimization
coleenp
parents: 46329
diff changeset
   131
// and destruction for parameters.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   133
// Specific Handles for different oop types
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   134
#define DEF_METADATA_HANDLE(name, type)          \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   135
  class name##Handle;                            \
20059
c26474fd5ac0 8022887: Assertion hit while using class and redefining it with RedefineClasses simultaneously
coleenp
parents: 19696
diff changeset
   136
  class name##Handle : public StackObj {         \
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   137
    type*     _value;                            \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   138
    Thread*   _thread;                           \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   139
   protected:                                    \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   140
    type*        obj() const                     { return _value; } \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   141
    type*        non_null_obj() const            { assert(_value != NULL, "resolving NULL _value"); return _value; } \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   142
                                                 \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
   public:                                       \
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    /* Constructors */                           \
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   145
    name##Handle () : _value(NULL), _thread(NULL) {}   \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   146
    name##Handle (Thread* thread, type* obj);    \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   147
                                                 \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   148
    name##Handle (const name##Handle &h);        \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   149
    name##Handle& operator=(const name##Handle &s); \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   150
                                                 \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   151
    /* Destructor */                             \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   152
    ~name##Handle ();                            \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   153
    void remove();                               \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
                                                 \
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   155
    /* Operators for ease of use */              \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   156
    type*        operator () () const            { return obj(); } \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   157
    type*        operator -> () const            { return non_null_obj(); } \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
                                                 \
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   159
    bool    operator == (type* o) const          { return obj() == o; } \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   160
    bool    operator == (const name##Handle& h) const  { return obj() == h.obj(); } \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
                                                 \
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   162
    /* Null checks */                            \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   163
    bool    is_null() const                      { return _value == NULL; } \
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   164
    bool    not_null() const                     { return _value != NULL; } \
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   168
DEF_METADATA_HANDLE(method, Method)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   169
DEF_METADATA_HANDLE(constantPool, ConstantPool)
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   170
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// Thread local handle area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
class HandleArea: public Arena {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  friend class HandleMark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  friend class NoHandleMark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  friend class ResetNoHandleMark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  int _handle_mark_nesting;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  int _no_handle_mark_nesting;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  HandleArea* _prev;          // link to outer (older) area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  // Constructor
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 22551
diff changeset
   184
  HandleArea(HandleArea* prev) : Arena(mtThread, Chunk::tiny_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    debug_only(_handle_mark_nesting    = 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    debug_only(_no_handle_mark_nesting = 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    _prev = prev;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // Handle allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  oop* real_allocate_handle(oop obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    oop* handle = (oop*) (UseMallocOnly ? internal_malloc_4(oopSize) : Amalloc_4(oopSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    oop* handle = (oop*) Amalloc_4(oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    *handle = obj;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    return handle;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  oop* allocate_handle(oop obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  oop* allocate_handle(oop obj) { return real_allocate_handle(obj); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // Garbage collection support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  void oops_do(OopClosure* f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // Number of handles in use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  size_t used() const     { return Arena::used() / oopSize; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  debug_only(bool no_handle_mark_active() { return _no_handle_mark_nesting > 0; })
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// Handles are allocated in a (growable) thread local handle area. Deallocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
// is managed using a HandleMark. It should normally not be necessary to use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
// HandleMarks manually.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
// A HandleMark constructor will record the current handle area top, and the
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 20059
diff changeset
   224
// destructor will reset the top, destroying all handles allocated in between.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
// The following code will therefore NOT work:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
//   Handle h;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
//   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
//     HandleMark hm;
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 29199
diff changeset
   230
//     h = Handle(THREAD, obj);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
//   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
//   h()->print();       // WRONG, h destroyed by HandleMark destructor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
// If h has to be preserved, it can be converted to an oop or a local JNI handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
// across the HandleMark boundary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
17031
9a576749065b 8012907: anti-delta fix for 8010992
dcubed
parents: 17026
diff changeset
   237
// The base class of HandleMark should have been StackObj but we also heap allocate
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17031
diff changeset
   238
// a HandleMark when a thread is created. The operator new is for this special case.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
17031
9a576749065b 8012907: anti-delta fix for 8010992
dcubed
parents: 17026
diff changeset
   240
class HandleMark {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  Thread *_thread;              // thread that owns this mark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  HandleArea *_area;            // saved handle area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  Chunk *_chunk;                // saved arena chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  char *_hwm, *_max;            // saved arena info
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8921
diff changeset
   246
  size_t _size_in_bytes;        // size of handle area
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  // Link to previous active HandleMark in thread
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  HandleMark* _previous_handle_mark;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
17031
9a576749065b 8012907: anti-delta fix for 8010992
dcubed
parents: 17026
diff changeset
   250
  void initialize(Thread* thread);                // common code for constructors
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  void set_previous_handle_mark(HandleMark* mark) { _previous_handle_mark = mark; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  HandleMark* previous_handle_mark() const        { return _previous_handle_mark; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
14120
7d298141c258 7199092: NMT: NMT needs to deal overlapped virtual memory ranges
zgu
parents: 14078
diff changeset
   254
  size_t size_in_bytes() const { return _size_in_bytes; }
53682
e30211561a17 8218565: HandleMark cleanup
redestad
parents: 53582
diff changeset
   255
  // remove all chunks beginning with the next
e30211561a17 8218565: HandleMark cleanup
redestad
parents: 53582
diff changeset
   256
  void chop_later_chunks();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  HandleMark();                            // see handles_inline.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  HandleMark(Thread* thread)                      { initialize(thread); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  ~HandleMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  // Functions used by HandleMarkCleaner
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // called in the constructor of HandleMarkCleaner
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  void push();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  // called in the destructor of HandleMarkCleaner
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  void pop_and_restore();
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17031
diff changeset
   267
  // overloaded operators
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
   268
  void* operator new(size_t size) throw();
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
   269
  void* operator new [](size_t size) throw();
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17031
diff changeset
   270
  void operator delete(void* p);
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17031
diff changeset
   271
  void operator delete[](void* p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
// A NoHandleMark stack object will verify that no handles are allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
// in its scope. Enabled in debug mode only.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
class NoHandleMark: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
  NoHandleMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  ~NoHandleMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  NoHandleMark()  {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  ~NoHandleMark() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
class ResetNoHandleMark: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  int _no_handle_mark_nesting;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  ResetNoHandleMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  ~ResetNoHandleMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  ResetNoHandleMark()  {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  ~ResetNoHandleMark() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   301
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   302
// The HandleMarkCleaner is a faster version of HandleMark.
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   303
// It relies on the fact that there is a HandleMark further
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   304
// down the stack (in JavaCalls::call_helper), and just resets
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   305
// to the saved values in that HandleMark.
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   306
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   307
class HandleMarkCleaner: public StackObj {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   308
 private:
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   309
  Thread* _thread;
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   310
 public:
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   311
  inline HandleMarkCleaner(Thread* thread);
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   312
  inline ~HandleMarkCleaner();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   313
};
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 49393
diff changeset
   314
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 49658
diff changeset
   315
#endif // SHARE_RUNTIME_HANDLES_HPP