提交 aed6603b 编写于 作者: P poonam

8043224: -Xcheck:jni improvements to exception checking and excessive local refs

Summary: Warning when not checking exceptions from function that require so, also when local refs expand beyond capacity.
Reviewed-by: dsimms
上级 ae406f7d
/* /*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -235,7 +235,7 @@ protected: ...@@ -235,7 +235,7 @@ protected:
* @return the size of the user data. * @return the size of the user data.
*/ */
size_t get_user_size() const { size_t get_user_size() const {
assert(_base_addr, "Not wrapping any memory"); assert(_base_addr != NULL, "Not wrapping any memory");
return get_head_guard()->get_user_size(); return get_head_guard()->get_user_size();
} }
...@@ -245,7 +245,7 @@ protected: ...@@ -245,7 +245,7 @@ protected:
* @return the user data pointer. * @return the user data pointer.
*/ */
u_char* get_user_ptr() const { u_char* get_user_ptr() const {
assert(_base_addr, "Not wrapping any memory"); assert(_base_addr != NULL, "Not wrapping any memory");
return _base_addr + sizeof(GuardHeader); return _base_addr + sizeof(GuardHeader);
} }
...@@ -281,7 +281,7 @@ protected: ...@@ -281,7 +281,7 @@ protected:
memset(get_user_ptr(), ch, get_user_size()); memset(get_user_ptr(), ch, get_user_size());
} }
public: public:
/** /**
* Return the total size required for wrapping the given user size. * Return the total size required for wrapping the given user size.
* *
......
此差异已折叠。
/* /*
* Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -296,6 +296,7 @@ JNIHandleBlock* JNIHandleBlock::allocate_block(Thread* thread) { ...@@ -296,6 +296,7 @@ JNIHandleBlock* JNIHandleBlock::allocate_block(Thread* thread) {
block->_top = 0; block->_top = 0;
block->_next = NULL; block->_next = NULL;
block->_pop_frame_link = NULL; block->_pop_frame_link = NULL;
block->_planned_capacity = block_size_in_oops;
// _last, _free_list & _allocate_before_rebuild initialized in allocate_handle // _last, _free_list & _allocate_before_rebuild initialized in allocate_handle
debug_only(block->_last = NULL); debug_only(block->_last = NULL);
debug_only(block->_free_list = NULL); debug_only(block->_free_list = NULL);
...@@ -529,6 +530,12 @@ int JNIHandleBlock::length() const { ...@@ -529,6 +530,12 @@ int JNIHandleBlock::length() const {
return result; return result;
} }
const size_t JNIHandleBlock::get_number_of_live_handles() {
CountHandleClosure counter;
oops_do(&counter);
return counter.count();
}
// This method is not thread-safe, i.e., must be called whule holding a lock on the // This method is not thread-safe, i.e., must be called whule holding a lock on the
// structure. // structure.
long JNIHandleBlock::memory_usage() const { long JNIHandleBlock::memory_usage() const {
......
/* /*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -112,6 +112,9 @@ class JNIHandleBlock : public CHeapObj<mtInternal> { ...@@ -112,6 +112,9 @@ class JNIHandleBlock : public CHeapObj<mtInternal> {
oop* _free_list; // Handle free list oop* _free_list; // Handle free list
int _allocate_before_rebuild; // Number of blocks to allocate before rebuilding 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 #ifndef PRODUCT
JNIHandleBlock* _block_list_link; // Link for list below JNIHandleBlock* _block_list_link; // Link for list below
static JNIHandleBlock* _block_list; // List of all allocated blocks (for debugging only) static JNIHandleBlock* _block_list; // List of all allocated blocks (for debugging only)
...@@ -152,6 +155,11 @@ class JNIHandleBlock : public CHeapObj<mtInternal> { ...@@ -152,6 +155,11 @@ class JNIHandleBlock : public CHeapObj<mtInternal> {
// Traversal of weak handles. Unreachable oops are cleared. // Traversal of weak handles. Unreachable oops are cleared.
void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* f); void weak_oops_do(BoolObjectClosure* is_alive, 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 // Debugging
bool chain_contains(jobject handle) const; // Does this block or following blocks contain handle bool chain_contains(jobject handle) const; // Does this block or following blocks contain handle
bool contains(jobject handle) const; // Does this block contain handle bool contains(jobject handle) const; // Does this block contain handle
......
/* /*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1465,6 +1465,7 @@ void JavaThread::initialize() { ...@@ -1465,6 +1465,7 @@ void JavaThread::initialize() {
_thread_stat = new ThreadStatistics(); _thread_stat = new ThreadStatistics();
_blocked_on_compilation = false; _blocked_on_compilation = false;
_jni_active_critical = 0; _jni_active_critical = 0;
_pending_jni_exception_check_fn = NULL;
_do_not_unlock_if_synchronized = false; _do_not_unlock_if_synchronized = false;
_cached_monitor_info = NULL; _cached_monitor_info = NULL;
_parker = Parker::Allocate(this) ; _parker = Parker::Allocate(this) ;
......
/* /*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -926,6 +926,9 @@ class JavaThread: public Thread { ...@@ -926,6 +926,9 @@ class JavaThread: public Thread {
// support for JNI critical regions // support for JNI critical regions
jint _jni_active_critical; // count of entries into JNI critical region jint _jni_active_critical; // count of entries into JNI critical region
// Checked JNI: function name requires exception check
char* _pending_jni_exception_check_fn;
// For deadlock detection. // For deadlock detection.
int _depth_first_number; int _depth_first_number;
...@@ -1408,6 +1411,12 @@ class JavaThread: public Thread { ...@@ -1408,6 +1411,12 @@ class JavaThread: public Thread {
assert(_jni_active_critical >= 0, assert(_jni_active_critical >= 0,
"JNI critical nesting problem?"); } "JNI critical nesting problem?"); }
// Checked JNI, is the programmer required to check for exceptions, specify which function name
bool is_pending_jni_exception_check() const { return _pending_jni_exception_check_fn != NULL; }
void clear_pending_jni_exception_check() { _pending_jni_exception_check_fn = NULL; }
const char* get_pending_jni_exception_check() const { return _pending_jni_exception_check_fn; }
void set_pending_jni_exception_check(const char* fn_name) { _pending_jni_exception_check_fn = (char*) fn_name; }
// For deadlock detection // For deadlock detection
int depth_first_number() { return _depth_first_number; } int depth_first_number() { return _depth_first_number; }
void set_depth_first_number(int dfn) { _depth_first_number = dfn; } void set_depth_first_number(int dfn) { _depth_first_number = dfn; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册