67 // address designated by the jobject to produce the corresponding 68 // jweak. Accessing the value of a jobject must account for it 69 // being a possibly offset jweak. 70 static const uintptr_t weak_tag_size = 1; 71 static const uintptr_t weak_tag_alignment = (1u << weak_tag_size); 72 static const uintptr_t weak_tag_mask = weak_tag_alignment - 1; 73 static const int weak_tag_value = 1; 74 75 // Resolve handle into oop 76 inline static oop resolve(jobject handle); 77 // Resolve handle into oop, result guaranteed not to be null 78 inline static oop resolve_non_null(jobject handle); 79 // Resolve externally provided handle into oop with some guards 80 static oop resolve_external_guard(jobject handle); 81 82 // Check for equality without keeping objects alive 83 static bool is_same_object(jobject handle1, jobject handle2); 84 85 // Local handles 86 static jobject make_local(oop obj); 87 static jobject make_local(Thread* thread, oop obj); // Faster version when current thread is known 88 inline static void destroy_local(jobject handle); 89 90 // Global handles 91 static jobject make_global(Handle obj, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); 92 static void destroy_global(jobject handle); 93 94 // Weak global handles 95 static jobject make_weak_global(Handle obj, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); 96 static void destroy_weak_global(jobject handle); 97 static bool is_global_weak_cleared(jweak handle); // Test jweak without resolution 98 99 // Initialization 100 static void initialize(); 101 102 // Debugging 103 static void print_on(outputStream* st); 104 static void print(); 105 static void verify(); 106 // The category predicates all require handle != NULL. 107 static bool is_local_handle(Thread* thread, jobject handle); 108 static bool is_frame_handle(JavaThread* thread, jobject handle); 109 static bool is_global_handle(jobject handle); 110 static bool is_weak_global_handle(jobject handle); 111 static size_t global_handle_memory_usage(); 112 static size_t weak_global_handle_memory_usage(); 113 114 #ifndef PRODUCT 115 // Is handle from any local block of any thread? 159 160 #ifndef PRODUCT 161 JNIHandleBlock* _block_list_link; // Link for list below 162 static JNIHandleBlock* _block_list; // List of all allocated blocks (for debugging only) 163 #endif 164 165 static JNIHandleBlock* _block_free_list; // Free list of currently unused blocks 166 static int _blocks_allocated; // For debugging/printing 167 168 // Fill block with bad_handle values 169 void zap() NOT_DEBUG_RETURN; 170 171 // Free list computation 172 void rebuild_free_list(); 173 174 // No more handles in the both the current and following blocks 175 void clear() { _top = 0; } 176 177 public: 178 // Handle allocation 179 jobject allocate_handle(oop obj); 180 181 // Block allocation and block free list management 182 static JNIHandleBlock* allocate_block(Thread* thread = NULL); 183 static void release_block(JNIHandleBlock* block, Thread* thread = NULL); 184 185 // JNI PushLocalFrame/PopLocalFrame support 186 JNIHandleBlock* pop_frame_link() const { return _pop_frame_link; } 187 void set_pop_frame_link(JNIHandleBlock* block) { _pop_frame_link = block; } 188 189 // Stub generator support 190 static int top_offset_in_bytes() { return offset_of(JNIHandleBlock, _top); } 191 192 // Garbage collection support 193 // Traversal of handles 194 void oops_do(OopClosure* f); 195 196 // Checked JNI support 197 void set_planned_capacity(size_t planned_capacity) { _planned_capacity = planned_capacity; } 198 const size_t get_planned_capacity() { return _planned_capacity; } 199 const size_t get_number_of_live_handles(); 200 201 // Debugging 202 bool chain_contains(jobject handle) const; // Does this block or following blocks contain handle | 67 // address designated by the jobject to produce the corresponding 68 // jweak. Accessing the value of a jobject must account for it 69 // being a possibly offset jweak. 70 static const uintptr_t weak_tag_size = 1; 71 static const uintptr_t weak_tag_alignment = (1u << weak_tag_size); 72 static const uintptr_t weak_tag_mask = weak_tag_alignment - 1; 73 static const int weak_tag_value = 1; 74 75 // Resolve handle into oop 76 inline static oop resolve(jobject handle); 77 // Resolve handle into oop, result guaranteed not to be null 78 inline static oop resolve_non_null(jobject handle); 79 // Resolve externally provided handle into oop with some guards 80 static oop resolve_external_guard(jobject handle); 81 82 // Check for equality without keeping objects alive 83 static bool is_same_object(jobject handle1, jobject handle2); 84 85 // Local handles 86 static jobject make_local(oop obj); 87 static jobject make_local(Thread* thread, oop obj, // Faster version when current thread is known 88 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); 89 inline static void destroy_local(jobject handle); 90 91 // Global handles 92 static jobject make_global(Handle obj, 93 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); 94 static void destroy_global(jobject handle); 95 96 // Weak global handles 97 static jobject make_weak_global(Handle obj, 98 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); 99 static void destroy_weak_global(jobject handle); 100 static bool is_global_weak_cleared(jweak handle); // Test jweak without resolution 101 102 // Initialization 103 static void initialize(); 104 105 // Debugging 106 static void print_on(outputStream* st); 107 static void print(); 108 static void verify(); 109 // The category predicates all require handle != NULL. 110 static bool is_local_handle(Thread* thread, jobject handle); 111 static bool is_frame_handle(JavaThread* thread, jobject handle); 112 static bool is_global_handle(jobject handle); 113 static bool is_weak_global_handle(jobject handle); 114 static size_t global_handle_memory_usage(); 115 static size_t weak_global_handle_memory_usage(); 116 117 #ifndef PRODUCT 118 // Is handle from any local block of any thread? 162 163 #ifndef PRODUCT 164 JNIHandleBlock* _block_list_link; // Link for list below 165 static JNIHandleBlock* _block_list; // List of all allocated blocks (for debugging only) 166 #endif 167 168 static JNIHandleBlock* _block_free_list; // Free list of currently unused blocks 169 static int _blocks_allocated; // For debugging/printing 170 171 // Fill block with bad_handle values 172 void zap() NOT_DEBUG_RETURN; 173 174 // Free list computation 175 void rebuild_free_list(); 176 177 // No more handles in the both the current and following blocks 178 void clear() { _top = 0; } 179 180 public: 181 // Handle allocation 182 jobject allocate_handle(oop obj, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); 183 184 // Block allocation and block free list management 185 static JNIHandleBlock* allocate_block(Thread* thread = NULL, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); 186 static void release_block(JNIHandleBlock* block, Thread* thread = NULL); 187 188 // JNI PushLocalFrame/PopLocalFrame support 189 JNIHandleBlock* pop_frame_link() const { return _pop_frame_link; } 190 void set_pop_frame_link(JNIHandleBlock* block) { _pop_frame_link = block; } 191 192 // Stub generator support 193 static int top_offset_in_bytes() { return offset_of(JNIHandleBlock, _top); } 194 195 // Garbage collection support 196 // Traversal of handles 197 void oops_do(OopClosure* f); 198 199 // Checked JNI support 200 void set_planned_capacity(size_t planned_capacity) { _planned_capacity = planned_capacity; } 201 const size_t get_planned_capacity() { return _planned_capacity; } 202 const size_t get_number_of_live_handles(); 203 204 // Debugging 205 bool chain_contains(jobject handle) const; // Does this block or following blocks contain handle |