--- a/hotspot/src/os/aix/vm/os_aix.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/aix/vm/os_aix.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -4137,15 +4137,6 @@
return 1;
}
-int os::socket_available(int fd, jint *pbytes) {
- // Linux doc says EINTR not returned, unlike Solaris
- int ret = ::ioctl(fd, FIONREAD, pbytes);
-
- //%% note ioctl can return 0 when successful, JVM_SocketAvailable
- // is expected to return 0 on failure and 1 on success to the jdk.
- return (ret < 0) ? 0 : 1;
-}
-
// Map a block of memory.
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
char *addr, size_t bytes, bool read_only,
--- a/hotspot/src/os/aix/vm/os_aix.inline.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/aix/vm/os_aix.inline.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -178,92 +178,14 @@
return os::send(fd, buf, nBytes, flags);
}
-inline int os::timeout(int fd, long timeout) {
- julong prevtime,newtime;
- struct timeval t;
-
- gettimeofday(&t, NULL);
- prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
-
- for(;;) {
- struct pollfd pfd;
-
- pfd.fd = fd;
- pfd.events = POLLIN | POLLERR;
-
- int res = ::poll(&pfd, 1, timeout);
-
- if (res == OS_ERR && errno == EINTR) {
-
- // On Linux any value < 0 means "forever"
-
- if(timeout >= 0) {
- gettimeofday(&t, NULL);
- newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
- timeout -= newtime - prevtime;
- if(timeout <= 0)
- return OS_OK;
- prevtime = newtime;
- }
- } else
- return res;
- }
-}
-
-inline int os::listen(int fd, int count) {
- return ::listen(fd, count);
-}
-
inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
RESTARTABLE_RETURN_INT(::connect(fd, him, len));
}
-inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
- // Linux doc says this can't return EINTR, unlike accept() on Solaris.
- // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
- return (int)::accept(fd, him, len);
-}
-
-inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
- sockaddr* from, socklen_t* fromlen) {
- RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
-}
-
-inline int os::sendto(int fd, char* buf, size_t len, uint flags,
- struct sockaddr* to, socklen_t tolen) {
- RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
-}
-
-inline int os::socket_shutdown(int fd, int howto) {
- return ::shutdown(fd, howto);
-}
-
-inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
- return ::bind(fd, him, len);
-}
-
-inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
- return ::getsockname(fd, him, len);
-}
-
-inline int os::get_host_name(char* name, int namelen) {
- return ::gethostname(name, namelen);
-}
-
inline struct hostent* os::get_host_by_name(char* name) {
return ::gethostbyname(name);
}
-inline int os::get_sock_opt(int fd, int level, int optname,
- char* optval, socklen_t* optlen) {
- return ::getsockopt(fd, level, optname, optval, optlen);
-}
-
-inline int os::set_sock_opt(int fd, int level, int optname,
- const char* optval, socklen_t optlen) {
- return ::setsockopt(fd, level, optname, optval, optlen);
-}
-
inline bool os::supports_monotonic_clock() {
// mread_real_time() is monotonic on AIX (see os::javaTimeNanos() comments)
return true;
--- a/hotspot/src/os/bsd/vm/os_bsd.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/bsd/vm/os_bsd.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -3958,21 +3958,6 @@
return 1;
}
-int os::socket_available(int fd, jint *pbytes) {
- if (fd < 0) {
- return OS_OK;
- }
-
- int ret;
-
- RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret);
-
- //%% note ioctl can return 0 when successful, JVM_SocketAvailable
- // is expected to return 0 on failure and 1 on success to the jdk.
-
- return (ret == OS_ERR) ? 0 : 1;
-}
-
// Map a block of memory.
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
char *addr, size_t bytes, bool read_only,
--- a/hotspot/src/os/bsd/vm/os_bsd.inline.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/bsd/vm/os_bsd.inline.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -181,91 +181,14 @@
return os::send(fd, buf, nBytes, flags);
}
-inline int os::timeout(int fd, long timeout) {
- julong prevtime,newtime;
- struct timeval t;
-
- gettimeofday(&t, NULL);
- prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
-
- for(;;) {
- struct pollfd pfd;
-
- pfd.fd = fd;
- pfd.events = POLLIN | POLLERR;
-
- int res = ::poll(&pfd, 1, timeout);
-
- if (res == OS_ERR && errno == EINTR) {
-
- // On Bsd any value < 0 means "forever"
-
- if(timeout >= 0) {
- gettimeofday(&t, NULL);
- newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
- timeout -= newtime - prevtime;
- if(timeout <= 0)
- return OS_OK;
- prevtime = newtime;
- }
- } else
- return res;
- }
-}
-
-inline int os::listen(int fd, int count) {
- return ::listen(fd, count);
-}
-
inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
RESTARTABLE_RETURN_INT(::connect(fd, him, len));
}
-inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
- // At least OpenBSD and FreeBSD can return EINTR from accept.
- RESTARTABLE_RETURN_INT(::accept(fd, him, len));
-}
-
-inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
- sockaddr* from, socklen_t* fromlen) {
- RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
-}
-
-inline int os::sendto(int fd, char* buf, size_t len, uint flags,
- struct sockaddr *to, socklen_t tolen) {
- RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
-}
-
-inline int os::socket_shutdown(int fd, int howto) {
- return ::shutdown(fd, howto);
-}
-
-inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
- return ::bind(fd, him, len);
-}
-
-inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
- return ::getsockname(fd, him, len);
-}
-
-inline int os::get_host_name(char* name, int namelen) {
- return ::gethostname(name, namelen);
-}
-
inline struct hostent* os::get_host_by_name(char* name) {
return ::gethostbyname(name);
}
-inline int os::get_sock_opt(int fd, int level, int optname,
- char *optval, socklen_t* optlen) {
- return ::getsockopt(fd, level, optname, optval, optlen);
-}
-
-inline int os::set_sock_opt(int fd, int level, int optname,
- const char* optval, socklen_t optlen) {
- return ::setsockopt(fd, level, optname, optval, optlen);
-}
-
inline bool os::supports_monotonic_clock() {
#ifdef __APPLE__
return true;
--- a/hotspot/src/os/linux/vm/os_linux.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/linux/vm/os_linux.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -5211,15 +5211,6 @@
return 1;
}
-int os::socket_available(int fd, jint *pbytes) {
- // Linux doc says EINTR not returned, unlike Solaris
- int ret = ::ioctl(fd, FIONREAD, pbytes);
-
- //%% note ioctl can return 0 when successful, JVM_SocketAvailable
- // is expected to return 0 on failure and 1 on success to the jdk.
- return (ret < 0) ? 0 : 1;
-}
-
// Map a block of memory.
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
char *addr, size_t bytes, bool read_only,
--- a/hotspot/src/os/linux/vm/os_linux.inline.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/linux/vm/os_linux.inline.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -173,92 +173,14 @@
return os::send(fd, buf, nBytes, flags);
}
-inline int os::timeout(int fd, long timeout) {
- julong prevtime,newtime;
- struct timeval t;
-
- gettimeofday(&t, NULL);
- prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
-
- for(;;) {
- struct pollfd pfd;
-
- pfd.fd = fd;
- pfd.events = POLLIN | POLLERR;
-
- int res = ::poll(&pfd, 1, timeout);
-
- if (res == OS_ERR && errno == EINTR) {
-
- // On Linux any value < 0 means "forever"
-
- if(timeout >= 0) {
- gettimeofday(&t, NULL);
- newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
- timeout -= newtime - prevtime;
- if(timeout <= 0)
- return OS_OK;
- prevtime = newtime;
- }
- } else
- return res;
- }
-}
-
-inline int os::listen(int fd, int count) {
- return ::listen(fd, count);
-}
-
inline int os::connect(int fd, struct sockaddr* him, socklen_t len) {
RESTARTABLE_RETURN_INT(::connect(fd, him, len));
}
-inline int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
- // Linux doc says this can't return EINTR, unlike accept() on Solaris.
- // But see attachListener_linux.cpp, LinuxAttachListener::dequeue().
- return (int)::accept(fd, him, len);
-}
-
-inline int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
- sockaddr* from, socklen_t* fromlen) {
- RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
-}
-
-inline int os::sendto(int fd, char* buf, size_t len, uint flags,
- struct sockaddr* to, socklen_t tolen) {
- RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
-}
-
-inline int os::socket_shutdown(int fd, int howto) {
- return ::shutdown(fd, howto);
-}
-
-inline int os::bind(int fd, struct sockaddr* him, socklen_t len) {
- return ::bind(fd, him, len);
-}
-
-inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
- return ::getsockname(fd, him, len);
-}
-
-inline int os::get_host_name(char* name, int namelen) {
- return ::gethostname(name, namelen);
-}
-
inline struct hostent* os::get_host_by_name(char* name) {
return ::gethostbyname(name);
}
-inline int os::get_sock_opt(int fd, int level, int optname,
- char* optval, socklen_t* optlen) {
- return ::getsockopt(fd, level, optname, optval, optlen);
-}
-
-inline int os::set_sock_opt(int fd, int level, int optname,
- const char* optval, socklen_t optlen) {
- return ::setsockopt(fd, level, optname, optval, optlen);
-}
-
inline bool os::supports_monotonic_clock() {
return Linux::_clock_gettime != NULL;
}
--- a/hotspot/src/os/solaris/vm/os_solaris.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/solaris/vm/os_solaris.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -5912,37 +5912,6 @@
// a poll() is done with timeout == -1, in which case we repeat with this
// "wait forever" value.
-int os::timeout(int fd, long timeout) {
- int res;
- struct timeval t;
- julong prevtime, newtime;
- static const char* aNull = 0;
- struct pollfd pfd;
- pfd.fd = fd;
- pfd.events = POLLIN;
-
- assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
- "Assumed _thread_in_native");
-
- gettimeofday(&t, &aNull);
- prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000;
-
- for (;;) {
- res = ::poll(&pfd, 1, timeout);
- if (res == OS_ERR && errno == EINTR) {
- if (timeout != -1) {
- gettimeofday(&t, &aNull);
- newtime = ((julong)t.tv_sec * 1000) + t.tv_usec /1000;
- timeout -= newtime - prevtime;
- if (timeout <= 0) {
- return OS_OK;
- }
- prevtime = newtime;
- }
- } else return res;
- }
-}
-
int os::connect(int fd, struct sockaddr *him, socklen_t len) {
int _result;
_result = ::connect(fd, him, len);
@@ -5982,46 +5951,6 @@
return _result;
}
-int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
- if (fd < 0) {
- return OS_ERR;
- }
- assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
- "Assumed _thread_in_native");
- RESTARTABLE_RETURN_INT((int)::accept(fd, him, len));
-}
-
-int os::recvfrom(int fd, char* buf, size_t nBytes, uint flags,
- sockaddr* from, socklen_t* fromlen) {
- assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
- "Assumed _thread_in_native");
- RESTARTABLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, flags, from, fromlen));
-}
-
-int os::sendto(int fd, char* buf, size_t len, uint flags,
- struct sockaddr* to, socklen_t tolen) {
- assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
- "Assumed _thread_in_native");
- RESTARTABLE_RETURN_INT((int)::sendto(fd, buf, len, flags, to, tolen));
-}
-
-int os::socket_available(int fd, jint *pbytes) {
- if (fd < 0) {
- return OS_OK;
- }
- int ret;
- RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret);
- // note: ioctl can return 0 when successful, JVM_SocketAvailable
- // is expected to return 0 on failure and 1 on success to the jdk.
- return (ret == OS_ERR) ? 0 : 1;
-}
-
-int os::bind(int fd, struct sockaddr* him, socklen_t len) {
- assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
- "Assumed _thread_in_native");
- return ::bind(fd, him, len);
-}
-
// Get the default path to the core file
// Returns the length of the string
int os::get_core_path(char* buffer, size_t bufferSize) {
--- a/hotspot/src/os/solaris/vm/os_solaris.inline.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/solaris/vm/os_solaris.inline.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -120,38 +120,10 @@
return ::socket(domain, type, protocol);
}
-inline int os::listen(int fd, int count) {
- if (fd < 0) return OS_ERR;
-
- return ::listen(fd, count);
-}
-
-inline int os::socket_shutdown(int fd, int howto){
- return ::shutdown(fd, howto);
-}
-
-inline int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len){
- return ::getsockname(fd, him, len);
-}
-
-inline int os::get_host_name(char* name, int namelen){
- return ::gethostname(name, namelen);
-}
-
inline struct hostent* os::get_host_by_name(char* name) {
return ::gethostbyname(name);
}
-inline int os::get_sock_opt(int fd, int level, int optname,
- char* optval, socklen_t* optlen) {
- return ::getsockopt(fd, level, optname, optval, optlen);
-}
-
-inline int os::set_sock_opt(int fd, int level, int optname,
- const char *optval, socklen_t optlen) {
- return ::setsockopt(fd, level, optname, optval, optlen);
-}
-
inline bool os::supports_monotonic_clock() {
// javaTimeNanos() is monotonic on Solaris, see getTimeNanos() comments
return true;
--- a/hotspot/src/os/windows/vm/os_windows.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/os/windows/vm/os_windows.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -5091,39 +5091,14 @@
return ::closesocket(fd);
}
-int os::socket_available(int fd, jint *pbytes) {
- int ret = ::ioctlsocket(fd, FIONREAD, (u_long*)pbytes);
- return (ret < 0) ? 0 : 1;
-}
-
int os::socket(int domain, int type, int protocol) {
return ::socket(domain, type, protocol);
}
-int os::listen(int fd, int count) {
- return ::listen(fd, count);
-}
-
int os::connect(int fd, struct sockaddr* him, socklen_t len) {
return ::connect(fd, him, len);
}
-int os::accept(int fd, struct sockaddr* him, socklen_t* len) {
- return ::accept(fd, him, len);
-}
-
-int os::sendto(int fd, char* buf, size_t len, uint flags,
- struct sockaddr* to, socklen_t tolen) {
-
- return ::sendto(fd, buf, (int)len, flags, to, tolen);
-}
-
-int os::recvfrom(int fd, char *buf, size_t nBytes, uint flags,
- sockaddr* from, socklen_t* fromlen) {
-
- return ::recvfrom(fd, buf, (int)nBytes, flags, from, fromlen);
-}
-
int os::recv(int fd, char* buf, size_t nBytes, uint flags) {
return ::recv(fd, buf, (int)nBytes, flags);
}
@@ -5136,45 +5111,6 @@
return ::send(fd, buf, (int)nBytes, flags);
}
-int os::timeout(int fd, long timeout) {
- fd_set tbl;
- struct timeval t;
-
- t.tv_sec = timeout / 1000;
- t.tv_usec = (timeout % 1000) * 1000;
-
- tbl.fd_count = 1;
- tbl.fd_array[0] = fd;
-
- return ::select(1, &tbl, 0, 0, &t);
-}
-
-int os::get_host_name(char* name, int namelen) {
- return ::gethostname(name, namelen);
-}
-
-int os::socket_shutdown(int fd, int howto) {
- return ::shutdown(fd, howto);
-}
-
-int os::bind(int fd, struct sockaddr* him, socklen_t len) {
- return ::bind(fd, him, len);
-}
-
-int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) {
- return ::getsockname(fd, him, len);
-}
-
-int os::get_sock_opt(int fd, int level, int optname,
- char* optval, socklen_t* optlen) {
- return ::getsockopt(fd, level, optname, optval, optlen);
-}
-
-int os::set_sock_opt(int fd, int level, int optname,
- const char* optval, socklen_t optlen) {
- return ::setsockopt(fd, level, optname, optval, optlen);
-}
-
// WINDOWS CONTEXT Flags for THREAD_SAMPLING
#if defined(IA32)
#define sampling_context_flags (CONTEXT_FULL | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS)
--- a/hotspot/src/share/vm/classfile/classFileParser.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/classfile/classFileParser.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -2557,7 +2557,7 @@
Array<Method*>* ClassFileParser::parse_methods(bool is_interface,
AccessFlags* promoted_flags,
bool* has_final_method,
- bool* has_default_methods,
+ bool* declares_default_methods,
TRAPS) {
ClassFileStream* cfs = stream();
cfs->guarantee_more(2, CHECK_NULL); // length
@@ -2576,11 +2576,11 @@
if (method->is_final()) {
*has_final_method = true;
}
- if (is_interface && !(*has_default_methods)
- && !method->is_abstract() && !method->is_static()
- && !method->is_private()) {
- // default method
- *has_default_methods = true;
+ // declares_default_methods: declares concrete instance methods, any access flags
+ // used for interface initialization, and default method inheritance analysis
+ if (is_interface && !(*declares_default_methods)
+ && !method->is_abstract() && !method->is_static()) {
+ *declares_default_methods = true;
}
_methods->at_put(index, method());
}
@@ -3739,6 +3739,7 @@
JvmtiCachedClassFileData *cached_class_file = NULL;
Handle class_loader(THREAD, loader_data->class_loader());
bool has_default_methods = false;
+ bool declares_default_methods = false;
ResourceMark rm(THREAD);
ClassFileStream* cfs = stream();
@@ -3976,9 +3977,13 @@
Array<Method*>* methods = parse_methods(access_flags.is_interface(),
&promoted_flags,
&has_final_method,
- &has_default_methods,
+ &declares_default_methods,
CHECK_(nullHandle));
+ if (declares_default_methods) {
+ has_default_methods = true;
+ }
+
// Additional attributes
ClassAnnotationCollector parsed_annotations;
parse_classfile_attributes(&parsed_annotations, CHECK_(nullHandle));
@@ -4120,6 +4125,7 @@
this_klass->set_minor_version(minor_version);
this_klass->set_major_version(major_version);
this_klass->set_has_default_methods(has_default_methods);
+ this_klass->set_declares_default_methods(declares_default_methods);
if (!host_klass.is_null()) {
assert (this_klass->is_anonymous(), "should be the same");
--- a/hotspot/src/share/vm/classfile/classFileParser.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/classfile/classFileParser.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -247,7 +247,7 @@
Array<Method*>* parse_methods(bool is_interface,
AccessFlags* promoted_flags,
bool* has_final_method,
- bool* has_default_method,
+ bool* declares_default_methods,
TRAPS);
intArray* sort_methods(Array<Method*>* methods);
--- a/hotspot/src/share/vm/memory/metaspace.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/memory/metaspace.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -3157,6 +3157,16 @@
SharedMiscDataSize = align_size_up(SharedMiscDataSize, max_alignment);
SharedMiscCodeSize = align_size_up(SharedMiscCodeSize, max_alignment);
+ // the min_misc_code_size estimate is based on MetaspaceShared::generate_vtable_methods()
+ uintx min_misc_code_size = align_size_up(
+ (MetaspaceShared::num_virtuals * MetaspaceShared::vtbl_list_size) *
+ (sizeof(void*) + MetaspaceShared::vtbl_method_size) + MetaspaceShared::vtbl_common_code_size,
+ max_alignment);
+
+ if (SharedMiscCodeSize < min_misc_code_size) {
+ report_out_of_shared_space(SharedMiscCode);
+ }
+
// Initialize with the sum of the shared space sizes. The read-only
// and read write metaspace chunks will be allocated out of this and the
// remainder is the misc code and data chunks.
--- a/hotspot/src/share/vm/memory/metaspaceShared.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/memory/metaspaceShared.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -57,11 +57,16 @@
static bool _archive_loading_failed;
public:
enum {
- vtbl_list_size = 17, // number of entries in the shared space vtable list.
- num_virtuals = 200 // maximum number of virtual functions
- // If virtual functions are added to Metadata,
- // this number needs to be increased. Also,
- // SharedMiscCodeSize will need to be increased.
+ vtbl_list_size = 17, // number of entries in the shared space vtable list.
+ num_virtuals = 200, // maximum number of virtual functions
+ // If virtual functions are added to Metadata,
+ // this number needs to be increased. Also,
+ // SharedMiscCodeSize will need to be increased.
+ // The following 2 sizes were based on
+ // MetaspaceShared::generate_vtable_methods()
+ vtbl_method_size = 16, // conservative size of the mov1 and jmp instructions
+ // for the x64 platform
+ vtbl_common_code_size = (1*K) // conservative size of the "common_code" for the x64 platform
};
enum {
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -736,6 +736,41 @@
}
}
+// Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
+void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) {
+ if (this_k->has_default_methods()) {
+ for (int i = 0; i < this_k->local_interfaces()->length(); ++i) {
+ Klass* iface = this_k->local_interfaces()->at(i);
+ InstanceKlass* ik = InstanceKlass::cast(iface);
+ if (ik->should_be_initialized()) {
+ if (ik->has_default_methods()) {
+ ik->initialize_super_interfaces(ik, THREAD);
+ }
+ // Only initialize() interfaces that "declare" concrete methods.
+ // has_default_methods drives searching superinterfaces since it
+ // means has_default_methods in its superinterface hierarchy
+ if (!HAS_PENDING_EXCEPTION && ik->declares_default_methods()) {
+ ik->initialize(THREAD);
+ }
+ if (HAS_PENDING_EXCEPTION) {
+ Handle e(THREAD, PENDING_EXCEPTION);
+ CLEAR_PENDING_EXCEPTION;
+ {
+ EXCEPTION_MARK;
+ // Locks object, set state, and notify all waiting threads
+ this_k->set_initialization_state_and_notify(
+ initialization_error, THREAD);
+
+ // ignore any exception thrown, superclass initialization error is
+ // thrown below
+ CLEAR_PENDING_EXCEPTION;
+ }
+ THROW_OOP(e());
+ }
+ }
+ }
+ }
+}
void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) {
// Make sure klass is linked (verified) before initialization
@@ -815,33 +850,11 @@
}
}
+ // Recursively initialize any superinterfaces that declare default methods
+ // Only need to recurse if has_default_methods which includes declaring and
+ // inheriting default methods
if (this_k->has_default_methods()) {
- // Step 7.5: initialize any interfaces which have default methods
- for (int i = 0; i < this_k->local_interfaces()->length(); ++i) {
- Klass* iface = this_k->local_interfaces()->at(i);
- InstanceKlass* ik = InstanceKlass::cast(iface);
- if (ik->has_default_methods() && ik->should_be_initialized()) {
- ik->initialize(THREAD);
-
- if (HAS_PENDING_EXCEPTION) {
- Handle e(THREAD, PENDING_EXCEPTION);
- CLEAR_PENDING_EXCEPTION;
- {
- EXCEPTION_MARK;
- // Locks object, set state, and notify all waiting threads
- this_k->set_initialization_state_and_notify(
- initialization_error, THREAD);
-
- // ignore any exception thrown, superclass initialization error is
- // thrown below
- CLEAR_PENDING_EXCEPTION;
- }
- DTRACE_CLASSINIT_PROBE_WAIT(
- super__failed, InstanceKlass::cast(this_k()), -1, wait);
- THROW_OOP(e());
- }
- }
- }
+ this_k->initialize_super_interfaces(this_k, CHECK);
}
// Step 8
--- a/hotspot/src/share/vm/oops/instanceKlass.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/oops/instanceKlass.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -199,13 +199,14 @@
bool _has_unloaded_dependent;
enum {
- _misc_rewritten = 1 << 0, // methods rewritten.
- _misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops
- _misc_should_verify_class = 1 << 2, // allow caching of preverification
- _misc_is_anonymous = 1 << 3, // has embedded _host_klass field
- _misc_is_contended = 1 << 4, // marked with contended annotation
- _misc_has_default_methods = 1 << 5, // class/superclass/implemented interfaces has default methods
- _misc_has_been_redefined = 1 << 6 // class has been redefined
+ _misc_rewritten = 1 << 0, // methods rewritten.
+ _misc_has_nonstatic_fields = 1 << 1, // for sizing with UseCompressedOops
+ _misc_should_verify_class = 1 << 2, // allow caching of preverification
+ _misc_is_anonymous = 1 << 3, // has embedded _host_klass field
+ _misc_is_contended = 1 << 4, // marked with contended annotation
+ _misc_has_default_methods = 1 << 5, // class/superclass/implemented interfaces has default methods
+ _misc_declares_default_methods = 1 << 6, // directly declares default methods (any access)
+ _misc_has_been_redefined = 1 << 7 // class has been redefined
};
u2 _misc_flags;
u2 _minor_version; // minor version number of class file
@@ -651,6 +652,17 @@
}
}
+ bool declares_default_methods() const {
+ return (_misc_flags & _misc_declares_default_methods) != 0;
+ }
+ void set_declares_default_methods(bool b) {
+ if (b) {
+ _misc_flags |= _misc_declares_default_methods;
+ } else {
+ _misc_flags &= ~_misc_declares_default_methods;
+ }
+ }
+
// for adding methods, ConstMethod::UNSET_IDNUM means no more ids available
inline u2 next_method_idnum();
void set_initial_method_idnum(u2 value) { _idnum_allocated_count = value; }
@@ -1022,6 +1034,7 @@
static bool link_class_impl (instanceKlassHandle this_k, bool throw_verifyerror, TRAPS);
static bool verify_code (instanceKlassHandle this_k, bool throw_verifyerror, TRAPS);
static void initialize_impl (instanceKlassHandle this_k, TRAPS);
+ static void initialize_super_interfaces (instanceKlassHandle this_k, TRAPS);
static void eager_initialize_impl (instanceKlassHandle this_k);
static void set_initialization_state_and_notify_impl (instanceKlassHandle this_k, ClassState state, TRAPS);
static void call_class_initializer_impl (instanceKlassHandle this_k, TRAPS);
--- a/hotspot/src/share/vm/prims/jvm.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/prims/jvm.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -3271,8 +3271,10 @@
THROW_0(vmSymbols::java_lang_NullPointerException());
}
oop a = JNIHandles::resolve_non_null(arr);
- if (!a->is_array() || (type_array_only && !a->is_typeArray())) {
+ if (!a->is_array()) {
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array");
+ } else if (type_array_only && !a->is_typeArray()) {
+ THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array of primitive type");
}
return arrayOop(a);
}
--- a/hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -41,6 +41,7 @@
void JvmtiClassFileReconstituter::write_field_infos() {
HandleMark hm(thread());
Array<AnnotationArray*>* fields_anno = ikh()->fields_annotations();
+ Array<AnnotationArray*>* fields_type_anno = ikh()->fields_type_annotations();
// Compute the real number of Java fields
int java_fields = ikh()->java_fields_count();
@@ -55,6 +56,7 @@
// int offset = ikh()->field_offset( index );
int generic_signature_index = fs.generic_signature_index();
AnnotationArray* anno = fields_anno == NULL ? NULL : fields_anno->at(fs.index());
+ AnnotationArray* type_anno = fields_type_anno == NULL ? NULL : fields_type_anno->at(fs.index());
// JVMSpec| field_info {
// JVMSpec| u2 access_flags;
@@ -80,6 +82,9 @@
if (anno != NULL) {
++attr_count; // has RuntimeVisibleAnnotations attribute
}
+ if (type_anno != NULL) {
+ ++attr_count; // has RuntimeVisibleTypeAnnotations attribute
+ }
write_u2(attr_count);
@@ -97,6 +102,9 @@
if (anno != NULL) {
write_annotations_attribute("RuntimeVisibleAnnotations", anno);
}
+ if (type_anno != NULL) {
+ write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
+ }
}
}
@@ -537,6 +545,7 @@
AnnotationArray* anno = method->annotations();
AnnotationArray* param_anno = method->parameter_annotations();
AnnotationArray* default_anno = method->annotation_default();
+ AnnotationArray* type_anno = method->type_annotations();
// skip generated default interface methods
if (method->is_overpass()) {
@@ -572,6 +581,9 @@
if (param_anno != NULL) {
++attr_count; // has RuntimeVisibleParameterAnnotations attribute
}
+ if (type_anno != NULL) {
+ ++attr_count; // has RuntimeVisibleTypeAnnotations attribute
+ }
write_u2(attr_count);
if (const_method->code_size() > 0) {
@@ -596,6 +608,9 @@
if (param_anno != NULL) {
write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno);
}
+ if (type_anno != NULL) {
+ write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
+ }
}
// Write the class attributes portion of ClassFile structure
@@ -605,6 +620,7 @@
u2 inner_classes_length = inner_classes_attribute_length();
Symbol* generic_signature = ikh()->generic_signature();
AnnotationArray* anno = ikh()->class_annotations();
+ AnnotationArray* type_anno = ikh()->class_type_annotations();
int attr_count = 0;
if (generic_signature != NULL) {
@@ -622,6 +638,9 @@
if (anno != NULL) {
++attr_count; // has RuntimeVisibleAnnotations attribute
}
+ if (type_anno != NULL) {
+ ++attr_count; // has RuntimeVisibleTypeAnnotations attribute
+ }
if (cpool()->operands() != NULL) {
++attr_count;
}
@@ -643,6 +662,9 @@
if (anno != NULL) {
write_annotations_attribute("RuntimeVisibleAnnotations", anno);
}
+ if (type_anno != NULL) {
+ write_annotations_attribute("RuntimeVisibleTypeAnnotations", type_anno);
+ }
if (cpool()->operands() != NULL) {
write_bootstrapmethod_attribute();
}
--- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -1569,6 +1569,29 @@
return false;
}
+ // rewrite constant pool references in the class_type_annotations:
+ if (!rewrite_cp_refs_in_class_type_annotations(scratch_class, THREAD)) {
+ // propagate failure back to caller
+ return false;
+ }
+
+ // rewrite constant pool references in the fields_type_annotations:
+ if (!rewrite_cp_refs_in_fields_type_annotations(scratch_class, THREAD)) {
+ // propagate failure back to caller
+ return false;
+ }
+
+ // rewrite constant pool references in the methods_type_annotations:
+ if (!rewrite_cp_refs_in_methods_type_annotations(scratch_class, THREAD)) {
+ // propagate failure back to caller
+ return false;
+ }
+
+ // There can be type annotations in the Code part of a method_info attribute.
+ // These annotations are not accessible, even by reflection.
+ // Currently they are not even parsed by the ClassFileParser.
+ // If runtime access is added they will also need to be rewritten.
+
// rewrite source file name index:
u2 source_file_name_idx = scratch_class->source_file_name_index();
if (source_file_name_idx != 0) {
@@ -2239,6 +2262,588 @@
} // end rewrite_cp_refs_in_methods_default_annotations()
+// Rewrite constant pool references in a class_type_annotations field.
+bool VM_RedefineClasses::rewrite_cp_refs_in_class_type_annotations(
+ instanceKlassHandle scratch_class, TRAPS) {
+
+ AnnotationArray* class_type_annotations = scratch_class->class_type_annotations();
+ if (class_type_annotations == NULL || class_type_annotations->length() == 0) {
+ // no class_type_annotations so nothing to do
+ return true;
+ }
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("class_type_annotations length=%d", class_type_annotations->length()));
+
+ int byte_i = 0; // byte index into class_type_annotations
+ return rewrite_cp_refs_in_type_annotations_typeArray(class_type_annotations,
+ byte_i, "ClassFile", THREAD);
+} // end rewrite_cp_refs_in_class_type_annotations()
+
+
+// Rewrite constant pool references in a fields_type_annotations field.
+bool VM_RedefineClasses::rewrite_cp_refs_in_fields_type_annotations(
+ instanceKlassHandle scratch_class, TRAPS) {
+
+ Array<AnnotationArray*>* fields_type_annotations = scratch_class->fields_type_annotations();
+ if (fields_type_annotations == NULL || fields_type_annotations->length() == 0) {
+ // no fields_type_annotations so nothing to do
+ return true;
+ }
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("fields_type_annotations length=%d", fields_type_annotations->length()));
+
+ for (int i = 0; i < fields_type_annotations->length(); i++) {
+ AnnotationArray* field_type_annotations = fields_type_annotations->at(i);
+ if (field_type_annotations == NULL || field_type_annotations->length() == 0) {
+ // this field does not have any annotations so skip it
+ continue;
+ }
+
+ int byte_i = 0; // byte index into field_type_annotations
+ if (!rewrite_cp_refs_in_type_annotations_typeArray(field_type_annotations,
+ byte_i, "field_info", THREAD)) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("bad field_type_annotations at %d", i));
+ // propagate failure back to caller
+ return false;
+ }
+ }
+
+ return true;
+} // end rewrite_cp_refs_in_fields_type_annotations()
+
+
+// Rewrite constant pool references in a methods_type_annotations field.
+bool VM_RedefineClasses::rewrite_cp_refs_in_methods_type_annotations(
+ instanceKlassHandle scratch_class, TRAPS) {
+
+ for (int i = 0; i < scratch_class->methods()->length(); i++) {
+ Method* m = scratch_class->methods()->at(i);
+ AnnotationArray* method_type_annotations = m->constMethod()->type_annotations();
+
+ if (method_type_annotations == NULL || method_type_annotations->length() == 0) {
+ // this method does not have any annotations so skip it
+ continue;
+ }
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("methods type_annotations length=%d", method_type_annotations->length()));
+
+ int byte_i = 0; // byte index into method_type_annotations
+ if (!rewrite_cp_refs_in_type_annotations_typeArray(method_type_annotations,
+ byte_i, "method_info", THREAD)) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("bad method_type_annotations at %d", i));
+ // propagate failure back to caller
+ return false;
+ }
+ }
+
+ return true;
+} // end rewrite_cp_refs_in_methods_type_annotations()
+
+
+// Rewrite constant pool references in a type_annotations
+// field. This "structure" is adapted from the
+// RuntimeVisibleTypeAnnotations_attribute described in
+// section 4.7.20 of the Java SE 8 Edition of the VM spec:
+//
+// type_annotations_typeArray {
+// u2 num_annotations;
+// type_annotation annotations[num_annotations];
+// }
+//
+bool VM_RedefineClasses::rewrite_cp_refs_in_type_annotations_typeArray(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref,
+ const char * location_mesg, TRAPS) {
+
+ if ((byte_i_ref + 2) > type_annotations_typeArray->length()) {
+ // not enough room for num_annotations field
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for num_annotations field"));
+ return false;
+ }
+
+ u2 num_annotations = Bytes::get_Java_u2((address)
+ type_annotations_typeArray->adr_at(byte_i_ref));
+ byte_i_ref += 2;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("num_type_annotations=%d", num_annotations));
+
+ int calc_num_annotations = 0;
+ for (; calc_num_annotations < num_annotations; calc_num_annotations++) {
+ if (!rewrite_cp_refs_in_type_annotation_struct(type_annotations_typeArray,
+ byte_i_ref, location_mesg, THREAD)) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("bad type_annotation_struct at %d", calc_num_annotations));
+ // propagate failure back to caller
+ return false;
+ }
+ }
+ assert(num_annotations == calc_num_annotations, "sanity check");
+
+ if (byte_i_ref != type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("read wrong amount of bytes at end of processing "
+ "type_annotations_typeArray (%d of %d bytes were read)",
+ byte_i_ref, type_annotations_typeArray->length()));
+ return false;
+ }
+
+ return true;
+} // end rewrite_cp_refs_in_type_annotations_typeArray()
+
+
+// Rewrite constant pool references in a type_annotation
+// field. This "structure" is adapted from the
+// RuntimeVisibleTypeAnnotations_attribute described in
+// section 4.7.20 of the Java SE 8 Edition of the VM spec:
+//
+// type_annotation {
+// u1 target_type;
+// union {
+// type_parameter_target;
+// supertype_target;
+// type_parameter_bound_target;
+// empty_target;
+// method_formal_parameter_target;
+// throws_target;
+// localvar_target;
+// catch_target;
+// offset_target;
+// type_argument_target;
+// } target_info;
+// type_path target_path;
+// annotation anno;
+// }
+//
+bool VM_RedefineClasses::rewrite_cp_refs_in_type_annotation_struct(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref,
+ const char * location_mesg, TRAPS) {
+
+ if (!skip_type_annotation_target(type_annotations_typeArray,
+ byte_i_ref, location_mesg, THREAD)) {
+ return false;
+ }
+
+ if (!skip_type_annotation_type_path(type_annotations_typeArray,
+ byte_i_ref, THREAD)) {
+ return false;
+ }
+
+ if (!rewrite_cp_refs_in_annotation_struct(type_annotations_typeArray,
+ byte_i_ref, THREAD)) {
+ return false;
+ }
+
+ return true;
+} // end rewrite_cp_refs_in_type_annotation_struct()
+
+
+// Read, verify and skip over the target_type and target_info part
+// so that rewriting can continue in the later parts of the struct.
+//
+// u1 target_type;
+// union {
+// type_parameter_target;
+// supertype_target;
+// type_parameter_bound_target;
+// empty_target;
+// method_formal_parameter_target;
+// throws_target;
+// localvar_target;
+// catch_target;
+// offset_target;
+// type_argument_target;
+// } target_info;
+//
+bool VM_RedefineClasses::skip_type_annotation_target(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref,
+ const char * location_mesg, TRAPS) {
+
+ if ((byte_i_ref + 1) > type_annotations_typeArray->length()) {
+ // not enough room for a target_type let alone the rest of a type_annotation
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a target_type"));
+ return false;
+ }
+
+ u1 target_type = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("target_type=0x%.2x", target_type));
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD, ("location=%s", location_mesg));
+
+ // Skip over target_info
+ switch (target_type) {
+ case 0x00:
+ // kind: type parameter declaration of generic class or interface
+ // location: ClassFile
+ case 0x01:
+ // kind: type parameter declaration of generic method or constructor
+ // location: method_info
+
+ {
+ // struct:
+ // type_parameter_target {
+ // u1 type_parameter_index;
+ // }
+ //
+ if ((byte_i_ref + 1) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a type_parameter_target"));
+ return false;
+ }
+
+ u1 type_parameter_index = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("type_parameter_target: type_parameter_index=%d",
+ type_parameter_index));
+ } break;
+
+ case 0x10:
+ // kind: type in extends clause of class or interface declaration
+ // (including the direct superclass of an anonymous class declaration),
+ // or in implements clause of interface declaration
+ // location: ClassFile
+
+ {
+ // struct:
+ // supertype_target {
+ // u2 supertype_index;
+ // }
+ //
+ if ((byte_i_ref + 2) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a supertype_target"));
+ return false;
+ }
+
+ u2 supertype_index = Bytes::get_Java_u2((address)
+ type_annotations_typeArray->adr_at(byte_i_ref));
+ byte_i_ref += 2;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("supertype_target: supertype_index=%d", supertype_index));
+ } break;
+
+ case 0x11:
+ // kind: type in bound of type parameter declaration of generic class or interface
+ // location: ClassFile
+ case 0x12:
+ // kind: type in bound of type parameter declaration of generic method or constructor
+ // location: method_info
+
+ {
+ // struct:
+ // type_parameter_bound_target {
+ // u1 type_parameter_index;
+ // u1 bound_index;
+ // }
+ //
+ if ((byte_i_ref + 2) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a type_parameter_bound_target"));
+ return false;
+ }
+
+ u1 type_parameter_index = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+ u1 bound_index = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("type_parameter_bound_target: type_parameter_index=%d, bound_index=%d",
+ type_parameter_index, bound_index));
+ } break;
+
+ case 0x13:
+ // kind: type in field declaration
+ // location: field_info
+ case 0x14:
+ // kind: return type of method, or type of newly constructed object
+ // location: method_info
+ case 0x15:
+ // kind: receiver type of method or constructor
+ // location: method_info
+
+ {
+ // struct:
+ // empty_target {
+ // }
+ //
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("empty_target"));
+ } break;
+
+ case 0x16:
+ // kind: type in formal parameter declaration of method, constructor, or lambda expression
+ // location: method_info
+
+ {
+ // struct:
+ // formal_parameter_target {
+ // u1 formal_parameter_index;
+ // }
+ //
+ if ((byte_i_ref + 1) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a formal_parameter_target"));
+ return false;
+ }
+
+ u1 formal_parameter_index = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("formal_parameter_target: formal_parameter_index=%d",
+ formal_parameter_index));
+ } break;
+
+ case 0x17:
+ // kind: type in throws clause of method or constructor
+ // location: method_info
+
+ {
+ // struct:
+ // throws_target {
+ // u2 throws_type_index
+ // }
+ //
+ if ((byte_i_ref + 2) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a throws_target"));
+ return false;
+ }
+
+ u2 throws_type_index = Bytes::get_Java_u2((address)
+ type_annotations_typeArray->adr_at(byte_i_ref));
+ byte_i_ref += 2;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("throws_target: throws_type_index=%d", throws_type_index));
+ } break;
+
+ case 0x40:
+ // kind: type in local variable declaration
+ // location: Code
+ case 0x41:
+ // kind: type in resource variable declaration
+ // location: Code
+
+ {
+ // struct:
+ // localvar_target {
+ // u2 table_length;
+ // struct {
+ // u2 start_pc;
+ // u2 length;
+ // u2 index;
+ // } table[table_length];
+ // }
+ //
+ if ((byte_i_ref + 2) > type_annotations_typeArray->length()) {
+ // not enough room for a table_length let alone the rest of a localvar_target
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a localvar_target table_length"));
+ return false;
+ }
+
+ u2 table_length = Bytes::get_Java_u2((address)
+ type_annotations_typeArray->adr_at(byte_i_ref));
+ byte_i_ref += 2;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("localvar_target: table_length=%d", table_length));
+
+ int table_struct_size = 2 + 2 + 2; // 3 u2 variables per table entry
+ int table_size = table_length * table_struct_size;
+
+ if ((byte_i_ref + table_size) > type_annotations_typeArray->length()) {
+ // not enough room for a table
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a table array of length %d", table_length));
+ return false;
+ }
+
+ // Skip over table
+ byte_i_ref += table_size;
+ } break;
+
+ case 0x42:
+ // kind: type in exception parameter declaration
+ // location: Code
+
+ {
+ // struct:
+ // catch_target {
+ // u2 exception_table_index;
+ // }
+ //
+ if ((byte_i_ref + 2) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a catch_target"));
+ return false;
+ }
+
+ u2 exception_table_index = Bytes::get_Java_u2((address)
+ type_annotations_typeArray->adr_at(byte_i_ref));
+ byte_i_ref += 2;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("catch_target: exception_table_index=%d", exception_table_index));
+ } break;
+
+ case 0x43:
+ // kind: type in instanceof expression
+ // location: Code
+ case 0x44:
+ // kind: type in new expression
+ // location: Code
+ case 0x45:
+ // kind: type in method reference expression using ::new
+ // location: Code
+ case 0x46:
+ // kind: type in method reference expression using ::Identifier
+ // location: Code
+
+ {
+ // struct:
+ // offset_target {
+ // u2 offset;
+ // }
+ //
+ if ((byte_i_ref + 2) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a offset_target"));
+ return false;
+ }
+
+ u2 offset = Bytes::get_Java_u2((address)
+ type_annotations_typeArray->adr_at(byte_i_ref));
+ byte_i_ref += 2;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("offset_target: offset=%d", offset));
+ } break;
+
+ case 0x47:
+ // kind: type in cast expression
+ // location: Code
+ case 0x48:
+ // kind: type argument for generic constructor in new expression or
+ // explicit constructor invocation statement
+ // location: Code
+ case 0x49:
+ // kind: type argument for generic method in method invocation expression
+ // location: Code
+ case 0x4A:
+ // kind: type argument for generic constructor in method reference expression using ::new
+ // location: Code
+ case 0x4B:
+ // kind: type argument for generic method in method reference expression using ::Identifier
+ // location: Code
+
+ {
+ // struct:
+ // type_argument_target {
+ // u2 offset;
+ // u1 type_argument_index;
+ // }
+ //
+ if ((byte_i_ref + 3) > type_annotations_typeArray->length()) {
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a type_argument_target"));
+ return false;
+ }
+
+ u2 offset = Bytes::get_Java_u2((address)
+ type_annotations_typeArray->adr_at(byte_i_ref));
+ byte_i_ref += 2;
+ u1 type_argument_index = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("type_argument_target: offset=%d, type_argument_index=%d",
+ offset, type_argument_index));
+ } break;
+
+ default:
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("unknown target_type"));
+#ifdef ASSERT
+ ShouldNotReachHere();
+#endif
+ return false;
+ }
+
+ return true;
+} // end skip_type_annotation_target()
+
+
+// Read, verify and skip over the type_path part so that rewriting
+// can continue in the later parts of the struct.
+//
+// type_path {
+// u1 path_length;
+// {
+// u1 type_path_kind;
+// u1 type_argument_index;
+// } path[path_length];
+// }
+//
+bool VM_RedefineClasses::skip_type_annotation_type_path(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref, TRAPS) {
+
+ if ((byte_i_ref + 1) > type_annotations_typeArray->length()) {
+ // not enough room for a path_length let alone the rest of the type_path
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for a type_path"));
+ return false;
+ }
+
+ u1 path_length = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("type_path: path_length=%d", path_length));
+
+ int calc_path_length = 0;
+ for (; calc_path_length < path_length; calc_path_length++) {
+ if ((byte_i_ref + 1 + 1) > type_annotations_typeArray->length()) {
+ // not enough room for a path
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("length() is too small for path entry %d of %d",
+ calc_path_length, path_length));
+ return false;
+ }
+
+ u1 type_path_kind = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+ u1 type_argument_index = type_annotations_typeArray->at(byte_i_ref);
+ byte_i_ref += 1;
+
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("type_path: path[%d]: type_path_kind=%d, type_argument_index=%d",
+ calc_path_length, type_path_kind, type_argument_index));
+
+ if (type_path_kind > 3 || (type_path_kind != 3 && type_argument_index != 0)) {
+ // not enough room for a path
+ RC_TRACE_WITH_THREAD(0x02000000, THREAD,
+ ("inconsistent type_path values"));
+ return false;
+ }
+ }
+ assert(path_length == calc_path_length, "sanity check");
+
+ return true;
+} // end skip_type_annotation_type_path()
+
+
// Rewrite constant pool references in the method's stackmap table.
// These "structures" are adapted from the StackMapTable_attribute that
// is described in section 4.8.4 of the 6.0 version of the VM spec
@@ -3223,23 +3828,6 @@
void VM_RedefineClasses::swap_annotations(instanceKlassHandle the_class,
instanceKlassHandle scratch_class) {
- // Since there is currently no rewriting of type annotations indexes
- // into the CP, we null out type annotations on scratch_class before
- // we swap annotations with the_class rather than facing the
- // possibility of shipping annotations with broken indexes to
- // Java-land.
- ClassLoaderData* loader_data = scratch_class->class_loader_data();
- AnnotationArray* new_class_type_annotations = scratch_class->class_type_annotations();
- if (new_class_type_annotations != NULL) {
- MetadataFactory::free_array<u1>(loader_data, new_class_type_annotations);
- scratch_class->annotations()->set_class_type_annotations(NULL);
- }
- Array<AnnotationArray*>* new_field_type_annotations = scratch_class->fields_type_annotations();
- if (new_field_type_annotations != NULL) {
- Annotations::free_contents(loader_data, new_field_type_annotations);
- scratch_class->annotations()->set_fields_type_annotations(NULL);
- }
-
// Swap annotation fields values
Annotations* old_annotations = the_class->annotations();
the_class->set_annotations(scratch_class->annotations());
--- a/hotspot/src/share/vm/prims/jvmtiRedefineClasses.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/prims/jvmtiRedefineClasses.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -452,6 +452,17 @@
instanceKlassHandle scratch_class, TRAPS);
bool rewrite_cp_refs_in_element_value(
AnnotationArray* class_annotations, int &byte_i_ref, TRAPS);
+ bool rewrite_cp_refs_in_type_annotations_typeArray(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref,
+ const char * location_mesg, TRAPS);
+ bool rewrite_cp_refs_in_type_annotation_struct(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref,
+ const char * location_mesg, TRAPS);
+ bool skip_type_annotation_target(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref,
+ const char * location_mesg, TRAPS);
+ bool skip_type_annotation_type_path(
+ AnnotationArray* type_annotations_typeArray, int &byte_i_ref, TRAPS);
bool rewrite_cp_refs_in_fields_annotations(
instanceKlassHandle scratch_class, TRAPS);
void rewrite_cp_refs_in_method(methodHandle method,
@@ -463,6 +474,12 @@
instanceKlassHandle scratch_class, TRAPS);
bool rewrite_cp_refs_in_methods_parameter_annotations(
instanceKlassHandle scratch_class, TRAPS);
+ bool rewrite_cp_refs_in_class_type_annotations(
+ instanceKlassHandle scratch_class, TRAPS);
+ bool rewrite_cp_refs_in_fields_type_annotations(
+ instanceKlassHandle scratch_class, TRAPS);
+ bool rewrite_cp_refs_in_methods_type_annotations(
+ instanceKlassHandle scratch_class, TRAPS);
void rewrite_cp_refs_in_stack_map_table(methodHandle method, TRAPS);
void rewrite_cp_refs_in_verification_type_info(
address& stackmap_addr_ref, address stackmap_end, u2 frame_i,
--- a/hotspot/src/share/vm/runtime/os.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/runtime/os.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -680,28 +680,10 @@
// SocketInterface (ex HPI SocketInterface )
static int socket(int domain, int type, int protocol);
static int socket_close(int fd);
- static int socket_shutdown(int fd, int howto);
static int recv(int fd, char* buf, size_t nBytes, uint flags);
static int send(int fd, char* buf, size_t nBytes, uint flags);
static int raw_send(int fd, char* buf, size_t nBytes, uint flags);
- static int timeout(int fd, long timeout);
- static int listen(int fd, int count);
static int connect(int fd, struct sockaddr* him, socklen_t len);
- static int bind(int fd, struct sockaddr* him, socklen_t len);
- static int accept(int fd, struct sockaddr* him, socklen_t* len);
- static int recvfrom(int fd, char* buf, size_t nbytes, uint flags,
- struct sockaddr* from, socklen_t* fromlen);
- static int get_sock_name(int fd, struct sockaddr* him, socklen_t* len);
- static int sendto(int fd, char* buf, size_t len, uint flags,
- struct sockaddr* to, socklen_t tolen);
- static int socket_available(int fd, jint* pbytes);
-
- static int get_sock_opt(int fd, int level, int optname,
- char* optval, socklen_t* optlen);
- static int set_sock_opt(int fd, int level, int optname,
- const char* optval, socklen_t optlen);
- static int get_host_name(char* name, int namelen);
-
static struct hostent* get_host_by_name(char* name);
// Support for signals (see JVM_RaiseSignal, JVM_RegisterSignal)
--- a/hotspot/src/share/vm/utilities/debug.cpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/utilities/debug.cpp Mon Oct 27 15:09:23 2014 -0700
@@ -256,16 +256,18 @@
static const char* name[] = {
"shared read only space",
"shared read write space",
- "shared miscellaneous data space"
+ "shared miscellaneous data space",
+ "shared miscellaneous code space"
};
static const char* flag[] = {
"SharedReadOnlySize",
"SharedReadWriteSize",
- "SharedMiscDataSize"
+ "SharedMiscDataSize",
+ "SharedMiscCodeSize"
};
warning("\nThe %s is not large enough\n"
- "to preload requested classes. Use -XX:%s=\n"
+ "to preload requested classes. Use -XX:%s=<size>\n"
"to increase the initial size of %s.\n",
name[shared_space], flag[shared_space], name[shared_space]);
exit(2);
--- a/hotspot/src/share/vm/utilities/debug.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/utilities/debug.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -245,7 +245,8 @@
enum SharedSpaceType {
SharedReadOnly,
SharedReadWrite,
- SharedMiscData
+ SharedMiscData,
+ SharedMiscCode
};
void report_out_of_shared_space(SharedSpaceType space_type);
--- a/hotspot/src/share/vm/utilities/dtrace_disabled.hpp Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/src/share/vm/utilities/dtrace_disabled.hpp Mon Oct 27 15:09:23 2014 -0700
@@ -27,7 +27,7 @@
/* This file contains dummy provider probes needed when compiling a hotspot
* that does not support dtrace probes. This could be because we're building
- * on a system that doesn't suuport dtrace or because we're bulding a variant
+ * on a system that doesn't support dtrace or because we're bulding a variant
* of hotspot (like core) where we do not support dtrace
*/
#if !defined(DTRACE_ENABLED)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/RedefineTests/RedefineAnnotations.java Mon Oct 27 15:09:23 2014 -0700
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @library /testlibrary
+ * @summary Test that type annotations are retained after a retransform
+ * @run main RedefineAnnotations buildagent
+ * @run main/othervm -javaagent:redefineagent.jar RedefineAnnotations
+ */
+
+import static com.oracle.java.testlibrary.Asserts.assertTrue;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.lang.NoSuchFieldException;
+import java.lang.NoSuchMethodException;
+import java.lang.RuntimeException;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.instrument.ClassFileTransformer;
+import java.lang.instrument.IllegalClassFormatException;
+import java.lang.instrument.Instrumentation;
+import java.lang.instrument.UnmodifiableClassException;
+import java.lang.reflect.AnnotatedArrayType;
+import java.lang.reflect.AnnotatedParameterizedType;
+import java.lang.reflect.AnnotatedType;
+import java.lang.reflect.AnnotatedWildcardType;
+import java.lang.reflect.Executable;
+import java.lang.reflect.TypeVariable;
+import java.security.ProtectionDomain;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import jdk.internal.org.objectweb.asm.ClassReader;
+import jdk.internal.org.objectweb.asm.ClassVisitor;
+import jdk.internal.org.objectweb.asm.ClassWriter;
+import jdk.internal.org.objectweb.asm.FieldVisitor;
+import static jdk.internal.org.objectweb.asm.Opcodes.ASM5;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE_USE)
+@interface TestAnn {
+ String site();
+}
+
+public class RedefineAnnotations {
+ static Instrumentation inst;
+ public static void premain(String agentArgs, Instrumentation inst) {
+ RedefineAnnotations.inst = inst;
+ }
+
+ static class Transformer implements ClassFileTransformer {
+
+ public byte[] asm(ClassLoader loader, String className,
+ Class<?> classBeingRedefined,
+ ProtectionDomain protectionDomain, byte[] classfileBuffer)
+ throws IllegalClassFormatException {
+
+ ClassWriter cw = new ClassWriter(0);
+ ClassVisitor cv = new ReAddDummyFieldsClassVisitor(ASM5, cw) { };
+ ClassReader cr = new ClassReader(classfileBuffer);
+ cr.accept(cv, 0);
+ return cw.toByteArray();
+ }
+
+ public class ReAddDummyFieldsClassVisitor extends ClassVisitor {
+
+ LinkedList<F> fields = new LinkedList<>();
+
+ public ReAddDummyFieldsClassVisitor(int api, ClassVisitor cv) {
+ super(api, cv);
+ }
+
+ @Override public FieldVisitor visitField(int access, String name,
+ String desc, String signature, Object value) {
+ if (name.startsWith("dummy")) {
+ // Remove dummy field
+ fields.addLast(new F(access, name, desc, signature, value));
+ return null;
+ }
+ return cv.visitField(access, name, desc, signature, value);
+ }
+
+ @Override public void visitEnd() {
+ F f;
+ while ((f = fields.pollFirst()) != null) {
+ // Re-add dummy fields
+ cv.visitField(f.access, f.name, f.desc, f.signature, f.value);
+ }
+ }
+
+ private class F {
+ private int access;
+ private String name;
+ private String desc;
+ private String signature;
+ private Object value;
+ F(int access, String name, String desc, String signature, Object value) {
+ this.access = access;
+ this.name = name;
+ this.desc = desc;
+ this.signature = signature;
+ this.value = value;
+ }
+ }
+ }
+
+ @Override public byte[] transform(ClassLoader loader, String className,
+ Class<?> classBeingRedefined,
+ ProtectionDomain protectionDomain, byte[] classfileBuffer)
+ throws IllegalClassFormatException {
+
+ if (className.contains("TypeAnnotatedTestClass")) {
+ try {
+ // Here we remove and re-add the dummy fields. This shuffles the constant pool
+ return asm(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
+ } catch (Throwable e) {
+ // The retransform native code that called this method does not propagate
+ // exceptions. Instead of getting an uninformative generic error, catch
+ // problems here and print it, then exit.
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+ return null;
+ }
+ }
+
+ private static void buildAgent() {
+ try {
+ ClassFileInstaller.main("RedefineAnnotations");
+ } catch (Exception e) {
+ throw new RuntimeException("Could not write agent classfile", e);
+ }
+
+ try {
+ PrintWriter pw = new PrintWriter("MANIFEST.MF");
+ pw.println("Premain-Class: RedefineAnnotations");
+ pw.println("Agent-Class: RedefineAnnotations");
+ pw.println("Can-Retransform-Classes: true");
+ pw.close();
+ } catch (FileNotFoundException e) {
+ throw new RuntimeException("Could not write manifest file for the agent", e);
+ }
+
+ sun.tools.jar.Main jarTool = new sun.tools.jar.Main(System.out, System.err, "jar");
+ if (!jarTool.run(new String[] { "-cmf", "MANIFEST.MF", "redefineagent.jar", "RedefineAnnotations.class" })) {
+ throw new RuntimeException("Could not write the agent jar file");
+ }
+ }
+
+ public static void main(String argv[]) throws NoSuchFieldException, NoSuchMethodException {
+ if (argv.length == 1 && argv[0].equals("buildagent")) {
+ buildAgent();
+ return;
+ }
+
+ if (inst == null) {
+ throw new RuntimeException("Instrumentation object was null");
+ }
+
+ RedefineAnnotations test = new RedefineAnnotations();
+ test.testTransformAndVerify();
+ }
+
+ // Class type annotations
+ private Annotation classTypeParameterTA;
+ private Annotation extendsTA;
+ private Annotation implementsTA;
+
+ // Field type annotations
+ private Annotation fieldTA;
+ private Annotation innerTA;
+ private Annotation[] arrayTA = new Annotation[4];
+ private Annotation[] mapTA = new Annotation[5];
+
+ // Method type annotations
+ private Annotation returnTA, methodTypeParameterTA, formalParameterTA, throwsTA;
+
+ private void testTransformAndVerify()
+ throws NoSuchFieldException, NoSuchMethodException {
+
+ Class<TypeAnnotatedTestClass> c = TypeAnnotatedTestClass.class;
+ Class<?> myClass = c;
+
+ /*
+ * Verify that the expected annotations are where they should be before transform.
+ */
+ verifyClassTypeAnnotations(c);
+ verifyFieldTypeAnnotations(c);
+ verifyMethodTypeAnnotations(c);
+
+ try {
+ inst.addTransformer(new Transformer(), true);
+ inst.retransformClasses(myClass);
+ } catch (UnmodifiableClassException e) {
+ throw new RuntimeException(e);
+ }
+
+ /*
+ * Verify that the expected annotations are where they should be after transform.
+ * Also verify that before and after are equal.
+ */
+ verifyClassTypeAnnotations(c);
+ verifyFieldTypeAnnotations(c);
+ verifyMethodTypeAnnotations(c);
+ }
+
+ private void verifyClassTypeAnnotations(Class c) {
+ Annotation anno;
+
+ anno = c.getTypeParameters()[0].getAnnotations()[0];
+ verifyTestAnn(classTypeParameterTA, anno, "classTypeParameter");
+ classTypeParameterTA = anno;
+
+ anno = c.getAnnotatedSuperclass().getAnnotations()[0];
+ verifyTestAnn(extendsTA, anno, "extends");
+ extendsTA = anno;
+
+ anno = c.getAnnotatedInterfaces()[0].getAnnotations()[0];
+ verifyTestAnn(implementsTA, anno, "implements");
+ implementsTA = anno;
+ }
+
+ private void verifyFieldTypeAnnotations(Class c)
+ throws NoSuchFieldException, NoSuchMethodException {
+
+ verifyBasicFieldTypeAnnotations(c);
+ verifyInnerFieldTypeAnnotations(c);
+ verifyArrayFieldTypeAnnotations(c);
+ verifyMapFieldTypeAnnotations(c);
+ }
+
+ private void verifyBasicFieldTypeAnnotations(Class c)
+ throws NoSuchFieldException, NoSuchMethodException {
+
+ Annotation anno = c.getDeclaredField("typeAnnotatedBoolean").getAnnotatedType().getAnnotations()[0];
+ verifyTestAnn(fieldTA, anno, "field");
+ fieldTA = anno;
+ }
+
+ private void verifyInnerFieldTypeAnnotations(Class c)
+ throws NoSuchFieldException, NoSuchMethodException {
+
+ AnnotatedType at = c.getDeclaredField("typeAnnotatedInner").getAnnotatedType();
+ Annotation anno = at.getAnnotations()[0];
+ verifyTestAnn(innerTA, anno, "inner");
+ innerTA = anno;
+ }
+
+ private void verifyArrayFieldTypeAnnotations(Class c)
+ throws NoSuchFieldException, NoSuchMethodException {
+
+ Annotation anno;
+ AnnotatedType at;
+
+ at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType();
+ anno = at.getAnnotations()[0];
+ verifyTestAnn(arrayTA[0], anno, "array1");
+ arrayTA[0] = anno;
+
+ for (int i = 1; i <= 3; i++) {
+ at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType();
+ anno = at.getAnnotations()[0];
+ verifyTestAnn(arrayTA[i], anno, "array" + (i + 1));
+ arrayTA[i] = anno;
+ }
+ }
+
+ private void verifyMapFieldTypeAnnotations(Class c)
+ throws NoSuchFieldException, NoSuchMethodException {
+
+ Annotation anno;
+ AnnotatedType atBase;
+ AnnotatedType atParameter;
+ atBase = c.getDeclaredField("typeAnnotatedMap").getAnnotatedType();
+
+ anno = atBase.getAnnotations()[0];
+ verifyTestAnn(mapTA[0], anno, "map1");
+ mapTA[0] = anno;
+
+ atParameter =
+ ((AnnotatedParameterizedType) atBase).
+ getAnnotatedActualTypeArguments()[0];
+ anno = ((AnnotatedWildcardType) atParameter).getAnnotations()[0];
+ verifyTestAnn(mapTA[1], anno, "map2");
+ mapTA[1] = anno;
+
+ anno =
+ ((AnnotatedWildcardType) atParameter).
+ getAnnotatedUpperBounds()[0].getAnnotations()[0];
+ verifyTestAnn(mapTA[2], anno, "map3");
+ mapTA[2] = anno;
+
+ atParameter =
+ ((AnnotatedParameterizedType) atBase).
+ getAnnotatedActualTypeArguments()[1];
+ anno = ((AnnotatedParameterizedType) atParameter).getAnnotations()[0];
+ verifyTestAnn(mapTA[3], anno, "map4");
+ mapTA[3] = anno;
+
+ anno =
+ ((AnnotatedParameterizedType) atParameter).
+ getAnnotatedActualTypeArguments()[0].getAnnotations()[0];
+ verifyTestAnn(mapTA[4], anno, "map5");
+ mapTA[4] = anno;
+ }
+
+ private void verifyMethodTypeAnnotations(Class c)
+ throws NoSuchFieldException, NoSuchMethodException {
+ Annotation anno;
+ Executable typeAnnotatedMethod =
+ c.getDeclaredMethod("typeAnnotatedMethod", TypeAnnotatedTestClass.class);
+
+ anno = typeAnnotatedMethod.getAnnotatedReturnType().getAnnotations()[0];
+ verifyTestAnn(returnTA, anno, "return");
+ returnTA = anno;
+
+ anno = typeAnnotatedMethod.getTypeParameters()[0].getAnnotations()[0];
+ verifyTestAnn(methodTypeParameterTA, anno, "methodTypeParameter");
+ methodTypeParameterTA = anno;
+
+ anno = typeAnnotatedMethod.getAnnotatedParameterTypes()[0].getAnnotations()[0];
+ verifyTestAnn(formalParameterTA, anno, "formalParameter");
+ formalParameterTA = anno;
+
+ anno = typeAnnotatedMethod.getAnnotatedExceptionTypes()[0].getAnnotations()[0];
+ verifyTestAnn(throwsTA, anno, "throws");
+ throwsTA = anno;
+ }
+
+ private static void verifyTestAnn(Annotation verifyAgainst, Annotation anno, String expectedSite) {
+ verifyTestAnnSite(anno, expectedSite);
+
+ // When called before transform verifyAgainst will be null, when called
+ // after transform it will be the annotation from before the transform
+ if (verifyAgainst != null) {
+ assertTrue(anno.equals(verifyAgainst),
+ "Annotations do not match before and after." +
+ " Before: \"" + verifyAgainst + "\", After: \"" + anno + "\"");
+ }
+ }
+
+ private static void verifyTestAnnSite(Annotation testAnn, String expectedSite) {
+ String expectedAnn = "@TestAnn(site=" + expectedSite + ")";
+ assertTrue(testAnn.toString().equals(expectedAnn),
+ "Expected \"" + expectedAnn + "\", got \"" + testAnn + "\"");
+ }
+
+ public static class TypeAnnotatedTestClass <@TestAnn(site="classTypeParameter") S,T>
+ extends @TestAnn(site="extends") Thread
+ implements @TestAnn(site="implements") Runnable {
+
+ public @TestAnn(site="field") boolean typeAnnotatedBoolean;
+
+ public
+ RedefineAnnotations.
+ @TestAnn(site="inner") TypeAnnotatedTestClass
+ typeAnnotatedInner;
+
+ public
+ @TestAnn(site="array4") boolean
+ @TestAnn(site="array1") []
+ @TestAnn(site="array2") []
+ @TestAnn(site="array3") []
+ typeAnnotatedArray;
+
+ public @TestAnn(site="map1") Map
+ <@TestAnn(site="map2") ? extends @TestAnn(site="map3") String,
+ @TestAnn(site="map4") List<@TestAnn(site="map5") Object>> typeAnnotatedMap;
+
+ public int dummy1;
+ public int dummy2;
+ public int dummy3;
+
+ @TestAnn(site="return") <@TestAnn(site="methodTypeParameter") U,V> Class
+ typeAnnotatedMethod(@TestAnn(site="formalParameter") TypeAnnotatedTestClass arg)
+ throws @TestAnn(site="throws") ClassNotFoundException {
+
+ @TestAnn(site="local_variable_type") int foo = 0;
+ throw new ClassNotFoundException();
+ }
+
+ public void run() {}
+ }
+}
--- a/hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/test/runtime/SharedArchiveFile/LimitSharedSizes.java Mon Oct 27 15:09:23 2014 -0700
@@ -51,9 +51,12 @@
// Known issue, JDK-8038422 (assert() on Windows)
// new SharedSizeTestData("-XX:SharedMiscDataSize", "500k", "miscellaneous data"),
- // This will cause a VM crash; commenting out for now; see bug JDK-8038268
- // @ignore JDK-8038268
- // new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"),
+ // Too small of a misc code size should not cause a vm crash.
+ // It should result in the following error message:
+ // The shared miscellaneous code space is not large enough
+ // to preload requested classes. Use -XX:SharedMiscCodeSize=
+ // to increase the initial size of shared miscellaneous code space.
+ new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"),
// these values are larger than default ones, but should
// be acceptable and not cause failure
--- a/hotspot/test/runtime/lambda-features/InvokespecialInterface.java Mon Oct 27 07:49:54 2014 -0700
+++ b/hotspot/test/runtime/lambda-features/InvokespecialInterface.java Mon Oct 27 15:09:23 2014 -0700
@@ -33,11 +33,12 @@
import java.util.function.*;
import java.util.*;
+public class InvokespecialInterface {
interface I {
default void imethod() { System.out.println("I::imethod"); }
}
-class C implements I {
+static class C implements I {
public void foo() { I.super.imethod(); } // invokespecial InterfaceMethod
public void bar() { I i = this; i.imethod(); } // invokeinterface same
public void doSomeInvokedynamic() {
@@ -48,7 +49,6 @@
}
}
-public class InvokespecialInterface {
public static void main(java.lang.String[] unused) {
// need to create C and call I::foo()
C c = new C();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/lambda-features/TestInterfaceInit.java Mon Oct 27 15:09:23 2014 -0700
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @bug 8034275
+ * @summary [JDK 8u40] Test interface initialization: only for interfaces declaring default methods
+ * @run main TestInterfaceInit
+ */
+import java.util.List;
+import java.util.Arrays;
+import java.util.ArrayList;
+
+public class TestInterfaceInit {
+
+ static List<Class<?>> cInitOrder = new ArrayList<>();
+
+ // Declares a default method and initializes
+ interface I {
+ boolean v = TestInterfaceInit.out(I.class);
+ default void x() {}
+ }
+
+ // Declares a default method and initializes
+ interface J extends I {
+ boolean v = TestInterfaceInit.out(J.class);
+ default void x() {}
+ }
+ // No default method, does not initialize
+ interface JN extends J {
+ boolean v = TestInterfaceInit.out(JN.class);
+ }
+
+ // Declares a default method and initializes
+ interface K extends I {
+ boolean v = TestInterfaceInit.out(K.class);
+ default void x() {}
+ }
+
+ // No default method, does not initialize
+ interface KN extends K {
+ boolean v = TestInterfaceInit.out(KN.class);
+ }
+
+ interface L extends JN, KN {
+ boolean v = TestInterfaceInit.out(L.class);
+ default void x() {}
+ }
+
+ public static void main(String[] args) {
+ // Trigger initialization
+ boolean v = L.v;
+
+ List<Class<?>> expectedCInitOrder = Arrays.asList(I.class,J.class,K.class,L.class);
+ if (!cInitOrder.equals(expectedCInitOrder)) {
+ throw new RuntimeException(String.format("Class initialization array %s not equal to expected array %s", cInitOrder, expectedCInitOrder));
+ }
+ }
+
+ static boolean out(Class c) {
+ System.out.println("#: initializing " + c.getName());
+ cInitOrder.add(c);
+ return true;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/lambda-features/TestInterfaceOrder.java Mon Oct 27 15:09:23 2014 -0700
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ *
+ */
+
+/*
+ * @test
+ * @bug 8034275
+ * @summary [JDK 8u40] Test interface initialization order
+ * @run main TestInterfaceOrder
+ */
+
+import java.util.List;
+import java.util.Arrays;
+import java.util.ArrayList;
+
+public class TestInterfaceOrder {
+ static List<Class<?>> cInitOrder = new ArrayList<>();
+
+ public static void main(java.lang.String[] args) {
+ //Trigger initialization
+ C c = new C();
+
+ List<Class<?>> expectedCInitOrder = Arrays.asList(I.class, J.class, A.class, K.class, B.class, L.class, C.class);
+ if (!cInitOrder.equals(expectedCInitOrder)) {
+ throw new RuntimeException(String.format("Class initialization order %s not equal to expected order %s", cInitOrder, expectedCInitOrder));
+ }
+ }
+
+ interface I {
+ boolean v = TestInterfaceOrder.out(I.class);
+ default void i() {}
+ }
+
+ interface J extends I {
+ boolean v = TestInterfaceOrder.out(J.class);
+ default void j() {}
+ }
+
+ static class A implements J {
+ static boolean v = TestInterfaceOrder.out(A.class);
+ }
+
+ interface K extends I {
+ boolean v = TestInterfaceOrder.out(K.class);
+ default void k() {}
+ }
+
+ static class B extends A implements K {
+ static boolean v = TestInterfaceOrder.out(B.class);
+ }
+
+ interface L {
+ boolean v = TestInterfaceOrder.out(L.class);
+ default void l() {}
+ }
+
+ static class C extends B implements L {
+ static boolean v = TestInterfaceOrder.out(C.class);
+ }
+
+
+ static boolean out(Class c) {
+ System.out.println("#: initializing " + c.getName());
+ cInitOrder.add(c);
+ return true;
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/reflect/ArrayGetIntException.java Mon Oct 27 15:09:23 2014 -0700
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6191224
+ * @summary (reflect) Misleading detail string in IllegalArgumentException thrown by Array.get<Type>
+ * @run main ArrayGetIntException
+ */
+import java.io.*;
+import java.lang.reflect.Array;
+
+public class ArrayGetIntException {
+ public static void main(String[] args) throws Exception {
+ Object[] objArray = {new Integer(Integer.MAX_VALUE)};
+
+ // this access is legal
+ try {
+ System.out.println(Array.get(objArray, 0));
+ System.out.println("Test #1 PASSES");
+ } catch(Exception e) {
+ failTest("Test #1 FAILS - legal access denied" + e.getMessage());
+ }
+
+ // this access is not legal, but needs to generate the proper exception message
+ try {
+ System.out.println(Array.getInt(objArray, 0));
+ failTest("Test #2 FAILS - no exception");
+ } catch(Exception e) {
+ System.out.println(e);
+ if (e.getMessage().equals("Argument is not an array of primitive type")) {
+ System.out.println("Test #2 PASSES");
+ } else {
+ failTest("Test #2 FAILS - incorrect message: " + e.getMessage());
+ }
+ }
+
+ // this access is not legal, but needs to generate the proper exception message
+ try {
+ System.out.println(Array.getInt(new Object(), 0));
+ failTest("Test #3 FAILS - no exception");
+ } catch(Exception e) {
+ System.out.println(e);
+ if (e.getMessage().equals("Argument is not an array")) {
+ System.out.println("Test #3 PASSES");
+ } else {
+ failTest("Test #3 FAILS - incorrect message: " + e.getMessage());
+ }
+ }
+ }
+
+ private static void failTest(String errStr) {
+ System.out.println(errStr);
+ throw new Error(errStr);
+ }
+}