Skip to content

8297106: Remove the -Xcheck:jni local reference capacity checking #3749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 1 addition & 35 deletions src/hotspot/share/prims/jniCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
#include "utilities/formatBuffer.hpp"
#include "utilities/utf8.hpp"

// Complain every extra number of unplanned local refs
#define CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD 32

// Heap objects are allowed to be directly referenced only in VM code,
// not in native code.

Expand Down Expand Up @@ -202,17 +199,6 @@ check_pending_exception(JavaThread* thr) {
}
}

/**
* Add to the planned number of handles. I.e. plus current live & warning threshold
*/
static inline void
add_planned_handle_capacity(JNIHandleBlock* handles, size_t capacity) {
handles->set_planned_capacity(capacity +
handles->get_number_of_live_handles() +
CHECK_JNI_LOCAL_REF_CAP_WARN_THRESHOLD);
}


static inline void
functionEnterCritical(JavaThread* thr)
{
Expand Down Expand Up @@ -244,18 +230,7 @@ functionEnterExceptionAllowed(JavaThread* thr)
static inline void
functionExit(JavaThread* thr)
{
JNIHandleBlock* handles = thr->active_handles();
size_t planned_capacity = handles->get_planned_capacity();
size_t live_handles = handles->get_number_of_live_handles();
if (live_handles > planned_capacity) {
IN_VM(
tty->print_cr("WARNING: JNI local refs: " SIZE_FORMAT ", exceeds capacity: " SIZE_FORMAT,
live_handles, planned_capacity);
thr->print_stack();
)
// Complain just the once, reset to current + warn threshold
add_planned_handle_capacity(handles, 0);
}
// No checks at this time
}

static inline void
Expand Down Expand Up @@ -746,9 +721,6 @@ JNI_ENTRY_CHECKED(jint,
if (capacity < 0)
NativeReportJNIFatalError(thr, "negative capacity");
jint result = UNCHECKED()->PushLocalFrame(env, capacity);
if (result == JNI_OK) {
add_planned_handle_capacity(thr->active_handles(), capacity);
}
functionExit(thr);
return result;
JNI_END
Expand Down Expand Up @@ -850,12 +822,6 @@ JNI_ENTRY_CHECKED(jint,
NativeReportJNIFatalError(thr, "negative capacity");
}
jint result = UNCHECKED()->EnsureLocalCapacity(env, capacity);
if (result == JNI_OK) {
// increase local ref capacity if needed
if ((size_t)capacity > thr->active_handles()->get_planned_capacity()) {
add_planned_handle_capacity(thr->active_handles(), capacity);
}
}
functionExit(thr);
return result;
JNI_END
Expand Down
17 changes: 0 additions & 17 deletions src/hotspot/share/runtime/jniHandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ JNIHandleBlock* JNIHandleBlock::allocate_block(Thread* thread, AllocFailType all
block->_top = 0;
block->_next = NULL;
block->_pop_frame_link = NULL;
block->_planned_capacity = block_size_in_oops;
// _last, _free_list & _allocate_before_rebuild initialized in allocate_handle
debug_only(block->_last = NULL);
debug_only(block->_free_list = NULL);
Expand Down Expand Up @@ -591,22 +590,6 @@ size_t JNIHandleBlock::length() const {
return result;
}

class CountJNIHandleClosure: public OopClosure {
private:
int _count;
public:
CountJNIHandleClosure(): _count(0) {}
virtual void do_oop(oop* ooph) { _count++; }
virtual void do_oop(narrowOop* unused) { ShouldNotReachHere(); }
int count() { return _count; }
};

const size_t JNIHandleBlock::get_number_of_live_handles() {
CountJNIHandleClosure counter;
oops_do(&counter);
return counter.count();
}

// This method is not thread-safe, i.e., must be called while holding a lock on the
// structure.
size_t JNIHandleBlock::memory_usage() const {
Expand Down
8 changes: 0 additions & 8 deletions src/hotspot/share/runtime/jniHandles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ class JNIHandleBlock : public CHeapObj<mtInternal> {
uintptr_t* _free_list; // Handle free list
int _allocate_before_rebuild; // Number of blocks to allocate before rebuilding free list

// Check JNI, "planned capacity" for current frame (or push/ensure)
size_t _planned_capacity;

#ifndef PRODUCT
JNIHandleBlock* _block_list_link; // Link for list below
static JNIHandleBlock* _block_list; // List of all allocated blocks (for debugging only)
Expand Down Expand Up @@ -193,11 +190,6 @@ class JNIHandleBlock : public CHeapObj<mtInternal> {
// Traversal of handles
void oops_do(OopClosure* f);

// Checked JNI support
void set_planned_capacity(size_t planned_capacity) { _planned_capacity = planned_capacity; }
const size_t get_planned_capacity() { return _planned_capacity; }
const size_t get_number_of_live_handles();

// Debugging
bool chain_contains(jobject handle) const; // Does this block or following blocks contain handle
bool contains(jobject handle) const; // Does this block contain handle
Expand Down
4 changes: 0 additions & 4 deletions src/java.base/share/man/java.1
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,6 @@ A JNI call was made without checking for a pending exception from a
previous JNI call, and the current call is not safe when an exception
may be pending.
.IP \[bu] 2
The number of JNI local references existing when a JNI function
terminates exceeds the number guaranteed to be available.
See the \f[CB]EnsureLocalcapacity\f[R] function.
.IP \[bu] 2
A class descriptor is in decorated format (\f[CB]Lname;\f[R]) when it
should not be.
.IP \[bu] 2
Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,6 @@ tools/jlink/plugins/CompressorPluginTest.java 8247407 generic-
############################################################################

# core_svc
tools/launcher/TestXcheckJNIWarnings.java#jdwp-agent 8296936 generic-all

############################################################################

Expand Down

This file was deleted.