< prev index next >

src/hotspot/share/runtime/handles.hpp

Print this page

 56 //
 57 // Handles are specialized for different oop types to provide extra type
 58 // information and avoid unnecessary casting. For each oop type xxxOop
 59 // there is a corresponding handle called xxxHandle.
 60 
 61 //------------------------------------------------------------------------------------------------------------------------
 62 // Base class for all handles. Provides overloading of frequently
 63 // used operators for ease of use.
 64 
 65 class Handle {
 66  private:
 67   oop* _handle;
 68 
 69  protected:
 70   oop     obj() const                            { return _handle == NULL ? (oop)NULL : *_handle; }
 71   oop     non_null_obj() const                   { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
 72 
 73  public:
 74   // Constructors
 75   Handle()                                       { _handle = NULL; }
 76   inline Handle(Thread* thread, oop obj);
 77 
 78   // General access
 79   oop     operator () () const                   { return obj(); }
 80   oop     operator -> () const                   { return non_null_obj(); }
 81 
 82   bool operator == (oop o) const                 { return obj() == o; }
 83   bool operator != (oop o) const                 { return obj() != o; }
 84   bool operator == (const Handle& h) const       { return obj() == h.obj(); }
 85   bool operator != (const Handle& h) const       { return obj() != h.obj(); }
 86 
 87   // Null checks
 88   bool    is_null() const                        { return _handle == NULL; }
 89   bool    not_null() const                       { return _handle != NULL; }
 90 
 91   // Debugging
 92   void    print()                                { obj()->print(); }
 93 
 94   // Direct interface, use very sparingly.
 95   // Used by JavaCalls to quickly convert handles and to create handles static data structures.
 96   // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
 97   Handle(oop *handle, bool dummy)                { _handle = handle; }
 98 
 99   // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
100   // since duplicates is only valid as long as original handle is alive.
101   oop* raw_value() const                         { return _handle; }
102   static oop raw_resolve(oop *handle)            { return handle == NULL ? (oop)NULL : *handle; }
103 };
104 
105 // Specific Handles for different oop types
106 #define DEF_HANDLE(type, is_a)                   \
107   class type##Handle: public Handle {            \
108    protected:                                    \
109     type##Oop    obj() const                     { return (type##Oop)Handle::obj(); } \
110     type##Oop    non_null_obj() const            { return (type##Oop)Handle::non_null_obj(); } \
111                                                  \
112    public:                                       \
113     /* Constructors */                           \
114     type##Handle ()                              : Handle()                 {} \
115     inline type##Handle (Thread* thread, type##Oop obj); \
116     \
117     /* Operators for ease of use */              \
118     type##Oop    operator () () const            { return obj(); } \
119     type##Oop    operator -> () const            { return non_null_obj(); } \
120   };
121 
122 
123 DEF_HANDLE(instance         , is_instance_noinline         )
124 DEF_HANDLE(array            , is_array_noinline            )
125 DEF_HANDLE(objArray         , is_objArray_noinline         )
126 DEF_HANDLE(typeArray        , is_typeArray_noinline        )
127 
128 //------------------------------------------------------------------------------------------------------------------------
129 
130 // Metadata Handles.  Unlike oop Handles these are needed to prevent metadata
131 // from being reclaimed by RedefineClasses.
132 // Metadata Handles should be passed around as const references to avoid copy construction
133 // and destruction for parameters.
134 
135 // Specific Handles for different oop types

 56 //
 57 // Handles are specialized for different oop types to provide extra type
 58 // information and avoid unnecessary casting. For each oop type xxxOop
 59 // there is a corresponding handle called xxxHandle.
 60 
 61 //------------------------------------------------------------------------------------------------------------------------
 62 // Base class for all handles. Provides overloading of frequently
 63 // used operators for ease of use.
 64 
 65 class Handle {
 66  private:
 67   oop* _handle;
 68 
 69  protected:
 70   oop     obj() const                            { return _handle == NULL ? (oop)NULL : *_handle; }
 71   oop     non_null_obj() const                   { assert(_handle != NULL, "resolving NULL handle"); return *_handle; }
 72 
 73  public:
 74   // Constructors
 75   Handle()                                       { _handle = NULL; }
 76   inline Handle(Thread* thread, oop obj, bool allocNull = false);
 77 
 78   // General access
 79   oop     operator () () const                   { return obj(); }
 80   oop     operator -> () const                   { return non_null_obj(); }
 81 
 82   bool operator == (oop o) const                 { return obj() == o; }
 83   bool operator != (oop o) const                 { return obj() != o; }
 84   bool operator == (const Handle& h) const       { return obj() == h.obj(); }
 85   bool operator != (const Handle& h) const       { return obj() != h.obj(); }
 86 
 87   // Null checks
 88   bool    is_null() const                        { return _handle == NULL; }
 89   bool    not_null() const                       { return _handle != NULL; }
 90 
 91   // Debugging
 92   void    print()                                { obj()->print(); }
 93 
 94   // Direct interface, use very sparingly.
 95   // Used by JavaCalls to quickly convert handles and to create handles static data structures.
 96   // Constructor takes a dummy argument to prevent unintentional type conversion in C++.
 97   Handle(oop *handle, bool dummy)                { _handle = handle; }
 98 
 99   // Raw handle access. Allows easy duplication of Handles. This can be very unsafe
100   // since duplicates is only valid as long as original handle is alive.
101   oop* raw_value() const                         { return _handle; }
102   static oop raw_resolve(oop *handle)            { return handle == NULL ? (oop)NULL : *handle; }
103 };
104 
105 // Specific Handles for different oop types
106 #define DEF_HANDLE(type, is_a)                   \
107   class type##Handle: public Handle {            \
108    protected:                                    \
109     type##Oop    obj() const                     { return (type##Oop)Handle::obj(); } \
110     type##Oop    non_null_obj() const            { return (type##Oop)Handle::non_null_obj(); } \
111                                                  \
112    public:                                       \
113     /* Constructors */                           \
114     type##Handle ()                              : Handle()                 {} \
115     inline type##Handle (Thread* thread, type##Oop obj, bool allocNull = false); \
116     \
117     /* Operators for ease of use */              \
118     type##Oop    operator () () const            { return obj(); } \
119     type##Oop    operator -> () const            { return non_null_obj(); } \
120   };
121 
122 
123 DEF_HANDLE(instance         , is_instance_noinline         )
124 DEF_HANDLE(array            , is_array_noinline            )
125 DEF_HANDLE(objArray         , is_objArray_noinline         )
126 DEF_HANDLE(typeArray        , is_typeArray_noinline        )
127 
128 //------------------------------------------------------------------------------------------------------------------------
129 
130 // Metadata Handles.  Unlike oop Handles these are needed to prevent metadata
131 // from being reclaimed by RedefineClasses.
132 // Metadata Handles should be passed around as const references to avoid copy construction
133 // and destruction for parameters.
134 
135 // Specific Handles for different oop types
< prev index next >