diff --git a/.hgtags b/.hgtags index 41f7b254bf7..b9e82f0d134 100644 --- a/.hgtags +++ b/.hgtags @@ -159,3 +159,5 @@ a6e6d42203e6d35f9e8b31eac25b0021b4dd58ad jdk8-b33 f151d5833912a82cd4f203944da0305c3be83ecc jdk8-b35 98ce9816ae089c959ba1e70fba98423a31c4e9fa jdk8-b36 b3a91113026c99b0da010d41055719ab0d8938f0 jdk8-b37 +4cc5610a6dd6227da766ebf9742eb11ff5ded6c0 jdk8-b38 +35a5397278779a2f8f3013f81586dc8f30cb149d jdk8-b39 diff --git a/.hgtags-top-repo b/.hgtags-top-repo index 0494bf52131..5b76297fec5 100644 --- a/.hgtags-top-repo +++ b/.hgtags-top-repo @@ -159,3 +159,5 @@ cc771d92284f71765eca14d6d08703c4af254c04 jdk8-b21 5285317ebb4e8e4f6d8d52b5616fa801e2ea844d jdk8-b35 6a6ba0a07f33d37a2f97b1107e60c6a9a69ec84d jdk8-b36 b2972095a4b1e2a97409b7c3df61f3b263a5ce14 jdk8-b37 +d939bd0ab13c16647ffa38cc4b64fb31b7d44e10 jdk8-b38 +8927dd68aee3fa54a1a698e2980e1b2f6c7c12c1 jdk8-b39 diff --git a/corba/.hgtags b/corba/.hgtags index 77f6215faa8..611c780360f 100644 --- a/corba/.hgtags +++ b/corba/.hgtags @@ -159,3 +159,5 @@ e24c5cc8b0f7cc48374eef0f995838fb4823e0eb jdk8-b34 e3d735914edd0a621b16bb85417423f8e6af5d51 jdk8-b35 a5a61f259961a7f46b002e5cc50b4a9bf86927b6 jdk8-b36 83fac66442cf680bb59ec9e3a71cc4729322b595 jdk8-b37 +b8cbfb31139f820e5e094ba71449e58159fbe22e jdk8-b38 +785af00e2827990f149b32ec37f523dbca3efdd1 jdk8-b39 diff --git a/get_source.sh b/get_source.sh index bc609b3ee8d..24dca4aed48 100644 --- a/get_source.sh +++ b/get_source.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2010, 2012, 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 @@ -26,7 +26,7 @@ # # Get clones of all nested repositories -sh ./make/scripts/hgforest.sh clone +sh ./make/scripts/hgforest.sh clone $* # Update all existing repositories to the latest sources sh ./make/scripts/hgforest.sh pull -u diff --git a/hotspot/.hgtags b/hotspot/.hgtags index 8022f29a6bb..03a516d1f0d 100644 --- a/hotspot/.hgtags +++ b/hotspot/.hgtags @@ -244,3 +244,7 @@ dff6e3459210f8dd0430b9b03ccc99280560da30 hs24-b08 50b4400ca1ecb2ac2fde35f5e53ec8f04b86be7f jdk8-b36 bfcf92bfefb82da00f7fdbf0d9273feaa0a9456d jdk8-b37 7d5ec8bf38d1b12e0e09ec381f10976b8beede3b hs24-b09 +637c3f5f068f88fb9ec9c5867341cf59fd5ebedc jdk8-b38 +73147e6c48813b5fee904aa33f79a77103250ff4 hs24-b10 +96a403721094ecdaf6a1f4f52ebd0a82e07df199 jdk8-b39 +14b0e07ab9a6fa1662414496b7e07ac8450cf517 hs24-b11 diff --git a/hotspot/make/hotspot_version b/hotspot/make/hotspot_version index 3f3c7dc92ca..6922036c071 100644 --- a/hotspot/make/hotspot_version +++ b/hotspot/make/hotspot_version @@ -1,5 +1,5 @@ # -# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2006, 2012, 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 @@ -31,11 +31,11 @@ # # Don't put quotes (fail windows build). -HOTSPOT_VM_COPYRIGHT=Copyright 2011 +HOTSPOT_VM_COPYRIGHT=Copyright 2012 HS_MAJOR_VER=24 HS_MINOR_VER=0 -HS_BUILD_NUMBER=09 +HS_BUILD_NUMBER=11 JDK_MAJOR_VER=1 JDK_MINOR_VER=8 diff --git a/hotspot/make/linux/makefiles/vm.make b/hotspot/make/linux/makefiles/vm.make index a9517a4809b..6e9794ba710 100644 --- a/hotspot/make/linux/makefiles/vm.make +++ b/hotspot/make/linux/makefiles/vm.make @@ -102,9 +102,11 @@ CXXFLAGS = \ # a time and date. vm_version.o: CXXFLAGS += ${JRE_VERSION} -ifndef JAVASE_EMBEDDED +ifndef JAVASE_EMBEDDED +ifneq (${ARCH},arm) CFLAGS += -DINCLUDE_TRACE endif +endif # CFLAGS_WARN holds compiler options to suppress/enable warnings. CFLAGS += $(CFLAGS_WARN/BYFILE) @@ -153,11 +155,13 @@ SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm -ifndef JAVASE_EMBEDDED +ifndef JAVASE_EMBEDDED +ifneq (${ARCH},arm) SOURCE_PATHS+=$(shell if [ -d $(HS_ALT_SRC)/share/vm/jfr ]; then \ find $(HS_ALT_SRC)/share/vm/jfr -type d; \ fi) endif +endif CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path)) CORE_PATHS+=$(GENERATED)/jvmtifiles diff --git a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp index 904489e3a2b..b2587e4d8a2 100644 --- a/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp +++ b/hotspot/src/cpu/sparc/vm/c1_LIRAssembler_sparc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, 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 @@ -238,9 +238,12 @@ void LIR_Assembler::emit_string_compare(LIR_Opr left, LIR_Opr right, LIR_Opr dst Register result = dst->as_register(); { - // Get a pointer to the first character of string0 in tmp0 and get string0.count in str0 - // Get a pointer to the first character of string1 in tmp1 and get string1.count in str1 - // Also, get string0.count-string1.count in o7 and get the condition code set + // Get a pointer to the first character of string0 in tmp0 + // and get string0.length() in str0 + // Get a pointer to the first character of string1 in tmp1 + // and get string1.length() in str1 + // Also, get string0.length()-string1.length() in + // o7 and get the condition code set // Note: some instructions have been hoisted for better instruction scheduling Register tmp0 = L0; @@ -248,27 +251,40 @@ void LIR_Assembler::emit_string_compare(LIR_Opr left, LIR_Opr right, LIR_Opr dst Register tmp2 = L2; int value_offset = java_lang_String:: value_offset_in_bytes(); // char array - int offset_offset = java_lang_String::offset_offset_in_bytes(); // first character position - int count_offset = java_lang_String:: count_offset_in_bytes(); - - __ load_heap_oop(str0, value_offset, tmp0); - __ ld(str0, offset_offset, tmp2); - __ add(tmp0, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp0); - __ ld(str0, count_offset, str0); - __ sll(tmp2, exact_log2(sizeof(jchar)), tmp2); + if (java_lang_String::has_offset_field()) { + int offset_offset = java_lang_String::offset_offset_in_bytes(); // first character position + int count_offset = java_lang_String:: count_offset_in_bytes(); + __ load_heap_oop(str0, value_offset, tmp0); + __ ld(str0, offset_offset, tmp2); + __ add(tmp0, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp0); + __ ld(str0, count_offset, str0); + __ sll(tmp2, exact_log2(sizeof(jchar)), tmp2); + } else { + __ load_heap_oop(str0, value_offset, tmp1); + __ add(tmp1, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp0); + __ ld(tmp1, arrayOopDesc::length_offset_in_bytes(), str0); + } // str1 may be null add_debug_info_for_null_check_here(info); - __ load_heap_oop(str1, value_offset, tmp1); - __ add(tmp0, tmp2, tmp0); + if (java_lang_String::has_offset_field()) { + int offset_offset = java_lang_String::offset_offset_in_bytes(); // first character position + int count_offset = java_lang_String:: count_offset_in_bytes(); + __ load_heap_oop(str1, value_offset, tmp1); + __ add(tmp0, tmp2, tmp0); - __ ld(str1, offset_offset, tmp2); - __ add(tmp1, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp1); - __ ld(str1, count_offset, str1); - __ sll(tmp2, exact_log2(sizeof(jchar)), tmp2); + __ ld(str1, offset_offset, tmp2); + __ add(tmp1, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp1); + __ ld(str1, count_offset, str1); + __ sll(tmp2, exact_log2(sizeof(jchar)), tmp2); + __ add(tmp1, tmp2, tmp1); + } else { + __ load_heap_oop(str1, value_offset, tmp2); + __ add(tmp2, arrayOopDesc::base_offset_in_bytes(T_CHAR), tmp1); + __ ld(tmp2, arrayOopDesc::length_offset_in_bytes(), str1); + } __ subcc(str0, str1, O7); - __ add(tmp1, tmp2, tmp1); } { @@ -302,7 +318,7 @@ void LIR_Assembler::emit_string_compare(LIR_Opr left, LIR_Opr right, LIR_Opr dst // Shift base0 and base1 to the end of the arrays, negate limit __ add(base0, limit, base0); __ add(base1, limit, base1); - __ neg(limit); // limit = -min{string0.count, strin1.count} + __ neg(limit); // limit = -min{string0.length(), string1.length()} __ lduh(base0, limit, chr0); __ bind(Lloop); diff --git a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp index b0062406da1..4b2f8699e02 100644 --- a/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp +++ b/hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, 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 @@ -505,19 +505,28 @@ void LIR_Assembler::emit_string_compare(LIR_Opr arg0, LIR_Opr arg1, LIR_Opr dst, // Get addresses of first characters from both Strings __ load_heap_oop(rsi, Address(rax, java_lang_String::value_offset_in_bytes())); - __ movptr (rcx, Address(rax, java_lang_String::offset_offset_in_bytes())); - __ lea (rsi, Address(rsi, rcx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); - + if (java_lang_String::has_offset_field()) { + __ movptr (rcx, Address(rax, java_lang_String::offset_offset_in_bytes())); + __ movl (rax, Address(rax, java_lang_String::count_offset_in_bytes())); + __ lea (rsi, Address(rsi, rcx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); + } else { + __ movl (rax, Address(rsi, arrayOopDesc::length_offset_in_bytes())); + __ lea (rsi, Address(rsi, arrayOopDesc::base_offset_in_bytes(T_CHAR))); + } // rbx, may be NULL add_debug_info_for_null_check_here(info); __ load_heap_oop(rdi, Address(rbx, java_lang_String::value_offset_in_bytes())); - __ movptr (rcx, Address(rbx, java_lang_String::offset_offset_in_bytes())); - __ lea (rdi, Address(rdi, rcx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); + if (java_lang_String::has_offset_field()) { + __ movptr (rcx, Address(rbx, java_lang_String::offset_offset_in_bytes())); + __ movl (rbx, Address(rbx, java_lang_String::count_offset_in_bytes())); + __ lea (rdi, Address(rdi, rcx, Address::times_2, arrayOopDesc::base_offset_in_bytes(T_CHAR))); + } else { + __ movl (rbx, Address(rdi, arrayOopDesc::length_offset_in_bytes())); + __ lea (rdi, Address(rdi, arrayOopDesc::base_offset_in_bytes(T_CHAR))); + } // compute minimum length (in rax) and difference of lengths (on top of stack) - __ movl (rbx, Address(rbx, java_lang_String::count_offset_in_bytes())); - __ movl (rax, Address(rax, java_lang_String::count_offset_in_bytes())); __ mov (rcx, rbx); __ subptr(rbx, rax); // subtract lengths __ push (rbx); // result @@ -1462,7 +1471,11 @@ void LIR_Assembler::emit_opConvert(LIR_OpConvert* op) { break; case Bytecodes::_l2i: +#ifdef _LP64 + __ movl(dest->as_register(), src->as_register_lo()); +#else move_regs(src->as_register_lo(), dest->as_register()); +#endif break; case Bytecodes::_i2b: diff --git a/hotspot/src/os/windows/vm/jvm_windows.h b/hotspot/src/os/windows/vm/jvm_windows.h index a45f86c2e77..91039821558 100644 --- a/hotspot/src/os/windows/vm/jvm_windows.h +++ b/hotspot/src/os/windows/vm/jvm_windows.h @@ -59,7 +59,7 @@ typedef struct _MODULEINFO { #include -typedef unsigned int socklen_t; +typedef int socklen_t; // #include "jni.h" diff --git a/hotspot/src/os/windows/vm/os_windows.cpp b/hotspot/src/os/windows/vm/os_windows.cpp index de38c6c12da..c607905e836 100644 --- a/hotspot/src/os/windows/vm/os_windows.cpp +++ b/hotspot/src/os/windows/vm/os_windows.cpp @@ -4820,99 +4820,92 @@ struct hostent* os::get_host_by_name(char* name) { return (struct hostent*)os::WinSock2Dll::gethostbyname(name); } - int os::socket_close(int fd) { - ShouldNotReachHere(); - return 0; + return ::closesocket(fd); } int os::socket_available(int fd, jint *pbytes) { - ShouldNotReachHere(); - return 0; + int ret = ::ioctlsocket(fd, FIONREAD, (u_long*)pbytes); + return (ret < 0) ? 0 : 1; } int os::socket(int domain, int type, int protocol) { - ShouldNotReachHere(); - return 0; + return ::socket(domain, type, protocol); } int os::listen(int fd, int count) { - ShouldNotReachHere(); - return 0; + return ::listen(fd, count); } int os::connect(int fd, struct sockaddr* him, socklen_t len) { - ShouldNotReachHere(); - return 0; + return ::connect(fd, him, len); } int os::accept(int fd, struct sockaddr* him, socklen_t* len) { - ShouldNotReachHere(); - return 0; + return ::accept(fd, him, len); } int os::sendto(int fd, char* buf, size_t len, uint flags, struct sockaddr* to, socklen_t tolen) { - ShouldNotReachHere(); - return 0; + + 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) { - ShouldNotReachHere(); - return 0; + + return ::recvfrom(fd, buf, (int)nBytes, flags, from, fromlen); } int os::recv(int fd, char* buf, size_t nBytes, uint flags) { - ShouldNotReachHere(); - return 0; + return ::recv(fd, buf, (int)nBytes, flags); } int os::send(int fd, char* buf, size_t nBytes, uint flags) { - ShouldNotReachHere(); - return 0; + return ::send(fd, buf, (int)nBytes, flags); } int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { - ShouldNotReachHere(); - return 0; + return ::send(fd, buf, (int)nBytes, flags); } int os::timeout(int fd, long timeout) { - ShouldNotReachHere(); - return 0; + 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) { - ShouldNotReachHere(); - return 0; + return ::gethostname(name, namelen); } int os::socket_shutdown(int fd, int howto) { - ShouldNotReachHere(); - return 0; + return ::shutdown(fd, howto); } int os::bind(int fd, struct sockaddr* him, socklen_t len) { - ShouldNotReachHere(); - return 0; + return ::bind(fd, him, len); } int os::get_sock_name(int fd, struct sockaddr* him, socklen_t* len) { - ShouldNotReachHere(); - return 0; + return ::getsockname(fd, him, len); } int os::get_sock_opt(int fd, int level, int optname, char* optval, socklen_t* optlen) { - ShouldNotReachHere(); - return 0; + return ::getsockopt(fd, level, optname, optval, optlen); } int os::set_sock_opt(int fd, int level, int optname, const char* optval, socklen_t optlen) { - ShouldNotReachHere(); - return 0; + return ::setsockopt(fd, level, optname, optval, optlen); } diff --git a/hotspot/src/share/vm/classfile/classFileParser.cpp b/hotspot/src/share/vm/classfile/classFileParser.cpp index c7ea5b580aa..f24610c060c 100644 --- a/hotspot/src/share/vm/classfile/classFileParser.cpp +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp @@ -3355,7 +3355,8 @@ instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, static_field_size, total_oop_map_count, access_flags, - rt, CHECK_(nullHandle)); + rt, host_klass, + CHECK_(nullHandle)); instanceKlassHandle this_klass (THREAD, ik); assert(this_klass->static_field_size() == static_field_size, "sanity"); diff --git a/hotspot/src/share/vm/classfile/javaClasses.cpp b/hotspot/src/share/vm/classfile/javaClasses.cpp index b5e887f74a8..eab75e181e3 100644 --- a/hotspot/src/share/vm/classfile/javaClasses.cpp +++ b/hotspot/src/share/vm/classfile/javaClasses.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, 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 @@ -143,7 +143,27 @@ compute_optional_offset(int& dest_offset, } +int java_lang_String::value_offset = 0; +int java_lang_String::offset_offset = 0; +int java_lang_String::count_offset = 0; +int java_lang_String::hash_offset = 0; + +bool java_lang_String::initialized = false; + +void java_lang_String::compute_offsets() { + assert(!initialized, "offsets should be initialized only once"); + + klassOop k = SystemDictionary::String_klass(); + compute_offset(value_offset, k, vmSymbols::value_name(), vmSymbols::char_array_signature()); + compute_optional_offset(offset_offset, k, vmSymbols::offset_name(), vmSymbols::int_signature()); + compute_optional_offset(count_offset, k, vmSymbols::count_name(), vmSymbols::int_signature()); + compute_optional_offset(hash_offset, k, vmSymbols::hash_name(), vmSymbols::int_signature()); + + initialized = true; +} + Handle java_lang_String::basic_create(int length, bool tenured, TRAPS) { + assert(initialized, "Must be initialized"); // Create the String object first, so there's a chance that the String // and the char array it points to end up in the same cache line. oop obj; @@ -2837,10 +2857,6 @@ int java_lang_System::err_offset_in_bytes() { -int java_lang_String::value_offset; -int java_lang_String::offset_offset; -int java_lang_String::count_offset; -int java_lang_String::hash_offset; int java_lang_Class::_klass_offset; int java_lang_Class::_array_klass_offset; int java_lang_Class::_resolved_constructor_offset; @@ -3000,12 +3016,6 @@ void JavaClasses::compute_hard_coded_offsets() { const int x = heapOopSize; const int header = instanceOopDesc::base_offset_in_bytes(); - // Do the String Class - java_lang_String::value_offset = java_lang_String::hc_value_offset * x + header; - java_lang_String::offset_offset = java_lang_String::hc_offset_offset * x + header; - java_lang_String::count_offset = java_lang_String::offset_offset + sizeof (jint); - java_lang_String::hash_offset = java_lang_String::count_offset + sizeof (jint); - // Throwable Class java_lang_Throwable::backtrace_offset = java_lang_Throwable::hc_backtrace_offset * x + header; java_lang_Throwable::detailMessage_offset = java_lang_Throwable::hc_detailMessage_offset * x + header; @@ -3200,9 +3210,13 @@ void JavaClasses::check_offsets() { // java.lang.String CHECK_OFFSET("java/lang/String", java_lang_String, value, "[C"); - CHECK_OFFSET("java/lang/String", java_lang_String, offset, "I"); - CHECK_OFFSET("java/lang/String", java_lang_String, count, "I"); - CHECK_OFFSET("java/lang/String", java_lang_String, hash, "I"); + if (java_lang_String::has_offset_field()) { + CHECK_OFFSET("java/lang/String", java_lang_String, offset, "I"); + CHECK_OFFSET("java/lang/String", java_lang_String, count, "I"); + } + if (java_lang_String::has_hash_field()) { + CHECK_OFFSET("java/lang/String", java_lang_String, hash, "I"); + } // java.lang.Class diff --git a/hotspot/src/share/vm/classfile/javaClasses.hpp b/hotspot/src/share/vm/classfile/javaClasses.hpp index 2a32801fc73..708ea4f544a 100644 --- a/hotspot/src/share/vm/classfile/javaClasses.hpp +++ b/hotspot/src/share/vm/classfile/javaClasses.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, 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 @@ -52,26 +52,36 @@ class java_lang_String : AllStatic { private: - enum { - hc_value_offset = 0, - hc_offset_offset = 1 - //hc_count_offset = 2 -- not a word-scaled offset - //hc_hash_offset = 3 -- not a word-scaled offset - }; - static int value_offset; static int offset_offset; static int count_offset; static int hash_offset; + static bool initialized; + static Handle basic_create(int length, bool tenured, TRAPS); static Handle basic_create_from_unicode(jchar* unicode, int length, bool tenured, TRAPS); - static void set_value( oop string, typeArrayOop buffer) { string->obj_field_put(value_offset, (oop)buffer); } - static void set_offset(oop string, int offset) { string->int_field_put(offset_offset, offset); } - static void set_count( oop string, int count) { string->int_field_put(count_offset, count); } + static void set_value( oop string, typeArrayOop buffer) { + assert(initialized, "Must be initialized"); + string->obj_field_put(value_offset, (oop)buffer); + } + static void set_offset(oop string, int offset) { + assert(initialized, "Must be initialized"); + if (offset_offset > 0) { + string->int_field_put(offset_offset, offset); + } + } + static void set_count( oop string, int count) { + assert(initialized, "Must be initialized"); + if (count_offset > 0) { + string->int_field_put(count_offset, count); + } + } public: + static void compute_offsets(); + // Instance creation static Handle create_from_unicode(jchar* unicode, int len, TRAPS); static Handle create_tenured_from_unicode(jchar* unicode, int len, TRAPS); @@ -82,23 +92,61 @@ class java_lang_String : AllStatic { static Handle create_from_platform_dependent_str(const char* str, TRAPS); static Handle char_converter(Handle java_string, jchar from_char, jchar to_char, TRAPS); - static int value_offset_in_bytes() { return value_offset; } - static int count_offset_in_bytes() { return count_offset; } - static int offset_offset_in_bytes() { return offset_offset; } - static int hash_offset_in_bytes() { return hash_offset; } + static bool has_offset_field() { + assert(initialized, "Must be initialized"); + return (offset_offset > 0); + } + + static bool has_count_field() { + assert(initialized, "Must be initialized"); + return (count_offset > 0); + } + + static bool has_hash_field() { + assert(initialized, "Must be initialized"); + return (hash_offset > 0); + } + + static int value_offset_in_bytes() { + assert(initialized && (value_offset > 0), "Must be initialized"); + return value_offset; + } + static int count_offset_in_bytes() { + assert(initialized && (count_offset > 0), "Must be initialized"); + return count_offset; + } + static int offset_offset_in_bytes() { + assert(initialized && (offset_offset > 0), "Must be initialized"); + return offset_offset; + } + static int hash_offset_in_bytes() { + assert(initialized && (hash_offset > 0), "Must be initialized"); + return hash_offset; + } // Accessors static typeArrayOop value(oop java_string) { + assert(initialized && (value_offset > 0), "Must be initialized"); assert(is_instance(java_string), "must be java_string"); return (typeArrayOop) java_string->obj_field(value_offset); } static int offset(oop java_string) { + assert(initialized, "Must be initialized"); assert(is_instance(java_string), "must be java_string"); - return java_string->int_field(offset_offset); + if (offset_offset > 0) { + return java_string->int_field(offset_offset); + } else { + return 0; + } } static int length(oop java_string) { + assert(initialized, "Must be initialized"); assert(is_instance(java_string), "must be java_string"); - return java_string->int_field(count_offset); + if (count_offset > 0) { + return java_string->int_field(count_offset); + } else { + return ((typeArrayOop)java_string->obj_field(value_offset))->length(); + } } static int utf8_length(oop java_string); diff --git a/hotspot/src/share/vm/classfile/systemDictionary.cpp b/hotspot/src/share/vm/classfile/systemDictionary.cpp index 04bb9d9f5c5..0bdc16de6ff 100644 --- a/hotspot/src/share/vm/classfile/systemDictionary.cpp +++ b/hotspot/src/share/vm/classfile/systemDictionary.cpp @@ -1971,6 +1971,9 @@ void SystemDictionary::initialize_preloaded_classes(TRAPS) { // first do Object, String, Class initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK); + // Calculate offsets for String and Class classes since they are loaded and + // can be used after this point. + java_lang_String::compute_offsets(); java_lang_Class::compute_offsets(); // Fixup mirrors for classes loaded before java.lang.Class. diff --git a/hotspot/src/share/vm/classfile/vmSymbols.hpp b/hotspot/src/share/vm/classfile/vmSymbols.hpp index 9cee5ac0490..b0d014575aa 100644 --- a/hotspot/src/share/vm/classfile/vmSymbols.hpp +++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp @@ -340,6 +340,9 @@ template(park_event_name, "nativeParkEventPointer") \ template(cache_field_name, "cache") \ template(value_name, "value") \ + template(offset_name, "offset") \ + template(count_name, "count") \ + template(hash_name, "hash") \ template(frontCacheEnabled_name, "frontCacheEnabled") \ template(stringCacheEnabled_name, "stringCacheEnabled") \ template(numberOfLeadingZeros_name, "numberOfLeadingZeros") \ diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp index 5825a5772fc..938e94efcff 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.cpp @@ -6332,10 +6332,10 @@ void CMSCollector::reset(bool asynch) { ) } -void CMSCollector::do_CMS_operation(CMS_op_type op) { +void CMSCollector::do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause) { gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); - TraceTime t("GC", PrintGC, !PrintGCDetails, gclog_or_tty); + TraceTime t(GCCauseString("GC", gc_cause), PrintGC, !PrintGCDetails, gclog_or_tty); TraceCollectorStats tcs(counters()); switch (op) { diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp index a84253888b0..ecc60cc3ead 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepGeneration.hpp @@ -717,7 +717,7 @@ class CMSCollector: public CHeapObj { CMS_op_checkpointRootsFinal }; - void do_CMS_operation(CMS_op_type op); + void do_CMS_operation(CMS_op_type op, GCCause::Cause gc_cause); bool stop_world_and_do(CMS_op_type op); OopTaskQueueSet* task_queues() { return _task_queues; } diff --git a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp index c3b9d54bec3..3b8d5aa0878 100644 --- a/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp +++ b/hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/vmCMSOperations.cpp @@ -146,7 +146,7 @@ void VM_CMS_Initial_Mark::doit() { VM_CMS_Operation::verify_before_gc(); IsGCActiveMark x; // stop-world GC active - _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsInitial); + _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsInitial, gch->gc_cause()); VM_CMS_Operation::verify_after_gc(); #ifndef USDT2 @@ -178,7 +178,7 @@ void VM_CMS_Final_Remark::doit() { VM_CMS_Operation::verify_before_gc(); IsGCActiveMark x; // stop-world GC active - _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsFinal); + _collector->do_CMS_operation(CMSCollector::CMS_op_checkpointRootsFinal, gch->gc_cause()); VM_CMS_Operation::verify_after_gc(); #ifndef USDT2 diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp index 270e52e32b4..9d1f9d92ddc 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @@ -1252,10 +1252,7 @@ bool G1CollectedHeap::do_collection(bool explicit_gc, gclog_or_tty->date_stamp(G1Log::fine() && PrintGCDateStamps); TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty); - char verbose_str[128]; - sprintf(verbose_str, "Full GC (%s)", GCCause::to_string(gc_cause())); - TraceTime t(verbose_str, G1Log::fine(), true, gclog_or_tty); - + TraceTime t(GCCauseString("Full GC", gc_cause()), G1Log::fine(), true, gclog_or_tty); TraceCollectorStats tcs(g1mm()->full_collection_counters()); TraceMemoryManagerStats tms(true /* fullGC */, gc_cause()); @@ -3600,12 +3597,10 @@ G1CollectedHeap::do_collection_pause_at_safepoint(double target_pause_time_ms) { gclog_or_tty->date_stamp(G1Log::fine() && PrintGCDateStamps); TraceCPUTime tcpu(G1Log::finer(), true, gclog_or_tty); - char verbose_str[128]; - sprintf(verbose_str, "GC pause (%s) (%s)%s", - GCCause::to_string(gc_cause()), - g1_policy()->gcs_are_young() ? "young" : "mixed", - g1_policy()->during_initial_mark_pause() ? " (initial-mark)" : ""); - TraceTime t(verbose_str, G1Log::fine() && !G1Log::finer(), true, gclog_or_tty); + GCCauseString gc_cause_str = GCCauseString("GC pause", gc_cause()) + .append(g1_policy()->gcs_are_young() ? " (young)" : " (mixed)") + .append(g1_policy()->during_initial_mark_pause() ? " (initial-mark)" : ""); + TraceTime t(gc_cause_str, G1Log::fine() && !G1Log::finer(), true, gclog_or_tty); TraceCollectorStats tcs(g1mm()->incremental_collection_counters()); TraceMemoryManagerStats tms(false /* fullGC */, gc_cause()); @@ -5502,7 +5497,7 @@ void G1CollectedHeap::evacuate_collection_set() { if (evacuation_failed()) { remove_self_forwarding_pointers(); if (G1Log::finer()) { - gclog_or_tty->print(" (to-space overflow)"); + gclog_or_tty->print(" (to-space exhausted)"); } else if (G1Log::fine()) { gclog_or_tty->print("--"); } diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp index a4060618131..2050f6f5bba 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp @@ -886,9 +886,8 @@ void G1CollectorPolicy::record_collection_pause_start(double start_time_sec, size_t start_used) { if (G1Log::finer()) { gclog_or_tty->stamp(PrintGCTimeStamps); - gclog_or_tty->print("[GC pause (%s) (%s)", - GCCause::to_string(_g1->gc_cause()), - gcs_are_young() ? "young" : "mixed"); + gclog_or_tty->print("[%s", (const char*)GCCauseString("GC pause", _g1->gc_cause()) + .append(gcs_are_young() ? " (young)" : " (mixed)")); } // We only need to do this here as the policy will only be applied @@ -1010,7 +1009,8 @@ T sum_of(T* sum_arr, int start, int n, int N) { void G1CollectorPolicy::print_par_stats(int level, const char* str, - double* data) { + double* data, + bool showDecimals) { double min = data[0], max = data[0]; double total = 0.0; LineBuffer buf(level); @@ -1023,7 +1023,11 @@ void G1CollectorPolicy::print_par_stats(int level, max = val; total += val; if (G1Log::finest()) { - buf.append(" %.1lf", val); + if (showDecimals) { + buf.append(" %.1lf", val); + } else { + buf.append(" %d", (int)val); + } } } @@ -1031,36 +1035,26 @@ void G1CollectorPolicy::print_par_stats(int level, buf.append_and_print_cr(""); } double avg = total / (double) no_of_gc_threads(); - buf.append_and_print_cr(" Avg: %.1lf Min: %.1lf Max: %.1lf Diff: %.1lf]", - avg, min, max, max - min); -} - -void G1CollectorPolicy::print_par_sizes(int level, - const char* str, - double* data) { - double min = data[0], max = data[0]; - double total = 0.0; - LineBuffer buf(level); - buf.append("[%s :", str); - for (uint i = 0; i < no_of_gc_threads(); ++i) { - double val = data[i]; - if (val < min) - min = val; - if (val > max) - max = val; - total += val; - buf.append(" %d", (int) val); + if (showDecimals) { + buf.append_and_print_cr(" Min: %.1lf, Avg: %.1lf, Max: %.1lf, Diff: %.1lf, Sum: %.1lf]", + min, avg, max, max - min, total); + } else { + buf.append_and_print_cr(" Min: %d, Avg: %d, Max: %d, Diff: %d, Sum: %d]", + (int)min, (int)avg, (int)max, (int)max - (int)min, (int)total); } - buf.append_and_print_cr(""); - double avg = total / (double) no_of_gc_threads(); - buf.append_and_print_cr(" Sum: %d, Avg: %d, Min: %d, Max: %d, Diff: %d]", - (int)total, (int)avg, (int)min, (int)max, (int)max - (int)min); } void G1CollectorPolicy::print_stats(int level, const char* str, double value) { - LineBuffer(level).append_and_print_cr("[%s: %5.1lf ms]", str, value); + LineBuffer(level).append_and_print_cr("[%s: %.1lf ms]", str, value); +} + +void G1CollectorPolicy::print_stats(int level, + const char* str, + double value, + int workers) { + LineBuffer(level).append_and_print_cr("[%s: %.1lf ms, GC Workers: %d]", str, value, workers); } void G1CollectorPolicy::print_stats(int level, @@ -1373,7 +1367,7 @@ void G1CollectorPolicy::record_collection_pause_end(int no_of_gc_threads) { print_stats(1, "Root Region Scan Waiting", _root_region_scan_wait_time_ms); } if (parallel) { - print_stats(1, "Parallel Time", _cur_collection_par_time_ms); + print_stats(1, "Parallel Time", _cur_collection_par_time_ms, no_of_gc_threads); print_par_stats(2, "GC Worker Start", _par_last_gc_worker_start_times_ms); print_par_stats(2, "Ext Root Scanning", _par_last_ext_root_scan_times_ms); if (print_marking_info) { @@ -1381,13 +1375,15 @@ void G1CollectorPolicy::record_collection_pause_end(int no_of_gc_threads) { } print_par_stats(2, "Update RS", _par_last_update_rs_times_ms); if (G1Log::finest()) { - print_par_sizes(3, "Processed Buffers", _par_last_update_rs_processed_buffers); + print_par_stats(3, "Processed Buffers", _par_last_update_rs_processed_buffers, + false /* showDecimals */); } print_par_stats(2, "Scan RS", _par_last_scan_rs_times_ms); print_par_stats(2, "Object Copy", _par_last_obj_copy_times_ms); print_par_stats(2, "Termination", _par_last_termination_times_ms); if (G1Log::finest()) { - print_par_sizes(3, "Termination Attempts", _par_last_termination_attempts); + print_par_stats(3, "Termination Attempts", _par_last_termination_attempts, + false /* showDecimals */); } for (int i = 0; i < _parallel_gc_threads; i++) { @@ -1601,9 +1597,9 @@ void G1CollectorPolicy::record_collection_pause_end(int no_of_gc_threads) { _collectionSetChooser->verify(); } -#define EXT_SIZE_FORMAT "%d%s" +#define EXT_SIZE_FORMAT "%.1f%s" #define EXT_SIZE_PARAMS(bytes) \ - byte_size_in_proper_unit((bytes)), \ + byte_size_in_proper_unit((double)(bytes)), \ proper_unit_for_byte_size((bytes)) void G1CollectorPolicy::print_heap_transition() { diff --git a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp index 7cdf79d7feb..88069816ef6 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp +++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.hpp @@ -552,10 +552,10 @@ public: private: void print_stats(int level, const char* str, double value); + void print_stats(int level, const char* str, double value, int workers); void print_stats(int level, const char* str, int value); - void print_par_stats(int level, const char* str, double* data); - void print_par_sizes(int level, const char* str, double* data); + void print_par_stats(int level, const char* str, double* data, bool showDecimals = true); void check_other_times(int level, NumberSeq* other_times_ms, diff --git a/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp b/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp index 1a330ba6483..d880f5509ad 100644 --- a/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp +++ b/hotspot/src/share/vm/gc_implementation/g1/vm_operations_g1.cpp @@ -42,6 +42,7 @@ VM_G1CollectForAllocation::VM_G1CollectForAllocation( void VM_G1CollectForAllocation::doit() { G1CollectedHeap* g1h = G1CollectedHeap::heap(); + GCCauseSetter x(g1h, _gc_cause); _result = g1h->satisfy_failed_allocation(_word_size, &_pause_succeeded); assert(_result == NULL || _pause_succeeded, "if we get back a result, the pause should have succeeded"); diff --git a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 4f64dff0824..96ae468f0bf 100644 --- a/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/hotspot/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -916,7 +916,7 @@ void ParNewGeneration::collect(bool full, size_policy->minor_collection_begin(); } - TraceTime t1("GC", PrintGC && !PrintGCDetails, true, gclog_or_tty); + TraceTime t1(GCCauseString("GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, gclog_or_tty); // Capture heap used before collection (for printing). size_t gch_prev_used = gch->used(); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp index ad599ae3219..0ef97523630 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psMarkSweep.cpp @@ -160,16 +160,10 @@ bool PSMarkSweep::invoke_no_policy(bool clear_all_softrefs) { { HandleMark hm; - const bool is_system_gc = gc_cause == GCCause::_java_lang_system_gc; - // This is useful for debugging but don't change the output the - // the customer sees. - const char* gc_cause_str = "Full GC"; - if (is_system_gc && PrintGCDetails) { - gc_cause_str = "Full GC (System)"; - } + gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); - TraceTime t1(gc_cause_str, PrintGC, !PrintGCDetails, gclog_or_tty); + TraceTime t1(GCCauseString("Full GC", gc_cause), PrintGC, !PrintGCDetails, gclog_or_tty); TraceCollectorStats tcs(counters()); TraceMemoryManagerStats tms(true /* Full GC */,gc_cause); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp index 354b3d04347..8e7c74e4495 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.cpp @@ -2047,17 +2047,9 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { gc_task_manager()->task_idle_workers(); heap->set_par_threads(gc_task_manager()->active_workers()); - const bool is_system_gc = gc_cause == GCCause::_java_lang_system_gc; - - // This is useful for debugging but don't change the output the - // the customer sees. - const char* gc_cause_str = "Full GC"; - if (is_system_gc && PrintGCDetails) { - gc_cause_str = "Full GC (System)"; - } gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); - TraceTime t1(gc_cause_str, PrintGC, !PrintGCDetails, gclog_or_tty); + TraceTime t1(GCCauseString("Full GC", gc_cause), PrintGC, !PrintGCDetails, gclog_or_tty); TraceCollectorStats tcs(counters()); TraceMemoryManagerStats tms(true /* Full GC */,gc_cause); @@ -2090,7 +2082,8 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) { } #endif // #ifndef PRODUCT - bool max_on_system_gc = UseMaximumCompactionOnSystemGC && is_system_gc; + bool max_on_system_gc = UseMaximumCompactionOnSystemGC + && gc_cause == GCCause::_java_lang_system_gc; summary_phase(vmthread_cm, maximum_heap_compaction || max_on_system_gc); COMPILER2_PRESENT(assert(DerivedPointerTable::is_active(), "Sanity")); diff --git a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp index 984b1a452eb..65ece052d16 100644 --- a/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp +++ b/hotspot/src/share/vm/gc_implementation/parallelScavenge/psScavenge.cpp @@ -325,7 +325,7 @@ bool PSScavenge::invoke_no_policy() { gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); - TraceTime t1("GC", PrintGC, !PrintGCDetails, gclog_or_tty); + TraceTime t1(GCCauseString("GC", gc_cause), PrintGC, !PrintGCDetails, gclog_or_tty); TraceCollectorStats tcs(counters()); TraceMemoryManagerStats tms(false /* not full GC */,gc_cause); diff --git a/hotspot/src/share/vm/gc_implementation/shared/gcUtil.cpp b/hotspot/src/share/vm/gc_implementation/shared/gcUtil.cpp index 5325fee218b..3b9fd7a68aa 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/gcUtil.cpp +++ b/hotspot/src/share/vm/gc_implementation/shared/gcUtil.cpp @@ -31,9 +31,15 @@ float AdaptiveWeightedAverage::compute_adaptive_average(float new_sample, float average) { // We smooth the samples by not using weight() directly until we've // had enough data to make it meaningful. We'd like the first weight - // used to be 1, the second to be 1/2, etc until we have 100/weight - // samples. - unsigned count_weight = 100/count(); + // used to be 1, the second to be 1/2, etc until we have + // OLD_THRESHOLD/weight samples. + unsigned count_weight = 0; + + // Avoid division by zero if the counter wraps (7158457) + if (!is_old()) { + count_weight = OLD_THRESHOLD/count(); + } + unsigned adaptive_weight = (MAX2(weight(), count_weight)); float new_avg = exp_avg(average, new_sample, adaptive_weight); @@ -43,8 +49,6 @@ float AdaptiveWeightedAverage::compute_adaptive_average(float new_sample, void AdaptiveWeightedAverage::sample(float new_sample) { increment_count(); - assert(count() != 0, - "Wraparound -- history would be incorrectly discarded"); // Compute the new weighted average float new_avg = compute_adaptive_average(new_sample, average()); diff --git a/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp b/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp index 8dd3258de0a..86daba64c3f 100644 --- a/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp +++ b/hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp @@ -50,11 +50,20 @@ class AdaptiveWeightedAverage : public CHeapObj { unsigned _weight; // The weight used to smooth the averages // A higher weight favors the most // recent data. + bool _is_old; // Has enough historical data + + const static unsigned OLD_THRESHOLD = 100; protected: float _last_sample; // The last value sampled. - void increment_count() { _sample_count++; } + void increment_count() { + _sample_count++; + if (!_is_old && _sample_count > OLD_THRESHOLD) { + _is_old = true; + } + } + void set_average(float avg) { _average = avg; } // Helper function, computes an adaptive weighted average @@ -64,13 +73,15 @@ class AdaptiveWeightedAverage : public CHeapObj { public: // Input weight must be between 0 and 100 AdaptiveWeightedAverage(unsigned weight, float avg = 0.0) : - _average(avg), _sample_count(0), _weight(weight), _last_sample(0.0) { + _average(avg), _sample_count(0), _weight(weight), _last_sample(0.0), + _is_old(false) { } void clear() { _average = 0; _sample_count = 0; _last_sample = 0; + _is_old = false; } // Useful for modifying static structures after startup. @@ -84,7 +95,8 @@ class AdaptiveWeightedAverage : public CHeapObj { float average() const { return _average; } unsigned weight() const { return _weight; } unsigned count() const { return _sample_count; } - float last_sample() const { return _last_sample; } + float last_sample() const { return _last_sample; } + bool is_old() const { return _is_old; } // Update data with a new sample. void sample(float new_sample); diff --git a/hotspot/src/share/vm/gc_interface/gcCause.hpp b/hotspot/src/share/vm/gc_interface/gcCause.hpp index ae14115d7e2..8866d7675ce 100644 --- a/hotspot/src/share/vm/gc_interface/gcCause.hpp +++ b/hotspot/src/share/vm/gc_interface/gcCause.hpp @@ -88,4 +88,36 @@ class GCCause : public AllStatic { static const char* to_string(GCCause::Cause cause); }; +// Helper class for doing logging that includes the GC Cause +// as a string. +class GCCauseString : StackObj { + private: + static const int _length = 128; + char _buffer[_length]; + int _position; + + public: + GCCauseString(const char* prefix, GCCause::Cause cause) { + if (PrintGCCause) { + _position = jio_snprintf(_buffer, _length, "%s (%s)", prefix, GCCause::to_string(cause)); + } else { + _position = jio_snprintf(_buffer, _length, "%s", prefix); + } + assert(_position >= 0 && _position <= _length, + err_msg("Need to increase the buffer size in GCCauseString? %d", _position)); + } + + GCCauseString& append(const char* str) { + int res = jio_snprintf(_buffer + _position, _length - _position, "%s", str); + _position += res; + assert(res >= 0 && _position <= _length, + err_msg("Need to increase the buffer size in GCCauseString? %d", res)); + return *this; + } + + operator const char*() { + return _buffer; + } +}; + #endif // SHARE_VM_GC_INTERFACE_GCCAUSE_HPP diff --git a/hotspot/src/share/vm/memory/defNewGeneration.cpp b/hotspot/src/share/vm/memory/defNewGeneration.cpp index 315a38248c9..452f630730a 100644 --- a/hotspot/src/share/vm/memory/defNewGeneration.cpp +++ b/hotspot/src/share/vm/memory/defNewGeneration.cpp @@ -548,7 +548,7 @@ void DefNewGeneration::collect(bool full, init_assuming_no_promotion_failure(); - TraceTime t1("GC", PrintGC && !PrintGCDetails, true, gclog_or_tty); + TraceTime t1(GCCauseString("GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, gclog_or_tty); // Capture heap used before collection (for printing). size_t gch_prev_used = gch->used(); diff --git a/hotspot/src/share/vm/memory/dump.cpp b/hotspot/src/share/vm/memory/dump.cpp index af1d7928dca..e91d33135e4 100644 --- a/hotspot/src/share/vm/memory/dump.cpp +++ b/hotspot/src/share/vm/memory/dump.cpp @@ -78,8 +78,8 @@ public: void do_oop(oop* p) { if (p != NULL) { oop obj = *p; - if (obj->klass() == SystemDictionary::String_klass()) { - + if (obj->klass() == SystemDictionary::String_klass() && + java_lang_String::has_hash_field()) { int hash = java_lang_String::hash_string(obj); obj->int_field_put(hash_offset, hash); } diff --git a/hotspot/src/share/vm/memory/genCollectedHeap.cpp b/hotspot/src/share/vm/memory/genCollectedHeap.cpp index 10c3274548d..40f5afda442 100644 --- a/hotspot/src/share/vm/memory/genCollectedHeap.cpp +++ b/hotspot/src/share/vm/memory/genCollectedHeap.cpp @@ -480,26 +480,15 @@ void GenCollectedHeap::do_collection(bool full, const size_t perm_prev_used = perm_gen()->used(); print_heap_before_gc(); - if (Verbose) { - gclog_or_tty->print_cr("GC Cause: %s", GCCause::to_string(gc_cause())); - } { FlagSetting fl(_is_gc_active, true); bool complete = full && (max_level == (n_gens()-1)); - const char* gc_cause_str = "GC "; - if (complete) { - GCCause::Cause cause = gc_cause(); - if (cause == GCCause::_java_lang_system_gc) { - gc_cause_str = "Full GC (System) "; - } else { - gc_cause_str = "Full GC "; - } - } + const char* gc_cause_prefix = complete ? "Full GC" : "GC"; gclog_or_tty->date_stamp(PrintGC && PrintGCDateStamps); TraceCPUTime tcpu(PrintGCDetails, true, gclog_or_tty); - TraceTime t(gc_cause_str, PrintGCDetails, false, gclog_or_tty); + TraceTime t(GCCauseString(gc_cause_prefix, gc_cause()), PrintGCDetails, false, gclog_or_tty); gc_prologue(complete); increment_total_collections(complete); diff --git a/hotspot/src/share/vm/memory/genMarkSweep.cpp b/hotspot/src/share/vm/memory/genMarkSweep.cpp index d5cf4dc7562..4d13fbb22dd 100644 --- a/hotspot/src/share/vm/memory/genMarkSweep.cpp +++ b/hotspot/src/share/vm/memory/genMarkSweep.cpp @@ -76,7 +76,7 @@ void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp, _ref_processor = rp; rp->setup_policy(clear_all_softrefs); - TraceTime t1("Full GC", PrintGC && !PrintGCDetails, true, gclog_or_tty); + TraceTime t1(GCCauseString("Full GC", gch->gc_cause()), PrintGC && !PrintGCDetails, true, gclog_or_tty); // When collecting the permanent generation methodOops may be moving, // so we either have to flush all bcp data or convert it into bci. diff --git a/hotspot/src/share/vm/memory/oopFactory.cpp b/hotspot/src/share/vm/memory/oopFactory.cpp index fcac438bbe3..0dd620650e1 100644 --- a/hotspot/src/share/vm/memory/oopFactory.cpp +++ b/hotspot/src/share/vm/memory/oopFactory.cpp @@ -128,11 +128,12 @@ klassOop oopFactory::new_instanceKlass(Symbol* name, int vtable_len, int itable_ int static_field_size, unsigned int nonstatic_oop_map_count, AccessFlags access_flags, - ReferenceType rt, TRAPS) { + ReferenceType rt, + KlassHandle host_klass, TRAPS) { instanceKlassKlass* ikk = instanceKlassKlass::cast(Universe::instanceKlassKlassObj()); return ikk->allocate_instance_klass(name, vtable_len, itable_len, static_field_size, nonstatic_oop_map_count, - access_flags, rt, CHECK_NULL); + access_flags, rt, host_klass, CHECK_NULL); } diff --git a/hotspot/src/share/vm/memory/oopFactory.hpp b/hotspot/src/share/vm/memory/oopFactory.hpp index 61faf8e3db7..38de1a4f2c2 100644 --- a/hotspot/src/share/vm/memory/oopFactory.hpp +++ b/hotspot/src/share/vm/memory/oopFactory.hpp @@ -78,7 +78,8 @@ class oopFactory: AllStatic { int static_field_size, unsigned int nonstatic_oop_map_count, AccessFlags access_flags, - ReferenceType rt, TRAPS); + ReferenceType rt, + KlassHandle host_klass, TRAPS); // Methods private: diff --git a/hotspot/src/share/vm/memory/space.hpp b/hotspot/src/share/vm/memory/space.hpp index 33b56cf0651..f81c293a4bf 100644 --- a/hotspot/src/share/vm/memory/space.hpp +++ b/hotspot/src/share/vm/memory/space.hpp @@ -880,10 +880,17 @@ class ContiguousSpace: public CompactibleSpace { void object_iterate_mem(MemRegion mr, UpwardsObjectClosure* cl); // iterates on objects up to the safe limit HeapWord* object_iterate_careful(ObjectClosureCareful* cl); - inline HeapWord* concurrent_iteration_safe_limit(); + HeapWord* concurrent_iteration_safe_limit() { + assert(_concurrent_iteration_safe_limit <= top(), + "_concurrent_iteration_safe_limit update missed"); + return _concurrent_iteration_safe_limit; + } // changes the safe limit, all objects from bottom() to the new // limit should be properly initialized - inline void set_concurrent_iteration_safe_limit(HeapWord* new_limit); + void set_concurrent_iteration_safe_limit(HeapWord* new_limit) { + assert(new_limit <= top(), "uninitialized objects in the safe range"); + _concurrent_iteration_safe_limit = new_limit; + } #ifndef SERIALGC // In support of parallel oop_iterate. diff --git a/hotspot/src/share/vm/memory/space.inline.hpp b/hotspot/src/share/vm/memory/space.inline.hpp index 7d62476a69a..07e6127230c 100644 --- a/hotspot/src/share/vm/memory/space.inline.hpp +++ b/hotspot/src/share/vm/memory/space.inline.hpp @@ -67,17 +67,4 @@ OffsetTableContigSpace::block_start_const(const void* p) const { return _offsets.block_start(p); } -inline HeapWord* ContiguousSpace::concurrent_iteration_safe_limit() -{ - assert(_concurrent_iteration_safe_limit <= top(), - "_concurrent_iteration_safe_limit update missed"); - return _concurrent_iteration_safe_limit; -} - -inline void ContiguousSpace::set_concurrent_iteration_safe_limit(HeapWord* new_limit) -{ - assert(new_limit <= top(), "uninitialized objects in the safe range"); - _concurrent_iteration_safe_limit = new_limit; -} - #endif // SHARE_VM_MEMORY_SPACE_INLINE_HPP diff --git a/hotspot/src/share/vm/oops/instanceKlass.cpp b/hotspot/src/share/vm/oops/instanceKlass.cpp index aa5f7765a79..794a7e2809f 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceKlass.cpp @@ -1862,7 +1862,7 @@ void instanceKlass::follow_weak_klass_links( if (impl != NULL) { if (!is_alive->do_object_b(impl)) { // remove this guy - *start_of_implementor() = NULL; + *adr_implementor() = NULL; } } } else { diff --git a/hotspot/src/share/vm/oops/instanceKlass.hpp b/hotspot/src/share/vm/oops/instanceKlass.hpp index 31266375115..dd42bce8628 100644 --- a/hotspot/src/share/vm/oops/instanceKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceKlass.hpp @@ -78,6 +78,7 @@ // The embedded nonstatic oop-map blocks are short pairs (offset, length) // indicating where oops are located in instances of this klass. // [EMBEDDED implementor of the interface] only exist for interface +// [EMBEDDED host klass ] only exist for an anonymous class (JSR 292 enabled) // forward declaration for class -- see below for definition @@ -176,10 +177,6 @@ class instanceKlass: public Klass { oop _class_loader; // Protection domain. oop _protection_domain; - // Host class, which grants its access privileges to this class also. - // This is only non-null for an anonymous class (JSR 292 enabled). - // The host class is either named, or a previously loaded anonymous class. - klassOop _host_klass; // Class signers. objArrayOop _signers; // The InnerClasses attribute and EnclosingMethod attribute. The @@ -234,9 +231,13 @@ class instanceKlass: public Klass { int _nonstatic_oop_map_size;// size in words of nonstatic oop map blocks bool _is_marked_dependent; // used for marking during flushing and deoptimization - bool _rewritten; // methods rewritten. - bool _has_nonstatic_fields; // for sizing with UseCompressedOops - bool _should_verify_class; // allow caching of preverification + 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 _inner_classes field + }; + u2 _misc_flags; u2 _minor_version; // minor version number of class file u2 _major_version; // major version number of class file Thread* _init_thread; // Pointer to current thread doing initialization (to handle recusive initialization) @@ -276,13 +277,29 @@ class instanceKlass: public Klass { // NULL: no implementor. // A klassOop that's not itself: one implementor. // Itsef: more than one implementors. + // embedded host klass follows here + // The embedded host klass only exists in an anonymous class for + // dynamic language support (JSR 292 enabled). The host class grants + // its access privileges to this class also. The host class is either + // named, or a previously loaded anonymous class. A non-anonymous class + // or an anonymous class loaded through normal classloading does not + // have this embedded field. + // friend class instanceKlassKlass; friend class SystemDictionary; public: - bool has_nonstatic_fields() const { return _has_nonstatic_fields; } - void set_has_nonstatic_fields(bool b) { _has_nonstatic_fields = b; } + bool has_nonstatic_fields() const { + return (_misc_flags & _misc_has_nonstatic_fields) != 0; + } + void set_has_nonstatic_fields(bool b) { + if (b) { + _misc_flags |= _misc_has_nonstatic_fields; + } else { + _misc_flags &= ~_misc_has_nonstatic_fields; + } + } // field sizes int nonstatic_field_size() const { return _nonstatic_field_size; } @@ -335,7 +352,7 @@ class instanceKlass: public Klass { int java_fields_count() const { return (int)_java_fields_count; } // Number of fields including any injected fields - int all_fields_count() const { return _fields->length() / sizeof(FieldInfo::field_slots); } + int all_fields_count() const { return _fields->length() / FieldInfo::field_slots; } typeArrayOop fields() const { return _fields; } @@ -396,11 +413,19 @@ class instanceKlass: public Klass { bool is_in_error_state() const { return _init_state == initialization_error; } bool is_reentrant_initialization(Thread *thread) { return thread == _init_thread; } ClassState init_state() { return (ClassState)_init_state; } - bool is_rewritten() const { return _rewritten; } + bool is_rewritten() const { return (_misc_flags & _misc_rewritten) != 0; } // defineClass specified verification - bool should_verify_class() const { return _should_verify_class; } - void set_should_verify_class(bool value) { _should_verify_class = value; } + bool should_verify_class() const { + return (_misc_flags & _misc_should_verify_class) != 0; + } + void set_should_verify_class(bool value) { + if (value) { + _misc_flags |= _misc_should_verify_class; + } else { + _misc_flags &= ~_misc_should_verify_class; + } + } // marking bool is_marked_dependent() const { return _is_marked_dependent; } @@ -469,9 +494,30 @@ class instanceKlass: public Klass { void set_protection_domain(oop pd) { oop_store((oop*) &_protection_domain, pd); } // host class - oop host_klass() const { return _host_klass; } - void set_host_klass(oop host) { oop_store((oop*) &_host_klass, host); } - bool is_anonymous() const { return _host_klass != NULL; } + oop host_klass() const { + oop* hk = adr_host_klass(); + if (hk == NULL) { + return NULL; + } else { + return *hk; + } + } + void set_host_klass(oop host) { + assert(is_anonymous(), "not anonymous"); + oop* addr = adr_host_klass(); + assert(addr != NULL, "no reversed space"); + oop_store(addr, host); + } + bool is_anonymous() const { + return (_misc_flags & _misc_is_anonymous) != 0; + } + void set_is_anonymous(bool value) { + if (value) { + _misc_flags |= _misc_is_anonymous; + } else { + _misc_flags &= ~_misc_is_anonymous; + } + } // signers objArrayOop signers() const { return _signers; } @@ -651,7 +697,7 @@ class instanceKlass: public Klass { // Access to the implementor of an interface. klassOop implementor() const { - klassOop* k = start_of_implementor(); + klassOop* k = (klassOop*)adr_implementor(); if (k == NULL) { return NULL; } else { @@ -661,7 +707,7 @@ class instanceKlass: public Klass { void set_implementor(klassOop k) { assert(is_interface(), "not interface"); - oop* addr = (oop*)start_of_implementor(); + oop* addr = adr_implementor(); oop_store_without_check(addr, k); } @@ -717,9 +763,11 @@ class instanceKlass: public Klass { { return object_size(align_object_offset(vtable_length()) + align_object_offset(itable_length()) + - (is_interface() ? - (align_object_offset(nonstatic_oop_map_size()) + (int)sizeof(klassOop)/HeapWordSize) : - nonstatic_oop_map_size())); + ((is_interface() || is_anonymous()) ? + align_object_offset(nonstatic_oop_map_size()) : + nonstatic_oop_map_size()) + + (is_interface() ? (int)sizeof(klassOop)/HeapWordSize : 0) + + (is_anonymous() ? (int)sizeof(klassOop)/HeapWordSize : 0)); } static int vtable_start_offset() { return header_size(); } static int vtable_length_offset() { return oopDesc::header_size() + offset_of(instanceKlass, _vtable_len) / HeapWordSize; } @@ -737,15 +785,29 @@ class instanceKlass: public Klass { return (OopMapBlock*)(start_of_itable() + align_object_offset(itable_length())); } - klassOop* start_of_implementor() const { + oop* adr_implementor() const { if (is_interface()) { - return (klassOop*)(start_of_nonstatic_oop_maps() + - nonstatic_oop_map_count()); + return (oop*)(start_of_nonstatic_oop_maps() + + nonstatic_oop_map_count()); } else { return NULL; } }; + oop* adr_host_klass() const { + if (is_anonymous()) { + oop* adr_impl = adr_implementor(); + if (adr_impl != NULL) { + return adr_impl + 1; + } else { + return (oop*)(start_of_nonstatic_oop_maps() + + nonstatic_oop_map_count()); + } + } else { + return NULL; + } + } + // Allocation profiling support juint alloc_size() const { return _alloc_count * size_helper(); } void set_alloc_size(juint n) {} @@ -819,7 +881,7 @@ private: #else void set_init_state(ClassState state) { _init_state = (u1)state; } #endif - void set_rewritten() { _rewritten = true; } + void set_rewritten() { _misc_flags |= _misc_rewritten; } void set_init_thread(Thread *thread) { _init_thread = thread; } u2 idnum_allocated_count() const { return _idnum_allocated_count; } @@ -852,10 +914,8 @@ private: oop* adr_constants() const { return (oop*)&this->_constants;} oop* adr_class_loader() const { return (oop*)&this->_class_loader;} oop* adr_protection_domain() const { return (oop*)&this->_protection_domain;} - oop* adr_host_klass() const { return (oop*)&this->_host_klass;} oop* adr_signers() const { return (oop*)&this->_signers;} oop* adr_inner_classes() const { return (oop*)&this->_inner_classes;} - oop* adr_implementor() const { return (oop*)start_of_implementor(); } oop* adr_methods_jmethod_ids() const { return (oop*)&this->_methods_jmethod_ids;} oop* adr_methods_cached_itable_indices() const { return (oop*)&this->_methods_cached_itable_indices;} oop* adr_class_annotations() const { return (oop*)&this->_class_annotations;} diff --git a/hotspot/src/share/vm/oops/instanceKlassKlass.cpp b/hotspot/src/share/vm/oops/instanceKlassKlass.cpp index 808b6e56999..12ea2234451 100644 --- a/hotspot/src/share/vm/oops/instanceKlassKlass.cpp +++ b/hotspot/src/share/vm/oops/instanceKlassKlass.cpp @@ -103,7 +103,9 @@ void instanceKlassKlass::oop_follow_contents(oop obj) { MarkSweep::mark_and_push(ik->adr_class_loader()); MarkSweep::mark_and_push(ik->adr_inner_classes()); MarkSweep::mark_and_push(ik->adr_protection_domain()); - MarkSweep::mark_and_push(ik->adr_host_klass()); + if (ik->adr_host_klass() != NULL) { + MarkSweep::mark_and_push(ik->adr_host_klass()); + } MarkSweep::mark_and_push(ik->adr_signers()); MarkSweep::mark_and_push(ik->adr_class_annotations()); MarkSweep::mark_and_push(ik->adr_fields_annotations()); @@ -139,7 +141,9 @@ void instanceKlassKlass::oop_follow_contents(ParCompactionManager* cm, PSParallelCompact::mark_and_push(cm, ik->adr_class_loader()); PSParallelCompact::mark_and_push(cm, ik->adr_inner_classes()); PSParallelCompact::mark_and_push(cm, ik->adr_protection_domain()); - PSParallelCompact::mark_and_push(cm, ik->adr_host_klass()); + if (ik->adr_host_klass() != NULL) { + PSParallelCompact::mark_and_push(cm, ik->adr_host_klass()); + } PSParallelCompact::mark_and_push(cm, ik->adr_signers()); PSParallelCompact::mark_and_push(cm, ik->adr_class_annotations()); PSParallelCompact::mark_and_push(cm, ik->adr_fields_annotations()); @@ -177,10 +181,12 @@ int instanceKlassKlass::oop_oop_iterate(oop obj, OopClosure* blk) { blk->do_oop(ik->adr_constants()); blk->do_oop(ik->adr_class_loader()); blk->do_oop(ik->adr_protection_domain()); - blk->do_oop(ik->adr_host_klass()); + if (ik->adr_host_klass() != NULL) { + blk->do_oop(ik->adr_host_klass()); + } blk->do_oop(ik->adr_signers()); blk->do_oop(ik->adr_inner_classes()); - if (ik->is_interface()) { + if (ik->adr_implementor() != NULL) { blk->do_oop(ik->adr_implementor()); } blk->do_oop(ik->adr_class_annotations()); @@ -227,15 +233,13 @@ int instanceKlassKlass::oop_oop_iterate_m(oop obj, OopClosure* blk, adr = ik->adr_protection_domain(); if (mr.contains(adr)) blk->do_oop(adr); adr = ik->adr_host_klass(); - if (mr.contains(adr)) blk->do_oop(adr); + if (adr != NULL && mr.contains(adr)) blk->do_oop(adr); adr = ik->adr_signers(); if (mr.contains(adr)) blk->do_oop(adr); adr = ik->adr_inner_classes(); if (mr.contains(adr)) blk->do_oop(adr); - if (ik->is_interface()) { - adr = ik->adr_implementor(); - if (mr.contains(adr)) blk->do_oop(adr); - } + adr = ik->adr_implementor(); + if (adr != NULL && mr.contains(adr)) blk->do_oop(adr); adr = ik->adr_class_annotations(); if (mr.contains(adr)) blk->do_oop(adr); adr = ik->adr_fields_annotations(); @@ -270,10 +274,12 @@ int instanceKlassKlass::oop_adjust_pointers(oop obj) { MarkSweep::adjust_pointer(ik->adr_constants()); MarkSweep::adjust_pointer(ik->adr_class_loader()); MarkSweep::adjust_pointer(ik->adr_protection_domain()); - MarkSweep::adjust_pointer(ik->adr_host_klass()); + if (ik->adr_host_klass() != NULL) { + MarkSweep::adjust_pointer(ik->adr_host_klass()); + } MarkSweep::adjust_pointer(ik->adr_signers()); MarkSweep::adjust_pointer(ik->adr_inner_classes()); - if (ik->is_interface()) { + if (ik->adr_implementor() != NULL) { MarkSweep::adjust_pointer(ik->adr_implementor()); } MarkSweep::adjust_pointer(ik->adr_class_annotations()); @@ -302,7 +308,7 @@ void instanceKlassKlass::oop_push_contents(PSPromotionManager* pm, oop obj) { } oop* hk_addr = ik->adr_host_klass(); - if (PSScavenge::should_scavenge(hk_addr)) { + if (hk_addr != NULL && PSScavenge::should_scavenge(hk_addr)) { pm->claim_or_forward_depth(hk_addr); } @@ -328,9 +334,13 @@ int instanceKlassKlass::oop_update_pointers(ParCompactionManager* cm, oop obj) { for (oop* cur_oop = beg_oop; cur_oop < end_oop; ++cur_oop) { PSParallelCompact::adjust_pointer(cur_oop); } - if (ik->is_interface()) { + // embedded oops + if (ik->adr_implementor() != NULL) { PSParallelCompact::adjust_pointer(ik->adr_implementor()); } + if (ik->adr_host_klass() != NULL) { + PSParallelCompact::adjust_pointer(ik->adr_host_klass()); + } OopClosure* closure = PSParallelCompact::adjust_root_pointer_closure(); iterate_c_heap_oops(ik, closure); @@ -346,16 +356,23 @@ instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int it int static_field_size, unsigned nonstatic_oop_map_count, AccessFlags access_flags, - ReferenceType rt, TRAPS) { + ReferenceType rt, + KlassHandle host_klass, TRAPS) { const int nonstatic_oop_map_size = instanceKlass::nonstatic_oop_map_size(nonstatic_oop_map_count); int size = align_object_offset(vtable_len) + align_object_offset(itable_len); - if (access_flags.is_interface()) { - size += align_object_offset(nonstatic_oop_map_size) + (int)sizeof(klassOop)/HeapWordSize; + if (access_flags.is_interface() || !host_klass.is_null()) { + size += align_object_offset(nonstatic_oop_map_size); } else { size += nonstatic_oop_map_size; } + if (access_flags.is_interface()) { + size += (int)sizeof(klassOop)/HeapWordSize; + } + if (!host_klass.is_null()) { + size += (int)sizeof(klassOop)/HeapWordSize; + } size = instanceKlass::object_size(size); // Allocation @@ -389,6 +406,7 @@ instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int it ik->set_static_field_size(static_field_size); ik->set_nonstatic_oop_map_size(nonstatic_oop_map_size); ik->set_access_flags(access_flags); + ik->set_is_anonymous(!host_klass.is_null()); assert(k()->size() == size, "wrong size for object"); ik->set_array_klasses(NULL); @@ -401,7 +419,6 @@ instanceKlassKlass::allocate_instance_klass(Symbol* name, int vtable_len, int it ik->set_constants(NULL); ik->set_class_loader(NULL); ik->set_protection_domain(NULL); - ik->set_host_klass(NULL); ik->set_signers(NULL); ik->set_source_file_name(NULL); ik->set_source_debug_extension(NULL); @@ -503,7 +520,9 @@ void instanceKlassKlass::oop_print_on(oop obj, outputStream* st) { st->print(BULLET"constants: "); ik->constants()->print_value_on(st); st->cr(); st->print(BULLET"class loader: "); ik->class_loader()->print_value_on(st); st->cr(); st->print(BULLET"protection domain: "); ik->protection_domain()->print_value_on(st); st->cr(); - st->print(BULLET"host class: "); ik->host_klass()->print_value_on(st); st->cr(); + if (ik->host_klass() != NULL) { + st->print(BULLET"host class: "); ik->host_klass()->print_value_on(st); st->cr(); + } st->print(BULLET"signers: "); ik->signers()->print_value_on(st); st->cr(); if (ik->source_file_name() != NULL) { st->print(BULLET"source file: "); diff --git a/hotspot/src/share/vm/oops/instanceKlassKlass.hpp b/hotspot/src/share/vm/oops/instanceKlassKlass.hpp index ced9451da58..e360d134dbe 100644 --- a/hotspot/src/share/vm/oops/instanceKlassKlass.hpp +++ b/hotspot/src/share/vm/oops/instanceKlassKlass.hpp @@ -48,6 +48,7 @@ class instanceKlassKlass : public klassKlass { unsigned int nonstatic_oop_map_count, AccessFlags access_flags, ReferenceType rt, + KlassHandle host_klass, TRAPS); // Casting from klassOop diff --git a/hotspot/src/share/vm/opto/callGenerator.cpp b/hotspot/src/share/vm/opto/callGenerator.cpp index 6455c812567..26153217d07 100644 --- a/hotspot/src/share/vm/opto/callGenerator.cpp +++ b/hotspot/src/share/vm/opto/callGenerator.cpp @@ -137,6 +137,7 @@ JVMState* DirectCallGenerator::generate(JVMState* jvms) { } CallStaticJavaNode *call = new (kit.C, tf()->domain()->cnt()) CallStaticJavaNode(tf(), target, method(), kit.bci()); + _call_node = call; // Save the call node in case we need it later if (!is_static) { // Make an explicit receiver null_check as part of this call. // Since we share a map with the caller, his JVMS gets adjusted. @@ -155,7 +156,6 @@ JVMState* DirectCallGenerator::generate(JVMState* jvms) { kit.set_edges_for_java_call(call, false, _separate_io_proj); Node* ret = kit.set_results_for_java_call(call, _separate_io_proj); kit.push_node(method()->return_type()->basic_type(), ret); - _call_node = call; // Save the call node in case we need it later return kit.transfer_exceptions_into_jvms(); } diff --git a/hotspot/src/share/vm/opto/graphKit.cpp b/hotspot/src/share/vm/opto/graphKit.cpp index 61d922760c5..b3dca953133 100644 --- a/hotspot/src/share/vm/opto/graphKit.cpp +++ b/hotspot/src/share/vm/opto/graphKit.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2012, 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 @@ -3748,3 +3748,81 @@ void GraphKit::g1_write_barrier_post(Node* oop_store, final_sync(ideal); } #undef __ + + + +Node* GraphKit::load_String_offset(Node* ctrl, Node* str) { + if (java_lang_String::has_offset_field()) { + int offset_offset = java_lang_String::offset_offset_in_bytes(); + const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), + false, NULL, 0); + const TypePtr* offset_field_type = string_type->add_offset(offset_offset); + int offset_field_idx = C->get_alias_index(offset_field_type); + return make_load(ctrl, + basic_plus_adr(str, str, offset_offset), + TypeInt::INT, T_INT, offset_field_idx); + } else { + return intcon(0); + } +} + +Node* GraphKit::load_String_length(Node* ctrl, Node* str) { + if (java_lang_String::has_count_field()) { + int count_offset = java_lang_String::count_offset_in_bytes(); + const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), + false, NULL, 0); + const TypePtr* count_field_type = string_type->add_offset(count_offset); + int count_field_idx = C->get_alias_index(count_field_type); + return make_load(ctrl, + basic_plus_adr(str, str, count_offset), + TypeInt::INT, T_INT, count_field_idx); + } else { + return load_array_length(load_String_value(ctrl, str)); + } +} + +Node* GraphKit::load_String_value(Node* ctrl, Node* str) { + int value_offset = java_lang_String::value_offset_in_bytes(); + const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), + false, NULL, 0); + const TypePtr* value_field_type = string_type->add_offset(value_offset); + const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull, + TypeAry::make(TypeInt::CHAR,TypeInt::POS), + ciTypeArrayKlass::make(T_CHAR), true, 0); + int value_field_idx = C->get_alias_index(value_field_type); + return make_load(ctrl, basic_plus_adr(str, str, value_offset), + value_type, T_OBJECT, value_field_idx); +} + +void GraphKit::store_String_offset(Node* ctrl, Node* str, Node* value) { + int offset_offset = java_lang_String::offset_offset_in_bytes(); + const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), + false, NULL, 0); + const TypePtr* offset_field_type = string_type->add_offset(offset_offset); + int offset_field_idx = C->get_alias_index(offset_field_type); + store_to_memory(ctrl, basic_plus_adr(str, offset_offset), + value, T_INT, offset_field_idx); +} + +void GraphKit::store_String_value(Node* ctrl, Node* str, Node* value) { + int value_offset = java_lang_String::value_offset_in_bytes(); + const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), + false, NULL, 0); + const TypePtr* value_field_type = string_type->add_offset(value_offset); + const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull, + TypeAry::make(TypeInt::CHAR,TypeInt::POS), + ciTypeArrayKlass::make(T_CHAR), true, 0); + int value_field_idx = C->get_alias_index(value_field_type); + store_to_memory(ctrl, basic_plus_adr(str, value_offset), + value, T_OBJECT, value_field_idx); +} + +void GraphKit::store_String_length(Node* ctrl, Node* str, Node* value) { + int count_offset = java_lang_String::count_offset_in_bytes(); + const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), + false, NULL, 0); + const TypePtr* count_field_type = string_type->add_offset(count_offset); + int count_field_idx = C->get_alias_index(count_field_type); + store_to_memory(ctrl, basic_plus_adr(str, count_offset), + value, T_INT, count_field_idx); +} diff --git a/hotspot/src/share/vm/opto/graphKit.hpp b/hotspot/src/share/vm/opto/graphKit.hpp index bffebc8798e..723e65e3b05 100644 --- a/hotspot/src/share/vm/opto/graphKit.hpp +++ b/hotspot/src/share/vm/opto/graphKit.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2012, 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 @@ -781,6 +781,14 @@ class GraphKit : public Phase { Node* new_array(Node* klass_node, Node* count_val, int nargs, Node* *return_size_val = NULL); + // java.lang.String helpers + Node* load_String_offset(Node* ctrl, Node* str); + Node* load_String_length(Node* ctrl, Node* str); + Node* load_String_value(Node* ctrl, Node* str); + void store_String_offset(Node* ctrl, Node* str, Node* value); + void store_String_length(Node* ctrl, Node* str, Node* value); + void store_String_value(Node* ctrl, Node* str, Node* value); + // Handy for making control flow IfNode* create_and_map_if(Node* ctrl, Node* tst, float prob, float cnt) { IfNode* iff = new (C, 2) IfNode(ctrl, tst, prob, cnt);// New IfNode's diff --git a/hotspot/src/share/vm/opto/library_call.cpp b/hotspot/src/share/vm/opto/library_call.cpp index 13c3a4327ce..e0f5f95915f 100644 --- a/hotspot/src/share/vm/opto/library_call.cpp +++ b/hotspot/src/share/vm/opto/library_call.cpp @@ -147,7 +147,8 @@ class LibraryCallKit : public GraphKit { return generate_method_call(method_id, true, false); } - Node* make_string_method_node(int opcode, Node* str1, Node* cnt1, Node* str2, Node* cnt2); + Node* make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2); + Node* make_string_method_node(int opcode, Node* str1, Node* str2); bool inline_string_compareTo(); bool inline_string_indexOf(); Node* string_indexOf(Node* string_object, ciTypeArray* target_array, jint offset, jint cache_i, jint md2_i); @@ -873,48 +874,76 @@ Node* LibraryCallKit::generate_current_thread(Node* &tls_output) { //------------------------------make_string_method_node------------------------ -// Helper method for String intrinsic finctions. -Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1, Node* cnt1, Node* str2, Node* cnt2) { - const int value_offset = java_lang_String::value_offset_in_bytes(); - const int count_offset = java_lang_String::count_offset_in_bytes(); - const int offset_offset = java_lang_String::offset_offset_in_bytes(); - +// Helper method for String intrinsic functions. This version is called +// with str1 and str2 pointing to String object nodes. +// +Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1, Node* str2) { Node* no_ctrl = NULL; - ciInstanceKlass* klass = env()->String_klass(); - const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); - - const TypeAryPtr* value_type = - TypeAryPtr::make(TypePtr::NotNull, - TypeAry::make(TypeInt::CHAR,TypeInt::POS), - ciTypeArrayKlass::make(T_CHAR), true, 0); - - // Get start addr of string and substring - Node* str1_valuea = basic_plus_adr(str1, str1, value_offset); - Node* str1_value = make_load(no_ctrl, str1_valuea, value_type, T_OBJECT, string_type->add_offset(value_offset)); - Node* str1_offseta = basic_plus_adr(str1, str1, offset_offset); - Node* str1_offset = make_load(no_ctrl, str1_offseta, TypeInt::INT, T_INT, string_type->add_offset(offset_offset)); + // Get start addr of string + Node* str1_value = load_String_value(no_ctrl, str1); + Node* str1_offset = load_String_offset(no_ctrl, str1); Node* str1_start = array_element_address(str1_value, str1_offset, T_CHAR); - Node* str2_valuea = basic_plus_adr(str2, str2, value_offset); - Node* str2_value = make_load(no_ctrl, str2_valuea, value_type, T_OBJECT, string_type->add_offset(value_offset)); - Node* str2_offseta = basic_plus_adr(str2, str2, offset_offset); - Node* str2_offset = make_load(no_ctrl, str2_offseta, TypeInt::INT, T_INT, string_type->add_offset(offset_offset)); + // Get length of string 1 + Node* str1_len = load_String_length(no_ctrl, str1); + + Node* str2_value = load_String_value(no_ctrl, str2); + Node* str2_offset = load_String_offset(no_ctrl, str2); Node* str2_start = array_element_address(str2_value, str2_offset, T_CHAR); + Node* str2_len = NULL; + Node* result = NULL; + + switch (opcode) { + case Op_StrIndexOf: + // Get length of string 2 + str2_len = load_String_length(no_ctrl, str2); + + result = new (C, 6) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS), + str1_start, str1_len, str2_start, str2_len); + break; + case Op_StrComp: + // Get length of string 2 + str2_len = load_String_length(no_ctrl, str2); + + result = new (C, 6) StrCompNode(control(), memory(TypeAryPtr::CHARS), + str1_start, str1_len, str2_start, str2_len); + break; + case Op_StrEquals: + result = new (C, 5) StrEqualsNode(control(), memory(TypeAryPtr::CHARS), + str1_start, str2_start, str1_len); + break; + default: + ShouldNotReachHere(); + return NULL; + } + + // All these intrinsics have checks. + C->set_has_split_ifs(true); // Has chance for split-if optimization + + return _gvn.transform(result); +} + +// Helper method for String intrinsic functions. This version is called +// with str1 and str2 pointing to char[] nodes, with cnt1 and cnt2 pointing +// to Int nodes containing the lenghts of str1 and str2. +// +Node* LibraryCallKit::make_string_method_node(int opcode, Node* str1_start, Node* cnt1, Node* str2_start, Node* cnt2) { + Node* result = NULL; switch (opcode) { case Op_StrIndexOf: result = new (C, 6) StrIndexOfNode(control(), memory(TypeAryPtr::CHARS), - str1_start, cnt1, str2_start, cnt2); + str1_start, cnt1, str2_start, cnt2); break; case Op_StrComp: result = new (C, 6) StrCompNode(control(), memory(TypeAryPtr::CHARS), - str1_start, cnt1, str2_start, cnt2); + str1_start, cnt1, str2_start, cnt2); break; case Op_StrEquals: result = new (C, 5) StrEqualsNode(control(), memory(TypeAryPtr::CHARS), - str1_start, str2_start, cnt1); + str1_start, str2_start, cnt1); break; default: ShouldNotReachHere(); @@ -932,10 +961,6 @@ bool LibraryCallKit::inline_string_compareTo() { if (!Matcher::has_match_rule(Op_StrComp)) return false; - const int value_offset = java_lang_String::value_offset_in_bytes(); - const int count_offset = java_lang_String::count_offset_in_bytes(); - const int offset_offset = java_lang_String::offset_offset_in_bytes(); - _sp += 2; Node *argument = pop(); // pop non-receiver first: it was pushed second Node *receiver = pop(); @@ -952,18 +977,7 @@ bool LibraryCallKit::inline_string_compareTo() { return true; } - ciInstanceKlass* klass = env()->String_klass(); - const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); - Node* no_ctrl = NULL; - - // Get counts for string and argument - Node* receiver_cnta = basic_plus_adr(receiver, receiver, count_offset); - Node* receiver_cnt = make_load(no_ctrl, receiver_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); - - Node* argument_cnta = basic_plus_adr(argument, argument, count_offset); - Node* argument_cnt = make_load(no_ctrl, argument_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); - - Node* compare = make_string_method_node(Op_StrComp, receiver, receiver_cnt, argument, argument_cnt); + Node* compare = make_string_method_node(Op_StrComp, receiver, argument); push(compare); return true; } @@ -973,10 +987,6 @@ bool LibraryCallKit::inline_string_equals() { if (!Matcher::has_match_rule(Op_StrEquals)) return false; - const int value_offset = java_lang_String::value_offset_in_bytes(); - const int count_offset = java_lang_String::count_offset_in_bytes(); - const int offset_offset = java_lang_String::offset_offset_in_bytes(); - int nargs = 2; _sp += nargs; Node* argument = pop(); // pop non-receiver first: it was pushed second @@ -1030,24 +1040,31 @@ bool LibraryCallKit::inline_string_equals() { } } - const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); - - Node* no_ctrl = NULL; - Node* receiver_cnt; - Node* argument_cnt; - if (!stopped()) { + const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); + // Properly cast the argument to String argument = _gvn.transform(new (C, 2) CheckCastPPNode(control(), argument, string_type)); // This path is taken only when argument's type is String:NotNull. argument = cast_not_null(argument, false); - // Get counts for string and argument - Node* receiver_cnta = basic_plus_adr(receiver, receiver, count_offset); - receiver_cnt = make_load(no_ctrl, receiver_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); + Node* no_ctrl = NULL; - Node* argument_cnta = basic_plus_adr(argument, argument, count_offset); - argument_cnt = make_load(no_ctrl, argument_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); + // Get start addr of receiver + Node* receiver_val = load_String_value(no_ctrl, receiver); + Node* receiver_offset = load_String_offset(no_ctrl, receiver); + Node* receiver_start = array_element_address(receiver_val, receiver_offset, T_CHAR); + + // Get length of receiver + Node* receiver_cnt = load_String_length(no_ctrl, receiver); + + // Get start addr of argument + Node* argument_val = load_String_value(no_ctrl, argument); + Node* argument_offset = load_String_offset(no_ctrl, argument); + Node* argument_start = array_element_address(argument_val, argument_offset, T_CHAR); + + // Get length of argument + Node* argument_cnt = load_String_length(no_ctrl, argument); // Check for receiver count != argument count Node* cmp = _gvn.transform( new(C, 3) CmpINode(receiver_cnt, argument_cnt) ); @@ -1057,14 +1074,14 @@ bool LibraryCallKit::inline_string_equals() { phi->init_req(4, intcon(0)); region->init_req(4, if_ne); } - } - // Check for count == 0 is done by mach node StrEquals. + // Check for count == 0 is done by assembler code for StrEquals. - if (!stopped()) { - Node* equals = make_string_method_node(Op_StrEquals, receiver, receiver_cnt, argument, argument_cnt); - phi->init_req(1, equals); - region->init_req(1, control()); + if (!stopped()) { + Node* equals = make_string_method_node(Op_StrEquals, receiver_start, receiver_cnt, argument_start, argument_cnt); + phi->init_req(1, equals); + region->init_req(1, control()); + } } // post merge @@ -1162,20 +1179,9 @@ Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_ar const int nargs = 2; // number of arguments to push back for uncommon trap in predicate - const int value_offset = java_lang_String::value_offset_in_bytes(); - const int count_offset = java_lang_String::count_offset_in_bytes(); - const int offset_offset = java_lang_String::offset_offset_in_bytes(); - - ciInstanceKlass* klass = env()->String_klass(); - const TypeOopPtr* string_type = TypeOopPtr::make_from_klass(klass); - const TypeAryPtr* source_type = TypeAryPtr::make(TypePtr::NotNull, TypeAry::make(TypeInt::CHAR,TypeInt::POS), ciTypeArrayKlass::make(T_CHAR), true, 0); - - Node* sourceOffseta = basic_plus_adr(string_object, string_object, offset_offset); - Node* sourceOffset = make_load(no_ctrl, sourceOffseta, TypeInt::INT, T_INT, string_type->add_offset(offset_offset)); - Node* sourceCounta = basic_plus_adr(string_object, string_object, count_offset); - Node* sourceCount = make_load(no_ctrl, sourceCounta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); - Node* sourcea = basic_plus_adr(string_object, string_object, value_offset); - Node* source = make_load(no_ctrl, sourcea, source_type, T_OBJECT, string_type->add_offset(value_offset)); + Node* source = load_String_value(no_ctrl, string_object); + Node* sourceOffset = load_String_offset(no_ctrl, string_object); + Node* sourceCount = load_String_length(no_ctrl, string_object); Node* target = _gvn.transform( makecon(TypeOopPtr::make_from_constant(target_array, true)) ); jint target_length = target_array->length(); @@ -1243,10 +1249,6 @@ Node* LibraryCallKit::string_indexOf(Node* string_object, ciTypeArray* target_ar //------------------------------inline_string_indexOf------------------------ bool LibraryCallKit::inline_string_indexOf() { - const int value_offset = java_lang_String::value_offset_in_bytes(); - const int count_offset = java_lang_String::count_offset_in_bytes(); - const int offset_offset = java_lang_String::offset_offset_in_bytes(); - _sp += 2; Node *argument = pop(); // pop non-receiver first: it was pushed second Node *receiver = pop(); @@ -1280,12 +1282,21 @@ bool LibraryCallKit::inline_string_indexOf() { Node* result_phi = new (C, 4) PhiNode(result_rgn, TypeInt::INT); Node* no_ctrl = NULL; - // Get counts for string and substr - Node* source_cnta = basic_plus_adr(receiver, receiver, count_offset); - Node* source_cnt = make_load(no_ctrl, source_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); + // Get start addr of source string + Node* source = load_String_value(no_ctrl, receiver); + Node* source_offset = load_String_offset(no_ctrl, receiver); + Node* source_start = array_element_address(source, source_offset, T_CHAR); - Node* substr_cnta = basic_plus_adr(argument, argument, count_offset); - Node* substr_cnt = make_load(no_ctrl, substr_cnta, TypeInt::INT, T_INT, string_type->add_offset(count_offset)); + // Get length of source string + Node* source_cnt = load_String_length(no_ctrl, receiver); + + // Get start addr of substring + Node* substr = load_String_value(no_ctrl, argument); + Node* substr_offset = load_String_offset(no_ctrl, argument); + Node* substr_start = array_element_address(substr, substr_offset, T_CHAR); + + // Get length of source string + Node* substr_cnt = load_String_length(no_ctrl, argument); // Check for substr count > string count Node* cmp = _gvn.transform( new(C, 3) CmpINode(substr_cnt, source_cnt) ); @@ -1308,7 +1319,7 @@ bool LibraryCallKit::inline_string_indexOf() { } if (!stopped()) { - result = make_string_method_node(Op_StrIndexOf, receiver, source_cnt, argument, substr_cnt); + result = make_string_method_node(Op_StrIndexOf, source_start, source_cnt, substr_start, substr_cnt); result_phi->init_req(1, result); result_rgn->init_req(1, control()); } @@ -1333,11 +1344,19 @@ bool LibraryCallKit::inline_string_indexOf() { ciInstance* str = str_const->as_instance(); assert(str != NULL, "must be instance"); - ciObject* v = str->field_value_by_offset(value_offset).as_object(); - int o = str->field_value_by_offset(offset_offset).as_int(); - int c = str->field_value_by_offset(count_offset).as_int(); + ciObject* v = str->field_value_by_offset(java_lang_String::value_offset_in_bytes()).as_object(); ciTypeArray* pat = v->as_type_array(); // pattern (argument) character array + int o; + int c; + if (java_lang_String::has_offset_field()) { + o = str->field_value_by_offset(java_lang_String::offset_offset_in_bytes()).as_int(); + c = str->field_value_by_offset(java_lang_String::count_offset_in_bytes()).as_int(); + } else { + o = 0; + c = pat->length(); + } + // constant strings have no offset and count == length which // simplifies the resulting code somewhat so lets optimize for that. if (o != 0 || c != pat->length()) { diff --git a/hotspot/src/share/vm/opto/stringopts.cpp b/hotspot/src/share/vm/opto/stringopts.cpp index f3220f2cceb..99498ea9598 100644 --- a/hotspot/src/share/vm/opto/stringopts.cpp +++ b/hotspot/src/share/vm/opto/stringopts.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2012, 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 @@ -528,16 +528,6 @@ PhaseStringOpts::PhaseStringOpts(PhaseGVN* gvn, Unique_Node_List*): } // Collect the types needed to talk about the various slices of memory - const TypeInstPtr* string_type = TypeInstPtr::make(TypePtr::NotNull, C->env()->String_klass(), - false, NULL, 0); - - const TypePtr* value_field_type = string_type->add_offset(java_lang_String::value_offset_in_bytes()); - const TypePtr* offset_field_type = string_type->add_offset(java_lang_String::offset_offset_in_bytes()); - const TypePtr* count_field_type = string_type->add_offset(java_lang_String::count_offset_in_bytes()); - - value_field_idx = C->get_alias_index(value_field_type); - count_field_idx = C->get_alias_index(count_field_type); - offset_field_idx = C->get_alias_index(offset_field_type); char_adr_idx = C->get_alias_index(TypeAryPtr::CHARS); // For each locally allocated StringBuffer see if the usages can be @@ -897,8 +887,8 @@ bool StringConcat::validate_control_flow() { } Node* PhaseStringOpts::fetch_static_field(GraphKit& kit, ciField* field) { - const TypeKlassPtr* klass_type = TypeKlassPtr::make(field->holder()); - Node* klass_node = __ makecon(klass_type); + const TypeInstPtr* mirror_type = TypeInstPtr::make(field->holder()->java_mirror()); + Node* klass_node = __ makecon(mirror_type); BasicType bt = field->layout_type(); ciType* field_klass = field->type(); @@ -913,6 +903,7 @@ Node* PhaseStringOpts::fetch_static_field(GraphKit& kit, ciField* field) { // and may yield a vacuous result if the field is of interface type. type = TypeOopPtr::make_from_constant(con, true)->isa_oopptr(); assert(type != NULL, "field singleton type must be consistent"); + return __ makecon(type); } else { type = TypeOopPtr::make_from_klass(field_klass->as_klass()); } @@ -922,7 +913,7 @@ Node* PhaseStringOpts::fetch_static_field(GraphKit& kit, ciField* field) { return kit.make_load(NULL, kit.basic_plus_adr(klass_node, field->offset_in_bytes()), type, T_OBJECT, - C->get_alias_index(klass_type->add_offset(field->offset_in_bytes()))); + C->get_alias_index(mirror_type->add_offset(field->offset_in_bytes()))); } Node* PhaseStringOpts::int_stringSize(GraphKit& kit, Node* arg) { @@ -1173,18 +1164,9 @@ void PhaseStringOpts::int_getChars(GraphKit& kit, Node* arg, Node* char_array, N Node* PhaseStringOpts::copy_string(GraphKit& kit, Node* str, Node* char_array, Node* start) { Node* string = str; - Node* offset = kit.make_load(kit.control(), - kit.basic_plus_adr(string, string, java_lang_String::offset_offset_in_bytes()), - TypeInt::INT, T_INT, offset_field_idx); - Node* count = kit.make_load(kit.control(), - kit.basic_plus_adr(string, string, java_lang_String::count_offset_in_bytes()), - TypeInt::INT, T_INT, count_field_idx); - const TypeAryPtr* value_type = TypeAryPtr::make(TypePtr::NotNull, - TypeAry::make(TypeInt::CHAR,TypeInt::POS), - ciTypeArrayKlass::make(T_CHAR), true, 0); - Node* value = kit.make_load(kit.control(), - kit.basic_plus_adr(string, string, java_lang_String::value_offset_in_bytes()), - value_type, T_OBJECT, value_field_idx); + Node* offset = kit.load_String_offset(kit.control(), string); + Node* count = kit.load_String_length(kit.control(), string); + Node* value = kit.load_String_value (kit.control(), string); // copy the contents if (offset->is_Con() && count->is_Con() && value->is_Con() && count->get_int() < unroll_string_copy_length) { @@ -1341,10 +1323,9 @@ void PhaseStringOpts::replace_string_concat(StringConcat* sc) { arg = phi; sc->set_argument(argi, arg); } - // Node* offset = kit.make_load(NULL, kit.basic_plus_adr(arg, arg, offset_offset), - // TypeInt::INT, T_INT, offset_field_idx); - Node* count = kit.make_load(kit.control(), kit.basic_plus_adr(arg, arg, java_lang_String::count_offset_in_bytes()), - TypeInt::INT, T_INT, count_field_idx); + + Node* count = kit.load_String_length(kit.control(), arg); + length = __ AddI(length, count); string_sizes->init_req(argi, NULL); break; @@ -1435,12 +1416,11 @@ void PhaseStringOpts::replace_string_concat(StringConcat* sc) { } // Intialize the string - kit.store_to_memory(kit.control(), kit.basic_plus_adr(result, java_lang_String::offset_offset_in_bytes()), - __ intcon(0), T_INT, offset_field_idx); - kit.store_to_memory(kit.control(), kit.basic_plus_adr(result, java_lang_String::count_offset_in_bytes()), - length, T_INT, count_field_idx); - kit.store_to_memory(kit.control(), kit.basic_plus_adr(result, java_lang_String::value_offset_in_bytes()), - char_array, T_OBJECT, value_field_idx); + if (java_lang_String::has_offset_field()) { + kit.store_String_offset(kit.control(), result, __ intcon(0)); + kit.store_String_length(kit.control(), result, length); + } + kit.store_String_value(kit.control(), result, char_array); // hook up the outgoing control and result kit.replace_call(sc->end(), result); diff --git a/hotspot/src/share/vm/opto/stringopts.hpp b/hotspot/src/share/vm/opto/stringopts.hpp index 1ffe6c3092d..0fb1ed70f64 100644 --- a/hotspot/src/share/vm/opto/stringopts.hpp +++ b/hotspot/src/share/vm/opto/stringopts.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2012, 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 @@ -41,9 +41,6 @@ class PhaseStringOpts : public Phase { // Memory slices needed for code gen int char_adr_idx; - int value_field_idx; - int count_field_idx; - int offset_field_idx; // Integer.sizeTable - used for int to String conversion ciField* size_table_field; diff --git a/hotspot/src/share/vm/opto/superword.cpp b/hotspot/src/share/vm/opto/superword.cpp index d1d1e1cb91c..28c4cfe4153 100644 --- a/hotspot/src/share/vm/opto/superword.cpp +++ b/hotspot/src/share/vm/opto/superword.cpp @@ -1221,12 +1221,11 @@ Node* SuperWord::vector_opd(Node_List* p, int opd_idx) { return opd; // input is matching vector } assert(!opd->is_VectorStore(), "such vector is not expected here"); - // Convert scalar input to vector. Use p0's type because it's container - // maybe smaller than the operand's container. - const Type* opd_t = velt_type(!in_bb(opd) ? p0 : opd); - const Type* p0_t = velt_type(p0); - if (p0_t->higher_equal(opd_t)) opd_t = p0_t; - VectorNode* vn = VectorNode::scalar2vector(_phase->C, opd, vlen, opd_t); + // Convert scalar input to vector with the same number of elements as + // p0's vector. Use p0's type because size of operand's container in + // vector should match p0's size regardless operand's size. + const Type* p0_t = velt_type(p0); + VectorNode* vn = VectorNode::scalar2vector(_phase->C, opd, vlen, p0_t); _phase->_igvn.register_new_node_with_optimizer(vn); _phase->set_ctrl(vn, _phase->get_ctrl(opd)); @@ -1234,14 +1233,15 @@ Node* SuperWord::vector_opd(Node_List* p, int opd_idx) { } // Insert pack operation - const Type* opd_t = velt_type(!in_bb(opd) ? p0 : opd); - PackNode* pk = PackNode::make(_phase->C, opd, opd_t); + const Type* p0_t = velt_type(p0); + PackNode* pk = PackNode::make(_phase->C, opd, p0_t); + DEBUG_ONLY( const BasicType opd_bt = opd->bottom_type()->basic_type(); ) for (uint i = 1; i < vlen; i++) { Node* pi = p->at(i); Node* in = pi->in(opd_idx); assert(my_pack(in) == NULL, "Should already have been unpacked"); - assert(opd_t == velt_type(!in_bb(in) ? pi : in), "all same type"); + assert(opd_bt == in->bottom_type()->basic_type(), "all same type"); pk->add_opd(in); } _phase->_igvn.register_new_node_with_optimizer(pk); diff --git a/hotspot/src/share/vm/runtime/arguments.cpp b/hotspot/src/share/vm/runtime/arguments.cpp index 8deacc6f564..d319fddfe51 100644 --- a/hotspot/src/share/vm/runtime/arguments.cpp +++ b/hotspot/src/share/vm/runtime/arguments.cpp @@ -3039,7 +3039,7 @@ jint Arguments::parse(const JavaVMInitArgs* args) { return result; } -#ifdef JAVASE_EMBEDDED +#if (defined JAVASE_EMBEDDED || defined ARM) UNSUPPORTED_OPTION(UseG1GC, "G1 GC"); #endif @@ -3092,6 +3092,14 @@ jint Arguments::parse(const JavaVMInitArgs* args) { PrintGC = true; } + if (!JDK_Version::is_gte_jdk18x_version()) { + // To avoid changing the log format for 7 updates this flag is only + // true by default in JDK8 and above. + if (FLAG_IS_DEFAULT(PrintGCCause)) { + FLAG_SET_DEFAULT(PrintGCCause, false); + } + } + // Set object alignment values. set_object_alignment(); diff --git a/hotspot/src/share/vm/runtime/globals.cpp b/hotspot/src/share/vm/runtime/globals.cpp index 02d10573368..474090a2a4b 100644 --- a/hotspot/src/share/vm/runtime/globals.cpp +++ b/hotspot/src/share/vm/runtime/globals.cpp @@ -148,6 +148,8 @@ void Flag::print_as_flag(outputStream* st) { st->print("-XX:%s=" UINTX_FORMAT, name, get_uintx()); } else if (is_uint64_t()) { st->print("-XX:%s=" UINT64_FORMAT, name, get_uint64_t()); + } else if (is_double()) { + st->print("-XX:%s=%f", name, get_double()); } else if (is_ccstr()) { st->print("-XX:%s=", name); const char* cp = get_ccstr(); diff --git a/hotspot/src/share/vm/runtime/globals.hpp b/hotspot/src/share/vm/runtime/globals.hpp index 7ad4f9a042c..d030b4f1740 100644 --- a/hotspot/src/share/vm/runtime/globals.hpp +++ b/hotspot/src/share/vm/runtime/globals.hpp @@ -3902,7 +3902,10 @@ class CommandLineFlags { " of this flag is true for JDK 6 and earlier") \ \ diagnostic(bool, WhiteBoxAPI, false, \ - "Enable internal testing APIs") + "Enable internal testing APIs") \ + \ + product(bool, PrintGCCause, true, \ + "Include GC cause in GC logging") /* * Macros for factoring of globals diff --git a/hotspot/src/share/vm/runtime/java.hpp b/hotspot/src/share/vm/runtime/java.hpp index 307fcc2fb36..102fd6b7acd 100644 --- a/hotspot/src/share/vm/runtime/java.hpp +++ b/hotspot/src/share/vm/runtime/java.hpp @@ -206,6 +206,10 @@ class JDK_Version VALUE_OBJ_CLASS_SPEC { return current().compare_major(7) == 0; } + static bool is_jdk18x_version() { + return current().compare_major(8) == 0; + } + static bool is_gte_jdk13x_version() { return current().compare_major(3) >= 0; } @@ -225,6 +229,10 @@ class JDK_Version VALUE_OBJ_CLASS_SPEC { static bool is_gte_jdk17x_version() { return current().compare_major(7) >= 0; } + + static bool is_gte_jdk18x_version() { + return current().compare_major(8) >= 0; + } }; #endif // SHARE_VM_RUNTIME_JAVA_HPP diff --git a/hotspot/src/share/vm/utilities/globalDefinitions.hpp b/hotspot/src/share/vm/utilities/globalDefinitions.hpp index 89201f62f92..82a9333b789 100644 --- a/hotspot/src/share/vm/utilities/globalDefinitions.hpp +++ b/hotspot/src/share/vm/utilities/globalDefinitions.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, 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 @@ -179,6 +179,11 @@ const jlong NANOSECS_PER_SEC = CONST64(1000000000); const jint NANOSECS_PER_MILLISEC = 1000000; inline const char* proper_unit_for_byte_size(size_t s) { +#ifdef _LP64 + if (s >= 10*G) { + return "G"; + } +#endif if (s >= 10*M) { return "M"; } else if (s >= 10*K) { @@ -188,17 +193,22 @@ inline const char* proper_unit_for_byte_size(size_t s) { } } -inline size_t byte_size_in_proper_unit(size_t s) { +template +inline T byte_size_in_proper_unit(T s) { +#ifdef _LP64 + if (s >= 10*G) { + return (T)(s/G); + } +#endif if (s >= 10*M) { - return s/M; + return (T)(s/M); } else if (s >= 10*K) { - return s/K; + return (T)(s/K); } else { return s; } } - //---------------------------------------------------------------------------------------------------- // VM type definitions diff --git a/hotspot/test/compiler/7070134/Stemmer.java b/hotspot/test/compiler/7070134/Stemmer.java index c7edb750643..49484f94f2b 100644 --- a/hotspot/test/compiler/7070134/Stemmer.java +++ b/hotspot/test/compiler/7070134/Stemmer.java @@ -13,7 +13,18 @@ Porter, 1980, An algorithm for suffix stripping, Program, Vol. 14, no. 3, pp 130-137, - See also http://www.tartarus.org/~martin/PorterStemmer + http://www.tartarus.org/~martin/PorterStemmer + + The software is completely free for any purpose, unless notes at the head + of the program text indicates otherwise (which is rare). In any case, + the notes about licensing are never more restrictive than the BSD License. + + In every case where the software is not written by me (Martin Porter), + this licensing arrangement has been endorsed by the contributor, and it is + therefore unnecessary to ask the contributor again to confirm it. + + I have not asked any contributors (or their employers, if they have them) + for proofs that they have the right to distribute their software in this way. History: diff --git a/hotspot/test/compiler/7160610/Test7160610.java b/hotspot/test/compiler/7160610/Test7160610.java new file mode 100644 index 00000000000..62b2e6e14b9 --- /dev/null +++ b/hotspot/test/compiler/7160610/Test7160610.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2012, 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 7160610 + * @summary Unknown Native Code compilation issue. + * + * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-OptimizeFill Test7160610 + */ + +public class Test7160610 { + private static final byte[] BYTE_ARRAY = new byte[7]; + private static int[] anIntArray1190 = new int[32768]; + private static int[] anIntArray1191 = new int[32768]; + + public static void main(String arg[]) { + int i = 256; + for(int j = BYTE_ARRAY[2]; j < anIntArray1190.length; j++) { + anIntArray1190[j] = BYTE_ARRAY[2]; + } + + for(int k = BYTE_ARRAY[2]; (k ^ BYTE_ARRAY[1]) > -5001; k++) { + int i1 = (int)(Math.random() * 128D * (double)i); + anIntArray1190[i1] = (int)(Math.random() * 256D); + } + + for(int l = BYTE_ARRAY[2]; (l ^ BYTE_ARRAY[1]) > -21; l++) { + for(int j1 = BYTE_ARRAY[0]; j1 < i + -BYTE_ARRAY[0]; j1++) { + for(int k1 = BYTE_ARRAY[0]; (k1 ^ BYTE_ARRAY[1]) > -128; k1++) { + int l1 = k1 - -(j1 << 0x26cb6487); + anIntArray1191[l1] = (anIntArray1190[l1 + -BYTE_ARRAY[0]] - -anIntArray1190[l1 - -BYTE_ARRAY[0]] - -anIntArray1190[-128 + l1] - -anIntArray1190[128 + l1]) / BYTE_ARRAY[6]; + } + } + int ai[] = anIntArray1190; + anIntArray1190 = anIntArray1191; + anIntArray1191 = ai; + } + } + + static { + BYTE_ARRAY[6] = 4; + BYTE_ARRAY[5] = 5; + BYTE_ARRAY[4] = 3; + BYTE_ARRAY[3] = 2; + BYTE_ARRAY[2] = 0; + BYTE_ARRAY[1] = -1; + BYTE_ARRAY[0] = 1; + } +} diff --git a/hotspot/test/runtime/7167069/PrintAsFlag.java b/hotspot/test/runtime/7167069/PrintAsFlag.java new file mode 100644 index 00000000000..bf8747ec59d --- /dev/null +++ b/hotspot/test/runtime/7167069/PrintAsFlag.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2012, 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. + * + */ + +/* + * Note that in the run command below the only important flag is PrintCommandLineFlags. + * The others are just flags of all types; bool, intx, uintx, uint64_t, double and ccstr. + * + * @test PrintAsFlag + * @summary verify that Flag::print_as_flag() works correctly. This is used by "jinfo -flag" and -XX:+PrintCommandLineFlags. + * @run main/othervm -XX:+PrintCommandLineFlags -XX:-ShowMessageBoxOnError -XX:BiasedLockingStartupDelay=4000 -XX:ParallelGCThreads=4 -XX:MaxRAM=1G -XX:CMSSmallCoalSurplusPercent=1.05 -XX:ErrorFile="file" PrintAsFlag + */ + +public class PrintAsFlag { + public static void main(String... args) { + System.out.printf("Done"); + } +} diff --git a/jaxp/.hgtags b/jaxp/.hgtags index 60e82724512..0c06d95a38f 100644 --- a/jaxp/.hgtags +++ b/jaxp/.hgtags @@ -159,3 +159,5 @@ f3244c1f04864d35c41fa8d13669faf4f65b81e2 jdk8-b28 e187f3ede64965dc2979df9a211107cd3d38eacb jdk8-b35 cfd288fe1d3e2b700838342e70d71d44ac991af5 jdk8-b36 90204bfab4e2bed402badcc997cbf8446ab5669f jdk8-b37 +5bbe0cb6f2f2d7ce292da77bf4fa9d618d770a78 jdk8-b38 +f95fdbe525c88ef0d57dc1390be6582a8af5e07c jdk8-b39 diff --git a/jaxws/.hgtags b/jaxws/.hgtags index 30267c2eada..a0c4c18e846 100644 --- a/jaxws/.hgtags +++ b/jaxws/.hgtags @@ -159,3 +159,5 @@ f1d020a49c8c33667fb10c8caa255206a78a3675 jdk8-b34 e8afc16522e190cb93c66bcb15d6fba0fe9e6833 jdk8-b35 89b36c658e39f0a2957be55453a3a3befd9c8a6b jdk8-b36 b05a948db1b6c933c980f24e4dc8fd897b7cf4ef jdk8-b37 +ac1ba3b56775e3cdcd91b7a48793b59f6a3c18b5 jdk8-b38 +7f6b44fd303478caa83575dbc225de187c509c50 jdk8-b39 diff --git a/jdk/.hgtags b/jdk/.hgtags index dbcbbd5fb5d..d1ac29cc4ec 100644 --- a/jdk/.hgtags +++ b/jdk/.hgtags @@ -159,3 +159,6 @@ ddfe5562f61f54ed2121ac0c73b688b94f3e66b5 jdk8-b32 2e3e1356ffbddb2ae95c08da72830ba9ab8b3181 jdk8-b35 45da9cb055ee258dc09e69c1718e27eadea38e45 jdk8-b36 9e82ac15ab80370d6e021aea7b98c7c9626adb5e jdk8-b37 +c45f3509a70796c54b48f32910d1caf435763416 jdk8-b38 +b6f52911752110a2889681923992c7a0baa52ccc jdk8-b39 +b88fc3359dc7edabfa8a228855d8cebf8843c055 jdk8-b40 diff --git a/jdk/make/com/oracle/security/ucrypto/Makefile b/jdk/make/com/oracle/security/ucrypto/Makefile index 8ea7a749a7b..f6545e89828 100644 --- a/jdk/make/com/oracle/security/ucrypto/Makefile +++ b/jdk/make/com/oracle/security/ucrypto/Makefile @@ -139,7 +139,7 @@ ifndef OPENJDK # CLASSDESTDIR = $(TEMPDIR)/classes JAVAHFLAGS = -bootclasspath \ - "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)" + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" include $(BUILDDIR)/common/Mapfile-vers.gmk include $(BUILDDIR)/common/Library.gmk diff --git a/jdk/make/common/Release.gmk b/jdk/make/common/Release.gmk index d8ec1b713d7..4d8ddb1a6c7 100644 --- a/jdk/make/common/Release.gmk +++ b/jdk/make/common/Release.gmk @@ -156,6 +156,7 @@ JDK_MAN_PAGES = \ jstack.1 \ jstat.1 \ jstatd.1 \ + jvisualvm.1 \ native2ascii.1 \ rmic.1 \ schemagen.1 \ @@ -1311,8 +1312,8 @@ $(TEMP_PREV_JDK_COMPARISON): install-previous-jdk $(DIRDIFF_JARFILE) @$(java-vm-cleanup) # Clean up names in the messages printed out -CAT_FILTER = $(SED) -e "s@$(JDK_IMAGE_DIR)@JDK_IMAGE@g" \ - -e "s@$(JRE_IMAGE_DIR)@JRE_IMAGE@g" +CAT_FILTER = $(SED) -e "s|$(JDK_IMAGE_DIR)|JDK_IMAGE|g" \ + -e "s|$(JRE_IMAGE_DIR)|JRE_IMAGE|g" # Report on the jre image comparison compare-image-jre: $(TEMP_PREV_JRE_COMPARISON) diff --git a/jdk/make/common/shared/Defs-java.gmk b/jdk/make/common/shared/Defs-java.gmk index 5002c28198a..eb50e475e48 100644 --- a/jdk/make/common/shared/Defs-java.gmk +++ b/jdk/make/common/shared/Defs-java.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2007, 2012, 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 @@ -139,7 +139,7 @@ JAVACFLAGS += $(JAVAC_LINT_OPTIONS) # built implicitly/explicitly. # ifeq ($(wildcard $(SHARE_SRC)/classes/javax/crypto/Cipher.java),) - JCEFLAGS = $(CLASSPATH_SEPARATOR)$(LIBDIR)/jce.jar + JCE_PATH = $(CLASSPATH_SEPARATOR)$(LIBDIR)/jce.jar endif # Add the source level @@ -152,11 +152,11 @@ TARGET_CLASS_VERSION = 7 CLASS_VERSION = -target $(TARGET_CLASS_VERSION) JAVACFLAGS += $(CLASS_VERSION) JAVACFLAGS += -encoding ascii -JAVACFLAGS += "-Xbootclasspath:$(CLASSBINDIR)$(JCEFLAGS)" +JAVACFLAGS += "-Xbootclasspath:$(CLASSBINDIR)$(JCE_PATH)" JAVACFLAGS += $(OTHER_JAVACFLAGS) # Needed for javah -JAVAHFLAGS += -bootclasspath "$(CLASSBINDIR)$(JCEFLAGS)" +JAVAHFLAGS += -bootclasspath "$(CLASSBINDIR)$(JCE_PATH)" # Needed for javadoc to ensure it builds documentation # against the newly built classes diff --git a/jdk/make/java/redist/Makefile b/jdk/make/java/redist/Makefile index f72ad57333b..fb257f5c354 100644 --- a/jdk/make/java/redist/Makefile +++ b/jdk/make/java/redist/Makefile @@ -261,8 +261,7 @@ ifndef BUILD_CLIENT_ONLY ifeq ($(ZIP_DEBUGINFO_FILES),1) # the import JDK may not contain the target of the symlink ifneq ($(wildcard $(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/$(LIBJSIG_DIZ_NAME)),) - # check for the .diz file, but create the .debuginfo link - IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME) + IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_DIZ_NAME) endif else # the import JDK may not contain the target of the symlink @@ -319,8 +318,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) ifeq ($(ZIP_DEBUGINFO_FILES),1) # the import JDK may not contain the target of the symlink ifneq ($(wildcard $(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/$(LIBJSIG_DIZ_NAME)),) - # check for the .diz file, but create the .debuginfo link - IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME) + IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DIZ_NAME) endif else # the import JDK may not contain the target of the symlink @@ -472,11 +470,24 @@ $(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_NAME): $(call install-sym-link, ../$(LIBJSIG_NAME)) ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) -# we don't create a symlink to a libjsig.diz file +# We don't create a symlink to a libjsig.diz file, but we do put +# the libjsig.debuginfo symlink into a libjsig.diz file. The aurora +# system does not like dangling symlinks. + ifeq ($(ZIP_DEBUGINFO_FILES),1) +$(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DIZ_NAME) \ +$(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_DIZ_NAME): + @$(prep-target) + $(LN) -s ../$(LIBJSIG_DEBUGINFO_NAME) $(@D)/$(LIBJSIG_DEBUGINFO_NAME) + ( $(CD) $(@D) ; \ + $(ZIPEXE) -y $(LIBJSIG_DIZ_NAME) $(LIBJSIG_DEBUGINFO_NAME) ; \ + $(RM) $(LIBJSIG_DEBUGINFO_NAME) ; \ + ) + else $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME) \ $(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME): @$(prep-target) $(call install-sym-link, ../$(LIBJSIG_DEBUGINFO_NAME)) + endif endif else $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_NAME): @@ -484,10 +495,22 @@ $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_NAME): $(call install-sym-link, ../$(LIBJSIG_NAME)) ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) -# we don't create a symlink to a libjsig.diz file +# We don't create a symlink to a libjsig.diz file, but we do put +# the libjsig.debuginfo symlink into a libjsig.diz file. The aurora +# system does not like dangling symlinks. + ifeq ($(ZIP_DEBUGINFO_FILES),1) +$(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DIZ_NAME): + @$(prep-target) + $(LN) -s ../$(LIBJSIG_DEBUGINFO_NAME) $(@D)/$(LIBJSIG_DEBUGINFO_NAME) + ( $(CD) $(@D) ; \ + $(ZIPEXE) -y $(LIBJSIG_DIZ_NAME) $(LIBJSIG_DEBUGINFO_NAME) ; \ + $(RM) $(LIBJSIG_DEBUGINFO_NAME) ; \ + ) + else $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME): @$(prep-target) $(call install-sym-link, ../$(LIBJSIG_DEBUGINFO_NAME)) + endif endif endif diff --git a/jdk/make/sun/security/ec/Makefile b/jdk/make/sun/security/ec/Makefile index 841fc3716d2..0e92dd59cff 100644 --- a/jdk/make/sun/security/ec/Makefile +++ b/jdk/make/sun/security/ec/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, 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 @@ -160,7 +160,7 @@ ifeq ($(NATIVE_ECC_AVAILABLE), true) $(PKGDIR)/ECKeyPairGenerator.java JAVAHFLAGS = -bootclasspath \ - "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)" + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" # diff --git a/jdk/make/sun/security/mscapi/Makefile b/jdk/make/sun/security/mscapi/Makefile index 65eef782654..1cd6024a9c4 100644 --- a/jdk/make/sun/security/mscapi/Makefile +++ b/jdk/make/sun/security/mscapi/Makefile @@ -150,7 +150,7 @@ OTHER_INCLUDES += \ # CLASSDESTDIR = $(TEMPDIR)/classes JAVAHFLAGS = -bootclasspath \ - "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)" + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" include $(BUILDDIR)/common/Mapfile-vers.gmk diff --git a/jdk/make/sun/security/pkcs11/Makefile b/jdk/make/sun/security/pkcs11/Makefile index d7e049d9e1f..ecdba0997da 100644 --- a/jdk/make/sun/security/pkcs11/Makefile +++ b/jdk/make/sun/security/pkcs11/Makefile @@ -151,7 +151,7 @@ OTHER_INCLUDES += \ # CLASSDESTDIR = $(TEMPDIR)/classes JAVAHFLAGS = -bootclasspath \ - "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)" + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" include $(BUILDDIR)/common/Mapfile-vers.gmk diff --git a/jdk/makefiles/com/oracle/security/ucrypto/Makefile b/jdk/makefiles/com/oracle/security/ucrypto/Makefile index 8ea7a749a7b..f6545e89828 100644 --- a/jdk/makefiles/com/oracle/security/ucrypto/Makefile +++ b/jdk/makefiles/com/oracle/security/ucrypto/Makefile @@ -139,7 +139,7 @@ ifndef OPENJDK # CLASSDESTDIR = $(TEMPDIR)/classes JAVAHFLAGS = -bootclasspath \ - "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)" + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" include $(BUILDDIR)/common/Mapfile-vers.gmk include $(BUILDDIR)/common/Library.gmk diff --git a/jdk/makefiles/common/shared/Defs-java.gmk b/jdk/makefiles/common/shared/Defs-java.gmk index 4422ca312b0..897b24d77a3 100644 --- a/jdk/makefiles/common/shared/Defs-java.gmk +++ b/jdk/makefiles/common/shared/Defs-java.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2007, 2012, 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 @@ -141,7 +141,7 @@ JAVACFLAGS += $(JAVAC_LINT_OPTIONS) # built implicitly/explicitly. # ifeq ($(wildcard $(SHARE_SRC)/classes/javax/crypto/Cipher.java),) - JCEFLAGS = $(CLASSPATH_SEPARATOR)$(LIBDIR)/jce.jar + JCE_PATH = $(CLASSPATH_SEPARATOR)$(LIBDIR)/jce.jar endif # Add the source level @@ -154,11 +154,11 @@ TARGET_CLASS_VERSION = 7 CLASS_VERSION = -target $(TARGET_CLASS_VERSION) JAVACFLAGS += $(CLASS_VERSION) JAVACFLAGS += -encoding ascii -JAVACFLAGS += "-Xbootclasspath:$(CLASSBINDIR)$(JCEFLAGS)" +JAVACFLAGS += "-Xbootclasspath:$(CLASSBINDIR)$(JCE_PATH)" JAVACFLAGS += $(OTHER_JAVACFLAGS) # Needed for javah -JAVAHFLAGS += -bootclasspath "$(CLASSBINDIR)$(JCEFLAGS)" +JAVAHFLAGS += -bootclasspath "$(CLASSBINDIR)$(JCE_PATH)" # Needed for javadoc to ensure it builds documentation # against the newly built classes diff --git a/jdk/makefiles/sun/security/ec/Makefile b/jdk/makefiles/sun/security/ec/Makefile index 146a24e7a9b..d09dbecf629 100644 --- a/jdk/makefiles/sun/security/ec/Makefile +++ b/jdk/makefiles/sun/security/ec/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, 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 @@ -159,7 +159,8 @@ ifeq ($(NATIVE_ECC_AVAILABLE), true) $(PKGDIR)/ECDSASignature.java \ $(PKGDIR)/ECKeyPairGenerator.java - JAVAHFLAGS += -Xbootclasspath/p:$(CLASSDESTDIR) + JAVAHFLAGS = -bootclasspath \ + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" # # C and C++ files diff --git a/jdk/makefiles/sun/security/mscapi/Makefile b/jdk/makefiles/sun/security/mscapi/Makefile index 389d5a1a016..1cd6024a9c4 100644 --- a/jdk/makefiles/sun/security/mscapi/Makefile +++ b/jdk/makefiles/sun/security/mscapi/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2005, 2012, 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 @@ -149,7 +149,8 @@ OTHER_INCLUDES += \ # Rules # CLASSDESTDIR = $(TEMPDIR)/classes -JAVAHFLAGS += -Xbootclasspath/p:$(CLASSDESTDIR) +JAVAHFLAGS = -bootclasspath \ + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" include $(BUILDDIR)/common/Mapfile-vers.gmk diff --git a/jdk/makefiles/sun/security/pkcs11/Makefile b/jdk/makefiles/sun/security/pkcs11/Makefile index 7f9c1c75574..b94a6dbc109 100644 --- a/jdk/makefiles/sun/security/pkcs11/Makefile +++ b/jdk/makefiles/sun/security/pkcs11/Makefile @@ -150,7 +150,8 @@ OTHER_INCLUDES += \ # Rules # CLASSDESTDIR = $(TEMPDIR)/classes -JAVAHFLAGS = -bootclasspath "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)" +JAVAHFLAGS = -bootclasspath \ + "$(CLASSDESTDIR)$(CLASSPATH_SEPARATOR)$(CLASSBINDIR)$(JCE_PATH)" include $(BUILDDIR)/common/Mapfile-vers.gmk diff --git a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java index 7a4ef4b6605..cba98be1b2a 100644 --- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java +++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferences.java @@ -135,18 +135,21 @@ class MacOSXPreferences extends AbstractPreferences { // AbstractPreferences implementation + @Override protected void putSpi(String key, String value) { file.addKeyToNode(path, key, value); } // AbstractPreferences implementation + @Override protected String getSpi(String key) { return file.getKeyFromNode(path, key); } // AbstractPreferences implementation + @Override protected void removeSpi(String key) { Objects.requireNonNull(key, "Specified key cannot be null"); @@ -155,6 +158,7 @@ class MacOSXPreferences extends AbstractPreferences { // AbstractPreferences implementation + @Override protected void removeNodeSpi() throws BackingStoreException { @@ -174,6 +178,7 @@ class MacOSXPreferences extends AbstractPreferences { // AbstractPreferences implementation + @Override protected String[] childrenNamesSpi() throws BackingStoreException { @@ -183,6 +188,7 @@ class MacOSXPreferences extends AbstractPreferences { } // AbstractPreferences implementation + @Override protected String[] keysSpi() throws BackingStoreException { @@ -192,6 +198,7 @@ class MacOSXPreferences extends AbstractPreferences { } // AbstractPreferences implementation + @Override protected AbstractPreferences childSpi(String name) { // Add to parent's child list here and disallow sync @@ -203,6 +210,7 @@ class MacOSXPreferences extends AbstractPreferences { } // AbstractPreferences override + @Override public void flush() throws BackingStoreException { @@ -217,6 +225,7 @@ class MacOSXPreferences extends AbstractPreferences { } // AbstractPreferences implementation + @Override protected void flushSpi() throws BackingStoreException { @@ -224,6 +233,7 @@ class MacOSXPreferences extends AbstractPreferences { } // AbstractPreferences override + @Override public void sync() throws BackingStoreException { @@ -244,6 +254,7 @@ class MacOSXPreferences extends AbstractPreferences { } // AbstractPreferences implementation + @Override protected void syncSpi() throws BackingStoreException { diff --git a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java index 05ef30c7800..2d1710e1930 100644 --- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java +++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFactory.java @@ -26,10 +26,12 @@ package java.util.prefs; class MacOSXPreferencesFactory implements PreferencesFactory { + @Override public Preferences userRoot() { return MacOSXPreferences.getUserRoot(); } + @Override public Preferences systemRoot() { return MacOSXPreferences.getSystemRoot(); } diff --git a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java index 992ae620338..31355b5be46 100644 --- a/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java +++ b/jdk/src/macosx/classes/java/util/prefs/MacOSXPreferencesFile.java @@ -101,9 +101,10 @@ class MacOSXPreferencesFile { } // Maps string -> weak reference to MacOSXPreferencesFile - private static HashMap cachedFiles = null; + private static HashMap> + cachedFiles; // Files that may have unflushed changes - private static HashSet changedFiles = null; + private static HashSet changedFiles; // Timer and pending sync and flush tasks (which are both scheduled @@ -136,13 +137,14 @@ class MacOSXPreferencesFile { { MacOSXPreferencesFile result = null; - if (cachedFiles == null) cachedFiles = new HashMap(); + if (cachedFiles == null) + cachedFiles = new HashMap<>(); String hashkey = newName + String.valueOf(isUser); - WeakReference hashvalue = (WeakReference)cachedFiles.get(hashkey); + WeakReference hashvalue = cachedFiles.get(hashkey); if (hashvalue != null) { - result = (MacOSXPreferencesFile)hashvalue.get(); + result = hashvalue.get(); } if (result == null) { // Java user node == CF current user, any host @@ -150,7 +152,7 @@ class MacOSXPreferencesFile { result = new MacOSXPreferencesFile(newName, isUser ? cfCurrentUser : cfAnyUser, isUser ? cfAnyHost : cfCurrentHost); - cachedFiles.put(hashkey, new WeakReference(result)); + cachedFiles.put(hashkey, new WeakReference(result)); } // Don't schedule this file for flushing until some nodes or @@ -171,10 +173,11 @@ class MacOSXPreferencesFile { boolean ok = true; if (cachedFiles != null && !cachedFiles.isEmpty()) { - Iterator iter = cachedFiles.values().iterator(); + Iterator> iter = + cachedFiles.values().iterator(); while (iter.hasNext()) { - WeakReference ref = (WeakReference)iter.next(); - MacOSXPreferencesFile f = (MacOSXPreferencesFile)ref.get(); + WeakReference ref = iter.next(); + MacOSXPreferencesFile f = ref.get(); if (f != null) { if (!f.synchronize()) ok = false; } else { @@ -202,10 +205,11 @@ class MacOSXPreferencesFile { static synchronized boolean syncUser() { boolean ok = true; if (cachedFiles != null && !cachedFiles.isEmpty()) { - Iterator iter = cachedFiles.values().iterator(); + Iterator> iter = + cachedFiles.values().iterator(); while (iter.hasNext()) { - WeakReference ref = iter.next(); - MacOSXPreferencesFile f = (MacOSXPreferencesFile)ref.get(); + WeakReference ref = iter.next(); + MacOSXPreferencesFile f = ref.get(); if (f != null && f.user == cfCurrentUser) { if (!f.synchronize()) { ok = false; @@ -240,12 +244,10 @@ class MacOSXPreferencesFile { boolean ok = true; if (changedFiles != null && !changedFiles.isEmpty()) { - Iterator iter = changedFiles.iterator(); - while (iter.hasNext()) { - MacOSXPreferencesFile f = (MacOSXPreferencesFile)iter.next(); - if (!f.synchronize()) ok = false; + for (MacOSXPreferencesFile f : changedFiles) { + if (!f.synchronize()) + ok = false; } - changedFiles.clear(); } @@ -263,7 +265,8 @@ class MacOSXPreferencesFile { private void markChanged() { // Add this file to the changed file list - if (changedFiles == null) changedFiles = new HashSet(); + if (changedFiles == null) + changedFiles = new HashSet<>(); changedFiles.add(this); // Schedule a new flush and a shutdown hook, if necessary @@ -309,7 +312,9 @@ class MacOSXPreferencesFile { if (syncInterval > 0) { timer().schedule(new TimerTask() { - public void run() { MacOSXPreferencesFile.syncWorld();} + @Override + public void run() { + MacOSXPreferencesFile.syncWorld();} }, syncInterval * 1000, syncInterval * 1000); } else { // syncInterval property not set. No sync timer ever. @@ -323,6 +328,7 @@ class MacOSXPreferencesFile { if (timer == null) { timer = new Timer(true); // daemon Thread flushThread = new Thread() { + @Override public void run() { flushWorld(); } diff --git a/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java b/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java index 1fda340c509..02f743d3e72 100644 --- a/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java +++ b/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java @@ -40,7 +40,7 @@ public class CGraphicsDevice extends GraphicsDevice { private final int displayID; // Array of all GraphicsConfig instances for this device - private final CGraphicsConfig[] configs; + private final GraphicsConfiguration[] configs; // Default config (temporarily hard coded) private final int DEFAULT_CONFIG = 0; @@ -49,7 +49,7 @@ public class CGraphicsDevice extends GraphicsDevice { public CGraphicsDevice(int displayID) { this.displayID = displayID; - configs = new CGraphicsConfig[] { + configs = new GraphicsConfiguration[] { CGLGraphicsConfig.getConfig(this, 0) }; } @@ -66,7 +66,7 @@ public class CGraphicsDevice extends GraphicsDevice { */ @Override public GraphicsConfiguration[] getConfigurations() { - return configs; + return configs.clone(); } /** diff --git a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java index 517973b98b5..035cfe1596b 100644 --- a/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java +++ b/jdk/src/macosx/classes/sun/lwawt/LWComponentPeer.java @@ -976,8 +976,8 @@ public abstract class LWComponentPeer @Override public Image createImage(int w, int h) { - // TODO: accelerated image - return getGraphicsConfiguration().createCompatibleImage(w, h); + CGraphicsConfig gc = (CGraphicsConfig)getGraphicsConfiguration(); + return gc.createAcceleratedImage(getTarget(), w, h); } @Override diff --git a/jdk/src/share/classes/com/sun/crypto/provider/HmacCore.java b/jdk/src/share/classes/com/sun/crypto/provider/HmacCore.java index 57aed3d0b0c..bc865c63f47 100644 --- a/jdk/src/share/classes/com/sun/crypto/provider/HmacCore.java +++ b/jdk/src/share/classes/com/sun/crypto/provider/HmacCore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2012, 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 @@ -38,16 +38,16 @@ import java.security.spec.*; * This class constitutes the core of HMAC- algorithms, where * can be SHA1 or MD5, etc. See RFC 2104 for spec. * - * It also contains the implementation classes for the SHA-256, + * It also contains the implementation classes for SHA-224, SHA-256, * SHA-384, and SHA-512 HMACs. * * @author Jan Luehe */ -final class HmacCore implements Cloneable { +abstract class HmacCore extends MacSpi implements Cloneable { - private final MessageDigest md; - private final byte[] k_ipad; // inner padding - key XORd with ipad - private final byte[] k_opad; // outer padding - key XORd with opad + private MessageDigest md; + private byte[] k_ipad; // inner padding - key XORd with ipad + private byte[] k_opad; // outer padding - key XORd with opad private boolean first; // Is this the first data to be processed? private final int blockLen; @@ -72,23 +72,12 @@ final class HmacCore implements Cloneable { this(MessageDigest.getInstance(digestAlgorithm), bl); } - /** - * Constructor used for cloning. - */ - private HmacCore(HmacCore other) throws CloneNotSupportedException { - this.md = (MessageDigest)other.md.clone(); - this.blockLen = other.blockLen; - this.k_ipad = other.k_ipad.clone(); - this.k_opad = other.k_opad.clone(); - this.first = other.first; - } - /** * Returns the length of the HMAC in bytes. * * @return the HMAC length in bytes. */ - int getDigestLength() { + protected int engineGetMacLength() { return this.md.getDigestLength(); } @@ -103,9 +92,8 @@ final class HmacCore implements Cloneable { * @exception InvalidAlgorithmParameterException if the given algorithm * parameters are inappropriate for this MAC. */ - void init(Key key, AlgorithmParameterSpec params) + protected void engineInit(Key key, AlgorithmParameterSpec params) throws InvalidKeyException, InvalidAlgorithmParameterException { - if (params != null) { throw new InvalidAlgorithmParameterException ("HMAC does not use parameters"); @@ -140,7 +128,7 @@ final class HmacCore implements Cloneable { Arrays.fill(secret, (byte)0); secret = null; - reset(); + engineReset(); } /** @@ -148,7 +136,7 @@ final class HmacCore implements Cloneable { * * @param input the input byte to be processed. */ - void update(byte input) { + protected void engineUpdate(byte input) { if (first == true) { // compute digest for 1st pass; start with inner pad md.update(k_ipad); @@ -167,7 +155,7 @@ final class HmacCore implements Cloneable { * @param offset the offset in input where the input starts. * @param len the number of bytes to process. */ - void update(byte input[], int offset, int len) { + protected void engineUpdate(byte input[], int offset, int len) { if (first == true) { // compute digest for 1st pass; start with inner pad md.update(k_ipad); @@ -178,7 +166,13 @@ final class HmacCore implements Cloneable { md.update(input, offset, len); } - void update(ByteBuffer input) { + /** + * Processes the input.remaining() bytes in the ByteBuffer + * input. + * + * @param input the input byte buffer. + */ + protected void engineUpdate(ByteBuffer input) { if (first == true) { // compute digest for 1st pass; start with inner pad md.update(k_ipad); @@ -194,7 +188,7 @@ final class HmacCore implements Cloneable { * * @return the HMAC result. */ - byte[] doFinal() { + protected byte[] engineDoFinal() { if (first == true) { // compute digest for 1st pass; start with inner pad md.update(k_ipad); @@ -223,7 +217,7 @@ final class HmacCore implements Cloneable { * Resets the HMAC for further use, maintaining the secret key that the * HMAC was initialized with. */ - void reset() { + protected void engineReset() { if (first == false) { md.reset(); first = true; @@ -234,115 +228,38 @@ final class HmacCore implements Cloneable { * Clones this object. */ public Object clone() throws CloneNotSupportedException { - return new HmacCore(this); + HmacCore copy = (HmacCore) super.clone(); + copy.md = (MessageDigest) md.clone(); + copy.k_ipad = k_ipad.clone(); + copy.k_opad = k_opad.clone(); + return copy; + } + + // nested static class for the HmacSHA224 implementation + public static final class HmacSHA224 extends HmacCore { + public HmacSHA224() throws NoSuchAlgorithmException { + super("SHA-224", 64); + } } // nested static class for the HmacSHA256 implementation - public static final class HmacSHA256 extends MacSpi implements Cloneable { - private final HmacCore core; + public static final class HmacSHA256 extends HmacCore { public HmacSHA256() throws NoSuchAlgorithmException { - core = new HmacCore("SHA-256", 64); - } - private HmacSHA256(HmacSHA256 base) throws CloneNotSupportedException { - core = (HmacCore)base.core.clone(); - } - protected int engineGetMacLength() { - return core.getDigestLength(); - } - protected void engineInit(Key key, AlgorithmParameterSpec params) - throws InvalidKeyException, InvalidAlgorithmParameterException { - core.init(key, params); - } - protected void engineUpdate(byte input) { - core.update(input); - } - protected void engineUpdate(byte input[], int offset, int len) { - core.update(input, offset, len); - } - protected void engineUpdate(ByteBuffer input) { - core.update(input); - } - protected byte[] engineDoFinal() { - return core.doFinal(); - } - protected void engineReset() { - core.reset(); - } - public Object clone() throws CloneNotSupportedException { - return new HmacSHA256(this); + super("SHA-256", 64); } } // nested static class for the HmacSHA384 implementation - public static final class HmacSHA384 extends MacSpi implements Cloneable { - private final HmacCore core; + public static final class HmacSHA384 extends HmacCore { public HmacSHA384() throws NoSuchAlgorithmException { - core = new HmacCore("SHA-384", 128); - } - private HmacSHA384(HmacSHA384 base) throws CloneNotSupportedException { - core = (HmacCore)base.core.clone(); - } - protected int engineGetMacLength() { - return core.getDigestLength(); - } - protected void engineInit(Key key, AlgorithmParameterSpec params) - throws InvalidKeyException, InvalidAlgorithmParameterException { - core.init(key, params); - } - protected void engineUpdate(byte input) { - core.update(input); - } - protected void engineUpdate(byte input[], int offset, int len) { - core.update(input, offset, len); - } - protected void engineUpdate(ByteBuffer input) { - core.update(input); - } - protected byte[] engineDoFinal() { - return core.doFinal(); - } - protected void engineReset() { - core.reset(); - } - public Object clone() throws CloneNotSupportedException { - return new HmacSHA384(this); + super("SHA-384", 128); } } // nested static class for the HmacSHA512 implementation - public static final class HmacSHA512 extends MacSpi implements Cloneable { - private final HmacCore core; + public static final class HmacSHA512 extends HmacCore { public HmacSHA512() throws NoSuchAlgorithmException { - core = new HmacCore("SHA-512", 128); - } - private HmacSHA512(HmacSHA512 base) throws CloneNotSupportedException { - core = (HmacCore)base.core.clone(); - } - protected int engineGetMacLength() { - return core.getDigestLength(); - } - protected void engineInit(Key key, AlgorithmParameterSpec params) - throws InvalidKeyException, InvalidAlgorithmParameterException { - core.init(key, params); - } - protected void engineUpdate(byte input) { - core.update(input); - } - protected void engineUpdate(byte input[], int offset, int len) { - core.update(input, offset, len); - } - protected void engineUpdate(ByteBuffer input) { - core.update(input); - } - protected byte[] engineDoFinal() { - return core.doFinal(); - } - protected void engineReset() { - core.reset(); - } - public Object clone() throws CloneNotSupportedException { - return new HmacSHA512(this); + super("SHA-512", 128); } } - } diff --git a/jdk/src/share/classes/com/sun/crypto/provider/HmacMD5.java b/jdk/src/share/classes/com/sun/crypto/provider/HmacMD5.java index a4d9f4d46f4..ccf85561db9 100644 --- a/jdk/src/share/classes/com/sun/crypto/provider/HmacMD5.java +++ b/jdk/src/share/classes/com/sun/crypto/provider/HmacMD5.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2012, 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 @@ -37,97 +37,11 @@ import java.security.spec.*; * * @author Jan Luehe */ -public final class HmacMD5 extends MacSpi implements Cloneable { - - private HmacCore hmac; - private static final int MD5_BLOCK_LENGTH = 64; - +public final class HmacMD5 extends HmacCore { /** * Standard constructor, creates a new HmacMD5 instance. */ public HmacMD5() throws NoSuchAlgorithmException { - hmac = new HmacCore(MessageDigest.getInstance("MD5"), - MD5_BLOCK_LENGTH); - } - - /** - * Returns the length of the HMAC in bytes. - * - * @return the HMAC length in bytes. - */ - protected int engineGetMacLength() { - return hmac.getDigestLength(); - } - - /** - * Initializes the HMAC with the given secret key and algorithm parameters. - * - * @param key the secret key. - * @param params the algorithm parameters. - * - * @exception InvalidKeyException if the given key is inappropriate for - * initializing this MAC. - * @exception InvalidAlgorithmParameterException if the given algorithm - * parameters are inappropriate for this MAC. - */ - protected void engineInit(Key key, AlgorithmParameterSpec params) - throws InvalidKeyException, InvalidAlgorithmParameterException { - hmac.init(key, params); - } - - /** - * Processes the given byte. - * - * @param input the input byte to be processed. - */ - protected void engineUpdate(byte input) { - hmac.update(input); - } - - /** - * Processes the first len bytes in input, - * starting at offset. - * - * @param input the input buffer. - * @param offset the offset in input where the input starts. - * @param len the number of bytes to process. - */ - protected void engineUpdate(byte input[], int offset, int len) { - hmac.update(input, offset, len); - } - - protected void engineUpdate(ByteBuffer input) { - hmac.update(input); - } - - /** - * Completes the HMAC computation and resets the HMAC for further use, - * maintaining the secret key that the HMAC was initialized with. - * - * @return the HMAC result. - */ - protected byte[] engineDoFinal() { - return hmac.doFinal(); - } - - /** - * Resets the HMAC for further use, maintaining the secret key that the - * HMAC was initialized with. - */ - protected void engineReset() { - hmac.reset(); - } - - /* - * Clones this object. - */ - public Object clone() { - HmacMD5 that = null; - try { - that = (HmacMD5) super.clone(); - that.hmac = (HmacCore) this.hmac.clone(); - } catch (CloneNotSupportedException e) { - } - return that; + super("MD5", 64); } } diff --git a/jdk/src/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java b/jdk/src/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java index 9b3413c2416..ef0ef58ee45 100644 --- a/jdk/src/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java +++ b/jdk/src/share/classes/com/sun/crypto/provider/HmacPKCS12PBESHA1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -41,26 +41,13 @@ import java.security.spec.*; * * @author Valerie Peng */ -public final class HmacPKCS12PBESHA1 extends MacSpi implements Cloneable { - - private HmacCore hmac = null; - private static final int SHA1_BLOCK_LENGTH = 64; +public final class HmacPKCS12PBESHA1 extends HmacCore { /** * Standard constructor, creates a new HmacSHA1 instance. */ public HmacPKCS12PBESHA1() throws NoSuchAlgorithmException { - this.hmac = new HmacCore(MessageDigest.getInstance("SHA1"), - SHA1_BLOCK_LENGTH); - } - - /** - * Returns the length of the HMAC in bytes. - * - * @return the HMAC length in bytes. - */ - protected int engineGetMacLength() { - return hmac.getDigestLength(); + super("SHA1", 64); } /** @@ -71,7 +58,7 @@ public final class HmacPKCS12PBESHA1 extends MacSpi implements Cloneable { * * @exception InvalidKeyException if the given key is inappropriate for * initializing this MAC. - u* @exception InvalidAlgorithmParameterException if the given algorithm + * @exception InvalidAlgorithmParameterException if the given algorithm * parameters are inappropriate for this MAC. */ protected void engineInit(Key key, AlgorithmParameterSpec params) @@ -140,64 +127,8 @@ public final class HmacPKCS12PBESHA1 extends MacSpi implements Cloneable { ("IterationCount must be a positive number"); } byte[] derivedKey = PKCS12PBECipherCore.derive(passwdChars, salt, - iCount, hmac.getDigestLength(), PKCS12PBECipherCore.MAC_KEY); + iCount, engineGetMacLength(), PKCS12PBECipherCore.MAC_KEY); SecretKey cipherKey = new SecretKeySpec(derivedKey, "HmacSHA1"); - hmac.init(cipherKey, null); - } - - /** - * Processes the given byte. - * - * @param input the input byte to be processed. - */ - protected void engineUpdate(byte input) { - hmac.update(input); - } - - /** - * Processes the first len bytes in input, - * starting at offset. - * - * @param input the input buffer. - * @param offset the offset in input where the input starts. - * @param len the number of bytes to process. - */ - protected void engineUpdate(byte input[], int offset, int len) { - hmac.update(input, offset, len); - } - - protected void engineUpdate(ByteBuffer input) { - hmac.update(input); - } - - /** - * Completes the HMAC computation and resets the HMAC for further use, - * maintaining the secret key that the HMAC was initialized with. - * - * @return the HMAC result. - */ - protected byte[] engineDoFinal() { - return hmac.doFinal(); - } - - /** - * Resets the HMAC for further use, maintaining the secret key that the - * HMAC was initialized with. - */ - protected void engineReset() { - hmac.reset(); - } - - /* - * Clones this object. - */ - public Object clone() { - HmacPKCS12PBESHA1 that = null; - try { - that = (HmacPKCS12PBESHA1)super.clone(); - that.hmac = (HmacCore)this.hmac.clone(); - } catch (CloneNotSupportedException e) { - } - return that; + super.engineInit(cipherKey, null); } } diff --git a/jdk/src/share/classes/com/sun/crypto/provider/HmacSHA1.java b/jdk/src/share/classes/com/sun/crypto/provider/HmacSHA1.java index a9a9f6c423d..b79dc9d9658 100644 --- a/jdk/src/share/classes/com/sun/crypto/provider/HmacSHA1.java +++ b/jdk/src/share/classes/com/sun/crypto/provider/HmacSHA1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2012, 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 @@ -37,97 +37,11 @@ import java.security.spec.*; * * @author Jan Luehe */ -public final class HmacSHA1 extends MacSpi implements Cloneable { - - private HmacCore hmac = null; - private static final int SHA1_BLOCK_LENGTH = 64; - +public final class HmacSHA1 extends HmacCore { /** * Standard constructor, creates a new HmacSHA1 instance. */ public HmacSHA1() throws NoSuchAlgorithmException { - this.hmac = new HmacCore(MessageDigest.getInstance("SHA1"), - SHA1_BLOCK_LENGTH); - } - - /** - * Returns the length of the HMAC in bytes. - * - * @return the HMAC length in bytes. - */ - protected int engineGetMacLength() { - return hmac.getDigestLength(); - } - - /** - * Initializes the HMAC with the given secret key and algorithm parameters. - * - * @param key the secret key. - * @param params the algorithm parameters. - * - * @exception InvalidKeyException if the given key is inappropriate for - * initializing this MAC. - * @exception InvalidAlgorithmParameterException if the given algorithm - * parameters are inappropriate for this MAC. - */ - protected void engineInit(Key key, AlgorithmParameterSpec params) - throws InvalidKeyException, InvalidAlgorithmParameterException { - hmac.init(key, params); - } - - /** - * Processes the given byte. - * - * @param input the input byte to be processed. - */ - protected void engineUpdate(byte input) { - hmac.update(input); - } - - /** - * Processes the first len bytes in input, - * starting at offset. - * - * @param input the input buffer. - * @param offset the offset in input where the input starts. - * @param len the number of bytes to process. - */ - protected void engineUpdate(byte input[], int offset, int len) { - hmac.update(input, offset, len); - } - - protected void engineUpdate(ByteBuffer input) { - hmac.update(input); - } - - /** - * Completes the HMAC computation and resets the HMAC for further use, - * maintaining the secret key that the HMAC was initialized with. - * - * @return the HMAC result. - */ - protected byte[] engineDoFinal() { - return hmac.doFinal(); - } - - /** - * Resets the HMAC for further use, maintaining the secret key that the - * HMAC was initialized with. - */ - protected void engineReset() { - hmac.reset(); - } - - /* - * Clones this object. - */ - public Object clone() { - HmacSHA1 that = null; - try { - that = (HmacSHA1)super.clone(); - that.hmac = (HmacCore)this.hmac.clone(); - } catch (CloneNotSupportedException e) { - } - return that; + super("SHA1", 64); } } diff --git a/jdk/src/share/classes/com/sun/crypto/provider/KeyGeneratorCore.java b/jdk/src/share/classes/com/sun/crypto/provider/KeyGeneratorCore.java index 708d80ba7db..9593bbfe0b0 100644 --- a/jdk/src/share/classes/com/sun/crypto/provider/KeyGeneratorCore.java +++ b/jdk/src/share/classes/com/sun/crypto/provider/KeyGeneratorCore.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -105,11 +105,11 @@ final class KeyGeneratorCore { return new SecretKeySpec(b, name); } - // nested static class for the HmacSHA256 key generator - public static final class HmacSHA256KG extends KeyGeneratorSpi { + // nested static classes for the HmacSHA-2 family of key generator + abstract static class HmacSHA2KG extends KeyGeneratorSpi { private final KeyGeneratorCore core; - public HmacSHA256KG() { - core = new KeyGeneratorCore("HmacSHA256", 256); + protected HmacSHA2KG(String algoName, int len) { + core = new KeyGeneratorCore(algoName, len); } protected void engineInit(SecureRandom random) { core.implInit(random); @@ -124,47 +124,26 @@ final class KeyGeneratorCore { protected SecretKey engineGenerateKey() { return core.implGenerateKey(); } - } - // nested static class for the HmacSHA384 key generator - public static final class HmacSHA384KG extends KeyGeneratorSpi { - private final KeyGeneratorCore core; - public HmacSHA384KG() { - core = new KeyGeneratorCore("HmacSHA384", 384); + public static final class SHA224 extends HmacSHA2KG { + public SHA224() { + super("HmacSHA224", 224); + } } - protected void engineInit(SecureRandom random) { - core.implInit(random); + public static final class SHA256 extends HmacSHA2KG { + public SHA256() { + super("HmacSHA256", 256); + } } - protected void engineInit(AlgorithmParameterSpec params, - SecureRandom random) throws InvalidAlgorithmParameterException { - core.implInit(params, random); + public static final class SHA384 extends HmacSHA2KG { + public SHA384() { + super("HmacSHA384", 384); + } } - protected void engineInit(int keySize, SecureRandom random) { - core.implInit(keySize, random); - } - protected SecretKey engineGenerateKey() { - return core.implGenerateKey(); - } - } - - // nested static class for the HmacSHA384 key generator - public static final class HmacSHA512KG extends KeyGeneratorSpi { - private final KeyGeneratorCore core; - public HmacSHA512KG() { - core = new KeyGeneratorCore("HmacSHA512", 512); - } - protected void engineInit(SecureRandom random) { - core.implInit(random); - } - protected void engineInit(AlgorithmParameterSpec params, - SecureRandom random) throws InvalidAlgorithmParameterException { - core.implInit(params, random); - } - protected void engineInit(int keySize, SecureRandom random) { - core.implInit(keySize, random); - } - protected SecretKey engineGenerateKey() { - return core.implGenerateKey(); + public static final class SHA512 extends HmacSHA2KG { + public SHA512() { + super("HmacSHA512", 512); + } } } diff --git a/jdk/src/share/classes/com/sun/crypto/provider/OAEPParameters.java b/jdk/src/share/classes/com/sun/crypto/provider/OAEPParameters.java index 61423f0d4e6..9b3cbc27449 100644 --- a/jdk/src/share/classes/com/sun/crypto/provider/OAEPParameters.java +++ b/jdk/src/share/classes/com/sun/crypto/provider/OAEPParameters.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -108,6 +108,8 @@ public final class OAEPParameters extends AlgorithmParametersSpi { private static String convertToStandardName(String internalName) { if (internalName.equals("SHA")) { return "SHA-1"; + } else if (internalName.equals("SHA224")) { + return "SHA-224"; } else if (internalName.equals("SHA256")) { return "SHA-256"; } else if (internalName.equals("SHA384")) { @@ -143,6 +145,8 @@ public final class OAEPParameters extends AlgorithmParametersSpi { String mgfDigestName = convertToStandardName(params.getName()); if (mgfDigestName.equals("SHA-1")) { mgfSpec = MGF1ParameterSpec.SHA1; + } else if (mgfDigestName.equals("SHA-224")) { + mgfSpec = MGF1ParameterSpec.SHA224; } else if (mgfDigestName.equals("SHA-256")) { mgfSpec = MGF1ParameterSpec.SHA256; } else if (mgfDigestName.equals("SHA-384")) { diff --git a/jdk/src/share/classes/com/sun/crypto/provider/SunJCE.java b/jdk/src/share/classes/com/sun/crypto/provider/SunJCE.java index c58236ba3e6..e7a815283b5 100644 --- a/jdk/src/share/classes/com/sun/crypto/provider/SunJCE.java +++ b/jdk/src/share/classes/com/sun/crypto/provider/SunJCE.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, 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 @@ -65,7 +65,7 @@ import java.security.SecureRandom; * * - Diffie-Hellman Key Agreement * - * - HMAC-MD5, HMAC-SHA1, HMAC-SHA-256, HMAC-SHA-384, HMAC-SHA-512 + * - HMAC-MD5, HMAC-SHA1, HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, HMAC-SHA-512 * */ @@ -113,6 +113,7 @@ public final class SunJCE extends Provider { "NOPADDING|PKCS1PADDING|OAEPWITHMD5ANDMGF1PADDING" + "|OAEPWITHSHA1ANDMGF1PADDING" + "|OAEPWITHSHA-1ANDMGF1PADDING" + + "|OAEPWITHSHA-224ANDMGF1PADDING" + "|OAEPWITHSHA-256ANDMGF1PADDING" + "|OAEPWITHSHA-384ANDMGF1PADDING" + "|OAEPWITHSHA-512ANDMGF1PADDING"); @@ -221,12 +222,25 @@ public final class SunJCE extends Provider { put("KeyGenerator.HmacSHA1", "com.sun.crypto.provider.HmacSHA1KeyGenerator"); + put("KeyGenerator.HmacSHA224", + "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA224"); + put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.8", "HmacSHA224"); + put("Alg.Alias.KeyGenerator.1.2.840.113549.2.8", "HmacSHA224"); + put("KeyGenerator.HmacSHA256", - "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA256KG"); + "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA256"); + put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.9", "HmacSHA256"); + put("Alg.Alias.KeyGenerator.1.2.840.113549.2.9", "HmacSHA256"); + put("KeyGenerator.HmacSHA384", - "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA384KG"); + "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA384"); + put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.10", "HmacSHA384"); + put("Alg.Alias.KeyGenerator.1.2.840.113549.2.10", "HmacSHA384"); + put("KeyGenerator.HmacSHA512", - "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA512KG"); + "com.sun.crypto.provider.KeyGeneratorCore$HmacSHA2KG$SHA512"); + put("Alg.Alias.KeyGenerator.OID.1.2.840.113549.2.11", "HmacSHA512"); + put("Alg.Alias.KeyGenerator.1.2.840.113549.2.11", "HmacSHA512"); put("KeyPairGenerator.DiffieHellman", "com.sun.crypto.provider.DHKeyPairGenerator"); @@ -389,12 +403,23 @@ public final class SunJCE extends Provider { */ put("Mac.HmacMD5", "com.sun.crypto.provider.HmacMD5"); put("Mac.HmacSHA1", "com.sun.crypto.provider.HmacSHA1"); + put("Mac.HmacSHA224", + "com.sun.crypto.provider.HmacCore$HmacSHA224"); + put("Alg.Alias.Mac.OID.1.2.840.113549.2.8", "HmacSHA224"); + put("Alg.Alias.Mac.1.2.840.113549.2.8", "HmacSHA224"); put("Mac.HmacSHA256", "com.sun.crypto.provider.HmacCore$HmacSHA256"); + put("Alg.Alias.Mac.OID.1.2.840.113549.2.9", "HmacSHA256"); + put("Alg.Alias.Mac.1.2.840.113549.2.9", "HmacSHA256"); put("Mac.HmacSHA384", "com.sun.crypto.provider.HmacCore$HmacSHA384"); + put("Alg.Alias.Mac.OID.1.2.840.113549.2.10", "HmacSHA384"); + put("Alg.Alias.Mac.1.2.840.113549.2.10", "HmacSHA384"); put("Mac.HmacSHA512", "com.sun.crypto.provider.HmacCore$HmacSHA512"); + put("Alg.Alias.Mac.OID.1.2.840.113549.2.11", "HmacSHA512"); + put("Alg.Alias.Mac.1.2.840.113549.2.11", "HmacSHA512"); + put("Mac.HmacPBESHA1", "com.sun.crypto.provider.HmacPKCS12PBESHA1"); @@ -405,6 +430,7 @@ public final class SunJCE extends Provider { put("Mac.HmacMD5 SupportedKeyFormats", "RAW"); put("Mac.HmacSHA1 SupportedKeyFormats", "RAW"); + put("Mac.HmacSHA224 SupportedKeyFormats", "RAW"); put("Mac.HmacSHA256 SupportedKeyFormats", "RAW"); put("Mac.HmacSHA384 SupportedKeyFormats", "RAW"); put("Mac.HmacSHA512 SupportedKeyFormats", "RAW"); diff --git a/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java b/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java index a18c0ac10bd..20c2743ee4b 100644 --- a/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java +++ b/jdk/src/share/classes/com/sun/rowset/FilteredRowSetImpl.java @@ -128,7 +128,7 @@ public class FilteredRowSetImpl extends WebRowSetImpl implements Serializable, C for(int rows=this.getRow(); rows<=this.size();rows++) { bool = super.internalNext(); - if( p == null) { + if( !bool || p == null) { return bool; } if(p.evaluate(this)){ diff --git a/jdk/src/share/classes/java/lang/Integer.java b/jdk/src/share/classes/java/lang/Integer.java index 88acdfa11da..c33e90a5e49 100644 --- a/jdk/src/share/classes/java/lang/Integer.java +++ b/jdk/src/share/classes/java/lang/Integer.java @@ -780,6 +780,9 @@ public final class Integer extends Number implements Comparable { int j = low; for(int k = 0; k < cache.length; k++) cache[k] = new Integer(j++); + + // range [-128, 127] must be interned (JLS7 5.1.7) + assert IntegerCache.high >= 127; } private IntegerCache() {} @@ -801,7 +804,6 @@ public final class Integer extends Number implements Comparable { * @since 1.5 */ public static Integer valueOf(int i) { - assert IntegerCache.high >= 127; if (i >= IntegerCache.low && i <= IntegerCache.high) return IntegerCache.cache[i + (-IntegerCache.low)]; return new Integer(i); diff --git a/jdk/src/share/classes/java/nio/MappedByteBuffer.java b/jdk/src/share/classes/java/nio/MappedByteBuffer.java index e07ed1e2e0b..b022e1ca0bf 100644 --- a/jdk/src/share/classes/java/nio/MappedByteBuffer.java +++ b/jdk/src/share/classes/java/nio/MappedByteBuffer.java @@ -139,6 +139,9 @@ public abstract class MappedByteBuffer return isLoaded0(mappingAddress(offset), length, Bits.pageCount(length)); } + // not used, but a potential target for a store, see load() for details. + private static byte unused; + /** * Loads this buffer's content into physical memory. * @@ -157,15 +160,20 @@ public abstract class MappedByteBuffer long length = mappingLength(offset); load0(mappingAddress(offset), length); - // touch each page + // Read a byte from each page to bring it into memory. A checksum + // is computed as we go along to prevent the compiler from otherwise + // considering the loop as dead code. Unsafe unsafe = Unsafe.getUnsafe(); int ps = Bits.pageSize(); int count = Bits.pageCount(length); long a = mappingAddress(offset); + byte x = 0; for (int i=0; i * OAEP-PSSDigestAlgorithms ALGORITHM-IDENTIFIER ::= { * { OID id-sha1 PARAMETERS NULL }| + * { OID id-sha224 PARAMETERS NULL }| * { OID id-sha256 PARAMETERS NULL }| * { OID id-sha384 PARAMETERS NULL }| * { OID id-sha512 PARAMETERS NULL }, @@ -62,6 +63,11 @@ public class MGF1ParameterSpec implements AlgorithmParameterSpec { */ public static final MGF1ParameterSpec SHA1 = new MGF1ParameterSpec("SHA-1"); + /** + * The MGF1ParameterSpec which uses "SHA-224" message digest. + */ + public static final MGF1ParameterSpec SHA224 = + new MGF1ParameterSpec("SHA-224"); /** * The MGF1ParameterSpec which uses "SHA-256" message digest. */ diff --git a/jdk/src/share/classes/java/security/spec/PSSParameterSpec.java b/jdk/src/share/classes/java/security/spec/PSSParameterSpec.java index e9f29b553a6..37a2eeb2625 100644 --- a/jdk/src/share/classes/java/security/spec/PSSParameterSpec.java +++ b/jdk/src/share/classes/java/security/spec/PSSParameterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2012, 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 @@ -47,6 +47,7 @@ import java.security.spec.MGF1ParameterSpec; *
  * OAEP-PSSDigestAlgorithms    ALGORITHM-IDENTIFIER ::= {
  *   { OID id-sha1 PARAMETERS NULL   }|
+ *   { OID id-sha224 PARAMETERS NULL   }|
  *   { OID id-sha256 PARAMETERS NULL }|
  *   { OID id-sha384 PARAMETERS NULL }|
  *   { OID id-sha512 PARAMETERS NULL },
diff --git a/jdk/src/share/classes/java/util/NoSuchElementException.java b/jdk/src/share/classes/java/util/NoSuchElementException.java
index 88ff2c079a4..15e1aad98c2 100644
--- a/jdk/src/share/classes/java/util/NoSuchElementException.java
+++ b/jdk/src/share/classes/java/util/NoSuchElementException.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1994, 2012, 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
@@ -26,13 +26,12 @@
 package java.util;
 
 /**
- * Thrown by the nextElement method of an
- * Enumeration to indicate that there are no more
- * elements in the enumeration.
+ * Thrown by various accessor methods to indicate that the element being requested
+ * does not exist.
  *
  * @author  unascribed
- * @see     java.util.Enumeration
  * @see     java.util.Enumeration#nextElement()
+ * @see     java.util.Iterator#next()
  * @since   JDK1.0
  */
 public
diff --git a/jdk/src/share/classes/java/util/UUID.java b/jdk/src/share/classes/java/util/UUID.java
index 448429849b9..d3d8c242b4f 100644
--- a/jdk/src/share/classes/java/util/UUID.java
+++ b/jdk/src/share/classes/java/util/UUID.java
@@ -90,9 +90,11 @@ public final class UUID implements java.io.Serializable, Comparable {
 
     /*
      * The random number generator used by this class to create random
-     * based UUIDs.
+     * based UUIDs. In a holder class to defer initialization until needed.
      */
-    private static volatile SecureRandom numberGenerator = null;
+    private static class Holder {
+        static final SecureRandom numberGenerator = new SecureRandom();
+    }
 
     // Constructors and Factories
 
@@ -137,10 +139,7 @@ public final class UUID implements java.io.Serializable, Comparable {
      * @return  A randomly generated {@code UUID}
      */
     public static UUID randomUUID() {
-        SecureRandom ng = numberGenerator;
-        if (ng == null) {
-            numberGenerator = ng = new SecureRandom();
-        }
+        SecureRandom ng = Holder.numberGenerator;
 
         byte[] randomBytes = new byte[16];
         ng.nextBytes(randomBytes);
@@ -255,7 +254,8 @@ public final class UUID implements java.io.Serializable, Comparable {
      * The variant number has the following meaning:
      * 

    *
  • 0 Reserved for NCS backward compatibility - *
  • 2 The Leach-Salz variant (used by this class) + *
  • 2 IETF RFC 4122 + * (Leach-Salz), used by this class *
  • 6 Reserved, Microsoft Corporation backward compatibility *
  • 7 Reserved for future definition *
@@ -265,7 +265,7 @@ public final class UUID implements java.io.Serializable, Comparable { public int variant() { // This field is composed of a varying number of bits. // 0 - - Reserved for NCS backward compatibility - // 1 0 - The Leach-Salz variant (used by this class) + // 1 0 - The IETF aka Leach-Salz variant (used by this class) // 1 1 0 Reserved, Microsoft backward compatibility // 1 1 1 Reserved for future definition. return (int) ((leastSigBits >>> (64 - (leastSigBits >>> 62))) diff --git a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java index 9f4fee4aa84..dc26f4c0ba7 100644 --- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java +++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java @@ -35,7 +35,11 @@ package java.util.concurrent.atomic; import sun.misc.Unsafe; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; /** * A reflection-based utility that enables atomic updates to @@ -67,7 +71,9 @@ public abstract class AtomicIntegerFieldUpdater { * @throws IllegalArgumentException if the field is not a * volatile integer type * @throws RuntimeException with a nested reflection-based - * exception if the class does not hold field or is the wrong type + * exception if the class does not hold field or is the wrong type, + * or the field is inaccessible to the caller according to Java language + * access control */ public static AtomicIntegerFieldUpdater newUpdater(Class tclass, String fieldName) { return new AtomicIntegerFieldUpdaterImpl(tclass, fieldName); @@ -267,17 +273,29 @@ public abstract class AtomicIntegerFieldUpdater { private final Class tclass; private final Class cclass; - AtomicIntegerFieldUpdaterImpl(Class tclass, String fieldName) { + AtomicIntegerFieldUpdaterImpl(final Class tclass, final String fieldName) { Field field = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -295,6 +313,22 @@ public abstract class AtomicIntegerFieldUpdater { offset = unsafe.objectFieldOffset(field); } + /** + * Returns true if the second classloader can be found in the first + * classloader's delegation chain. + * Equivalent to the inaccessible: first.isAncestor(second). + */ + private static boolean isAncestor(ClassLoader first, ClassLoader second) { + ClassLoader acl = first; + do { + acl = acl.getParent(); + if (second == acl) { + return true; + } + } while (acl != null); + return false; + } + private void fullCheck(T obj) { if (!tclass.isInstance(obj)) throw new ClassCastException(); diff --git a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java index ccc5acbfe21..3311aecdbfb 100644 --- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java +++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicLongFieldUpdater.java @@ -35,7 +35,11 @@ package java.util.concurrent.atomic; import sun.misc.Unsafe; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; /** * A reflection-based utility that enables atomic updates to @@ -67,7 +71,9 @@ public abstract class AtomicLongFieldUpdater { * @throws IllegalArgumentException if the field is not a * volatile long type. * @throws RuntimeException with a nested reflection-based - * exception if the class does not hold field or is the wrong type. + * exception if the class does not hold field or is the wrong type, + * or the field is inaccessible to the caller according to Java language + * access control */ public static AtomicLongFieldUpdater newUpdater(Class tclass, String fieldName) { if (AtomicLong.VM_SUPPORTS_LONG_CAS) @@ -267,17 +273,29 @@ public abstract class AtomicLongFieldUpdater { private final Class tclass; private final Class cclass; - CASUpdater(Class tclass, String fieldName) { + CASUpdater(final Class tclass, final String fieldName) { Field field = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -350,17 +368,29 @@ public abstract class AtomicLongFieldUpdater { private final Class tclass; private final Class cclass; - LockedUpdater(Class tclass, String fieldName) { + LockedUpdater(final Class tclass, final String fieldName) { Field field = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -433,4 +463,20 @@ public abstract class AtomicLongFieldUpdater { ); } } + + /** + * Returns true if the second classloader can be found in the first + * classloader's delegation chain. + * Equivalent to the inaccessible: first.isAncestor(second). + */ + private static boolean isAncestor(ClassLoader first, ClassLoader second) { + ClassLoader acl = first; + do { + acl = acl.getParent(); + if (second == acl) { + return true; + } + } while (acl != null); + return false; + } } diff --git a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java index f2e0118aae7..bba703e67ec 100644 --- a/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java +++ b/jdk/src/share/classes/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java @@ -35,7 +35,11 @@ package java.util.concurrent.atomic; import sun.misc.Unsafe; -import java.lang.reflect.*; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; /** * A reflection-based utility that enables atomic updates to @@ -86,7 +90,9 @@ public abstract class AtomicReferenceFieldUpdater { * @return the updater * @throws IllegalArgumentException if the field is not a volatile reference type. * @throws RuntimeException with a nested reflection-based - * exception if the class does not hold field or is the wrong type. + * exception if the class does not hold field or is the wrong type, + * or the field is inaccessible to the caller according to Java language + * access control */ public static AtomicReferenceFieldUpdater newUpdater(Class tclass, Class vclass, String fieldName) { return new AtomicReferenceFieldUpdaterImpl(tclass, @@ -197,21 +203,33 @@ public abstract class AtomicReferenceFieldUpdater { * screenings fail. */ - AtomicReferenceFieldUpdaterImpl(Class tclass, + AtomicReferenceFieldUpdaterImpl(final Class tclass, Class vclass, - String fieldName) { + final String fieldName) { Field field = null; Class fieldClass = null; Class caller = null; int modifiers = 0; try { - field = tclass.getDeclaredField(fieldName); + field = AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public Field run() throws NoSuchFieldException { + return tclass.getDeclaredField(fieldName); + } + }); caller = sun.reflect.Reflection.getCallerClass(3); modifiers = field.getModifiers(); sun.reflect.misc.ReflectUtil.ensureMemberAccess( - caller, tclass, null, modifiers); - sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + caller, tclass, null, modifiers); + ClassLoader cl = tclass.getClassLoader(); + ClassLoader ccl = caller.getClassLoader(); + if ((ccl != null) && (ccl != cl) && + ((cl == null) || !isAncestor(cl, ccl))) { + sun.reflect.misc.ReflectUtil.checkPackageAccess(tclass); + } fieldClass = field.getType(); + } catch (PrivilegedActionException pae) { + throw new RuntimeException(pae.getException()); } catch (Exception ex) { throw new RuntimeException(ex); } @@ -232,6 +250,22 @@ public abstract class AtomicReferenceFieldUpdater { offset = unsafe.objectFieldOffset(field); } + /** + * Returns true if the second classloader can be found in the first + * classloader's delegation chain. + * Equivalent to the inaccessible: first.isAncestor(second). + */ + private static boolean isAncestor(ClassLoader first, ClassLoader second) { + ClassLoader acl = first; + do { + acl = acl.getParent(); + if (second == acl) { + return true; + } + } while (acl != null); + return false; + } + void targetCheck(T obj) { if (!tclass.isInstance(obj)) throw new ClassCastException(); @@ -281,7 +315,7 @@ public abstract class AtomicReferenceFieldUpdater { } @SuppressWarnings("unchecked") - public V get(T obj) { + public V get(T obj) { if (obj == null || obj.getClass() != tclass || cclass != null) targetCheck(obj); return (V)unsafe.getObjectVolatile(obj, offset); @@ -292,14 +326,14 @@ public abstract class AtomicReferenceFieldUpdater { return; } throw new RuntimeException( - new IllegalAccessException("Class " + - cclass.getName() + - " can not access a protected member of class " + - tclass.getName() + - " using an instance of " + - obj.getClass().getName() - ) - ); + new IllegalAccessException("Class " + + cclass.getName() + + " can not access a protected member of class " + + tclass.getName() + + " using an instance of " + + obj.getClass().getName() + ) + ); } } } diff --git a/jdk/src/share/classes/java/util/prefs/AbstractPreferences.java b/jdk/src/share/classes/java/util/prefs/AbstractPreferences.java index f4a7e5e0a39..5ba264e5354 100644 --- a/jdk/src/share/classes/java/util/prefs/AbstractPreferences.java +++ b/jdk/src/share/classes/java/util/prefs/AbstractPreferences.java @@ -305,8 +305,10 @@ public abstract class AbstractPreferences extends Preferences { * @param key key whose mapping is to be removed from the preference node. * @throws IllegalStateException if this node (or an ancestor) has been * removed with the {@link #removeNode()} method. + * @throws NullPointerException {@inheritDoc}. */ public void remove(String key) { + Objects.requireNonNull(key, "Specified key cannot be null"); synchronized(lock) { if (removed) throw new IllegalStateException("Node has been removed."); diff --git a/jdk/src/share/classes/java/util/regex/Pattern.java b/jdk/src/share/classes/java/util/regex/Pattern.java index 626d5b08657..6c32f6a30bb 100644 --- a/jdk/src/share/classes/java/util/regex/Pattern.java +++ b/jdk/src/share/classes/java/util/regex/Pattern.java @@ -152,15 +152,24 @@ import java.util.Arrays; * A digit: [0-9] * \D * A non-digit: [^0-9] + * \h + * A horizontal whitespace character: + * [ \t\xA0\u1680\u180e\u2000-\u200a\u202f\u205f\u3000] + * \H + * A non-horizontal whitespace character: [^\h] * \s * A whitespace character: [ \t\n\x0B\f\r] * \S * A non-whitespace character: [^\s] + * \v + * A vertical whitespace character: [\n\x0B\f\r\x85\u2028\u2029] + * + * \V + * A non-vertical whitespace character: [^\v] * \w * A word character: [a-zA-Z_0-9] * \W * A non-word character: [^\w] - * *   * POSIX character classes (US-ASCII only) * @@ -244,6 +253,13 @@ import java.util.Arrays; * The end of the input * *   + * Linebreak matcher + * \R + * Any Unicode linebreak sequence, is equivalent to + * \u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029] + * + * + *   * Greedy quantifiers * * X? @@ -599,11 +615,9 @@ import java.util.Arrays; *
  • Noncharacter_Code_Point *
  • Assigned * - - *

    - * Predefined Character classes and POSIX character classes are in - * conformance with the recommendation of Annex C: Compatibility Properties + * The following Predefined Character classes and POSIX character classes + * are in conformance with the recommendation of Annex C: Compatibility Properties * of Unicode Regular Expression * , when {@link #UNICODE_CHARACTER_CLASS} flag is specified. *

    @@ -668,12 +682,6 @@ import java.util.Arrays; * *

      *
    • Predefined character classes (Unicode character) - *

      \h    A horizontal whitespace - *

      \H    A non horizontal whitespace - *

      \v    A vertical whitespace - *

      \V    A non vertical whitespace - *

      \R    Any Unicode linebreak sequence - * \u005cu000D\u005cu000A|[\u005cu000A\u005cu000B\u005cu000C\u005cu000D\u005cu0085\u005cu2028\u005cu2029] *

      \X    Match Unicode * * extended grapheme cluster @@ -2178,7 +2186,7 @@ loop: for(int x=0, offset=0; x= 0) { append(ch, first); first++; @@ -2276,7 +2284,7 @@ loop: for(int x=0, offset=0; x= 0) { if (peek() == '-') { @@ -2606,9 +2636,15 @@ loop: for(int x=0, offset=0; x= 0x0A && cp <= 0x0D) || + cp == 0x85 || cp == 0x2028 || cp == 0x2029; + } + } + + /** + * Node class that matches a Perl horizontal whitespace + */ + static final class HorizWS extends BmpCharProperty { + boolean isSatisfiedBy(int cp) { + return cp == 0x09 || cp == 0x20 || cp == 0xa0 || + cp == 0x1680 || cp == 0x180e || + cp >= 0x2000 && cp <= 0x200a || + cp == 0x202f || cp == 0x205f || cp == 0x3000; + } + } + /** * Base class for all Slice nodes */ diff --git a/jdk/src/share/classes/sun/management/Agent.java b/jdk/src/share/classes/sun/management/Agent.java index 7f65e5ceb9f..19d2dedb5b4 100644 --- a/jdk/src/share/classes/sun/management/Agent.java +++ b/jdk/src/share/classes/sun/management/Agent.java @@ -168,7 +168,10 @@ public class Agent { // management properties can be overridden by system properties // which take precedence - configProps.putAll(System.getProperties()); + Properties sysProps = System.getProperties(); + synchronized(sysProps){ + configProps.putAll(sysProps); + } // if user specifies config file into command line for either // jcmd utilities or attach command it overrides properties set in @@ -264,7 +267,10 @@ public class Agent { // management properties can be overridden by system properties // which take precedence - props.putAll(System.getProperties()); + Properties sysProps = System.getProperties(); + synchronized(sysProps){ + props.putAll(sysProps); + } return props; } diff --git a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java index fe2c5fe33ac..f0f72551614 100644 --- a/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/jdk/src/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -629,17 +629,6 @@ class SocketChannelImpl break; } - synchronized (stateLock) { - if (isOpen() && (localAddress == null) || - ((InetSocketAddress)localAddress) - .getAddress().isAnyLocalAddress()) - { - // Socket was not bound before connecting or - // Socket was bound with an "anyLocalAddress" - localAddress = Net.localAddress(fd); - } - } - } finally { readerCleanup(); end((n > 0) || (n == IOStatus.UNAVAILABLE)); @@ -659,6 +648,8 @@ class SocketChannelImpl // Connection succeeded; disallow further // invocation state = ST_CONNECTED; + if (isOpen()) + localAddress = Net.localAddress(fd); return true; } // If nonblocking and no exception then connection @@ -747,6 +738,8 @@ class SocketChannelImpl if (n > 0) { synchronized (stateLock) { state = ST_CONNECTED; + if (isOpen()) + localAddress = Net.localAddress(fd); } return true; } diff --git a/jdk/src/share/classes/sun/security/ec/ECDSASignature.java b/jdk/src/share/classes/sun/security/ec/ECDSASignature.java index 0d68225c9b0..64a36b1c894 100644 --- a/jdk/src/share/classes/sun/security/ec/ECDSASignature.java +++ b/jdk/src/share/classes/sun/security/ec/ECDSASignature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2012, 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 @@ -41,6 +41,7 @@ import sun.security.util.*; * * . "NONEwithECDSA" * . "SHA1withECDSA" + * . "SHA224withECDSA" * . "SHA256withECDSA" * . "SHA384withECDSA" * . "SHA512withECDSA" @@ -162,6 +163,13 @@ abstract class ECDSASignature extends SignatureSpi { } } + // Nested class for SHA224withECDSA signatures + public static final class SHA224 extends ECDSASignature { + public SHA224() { + super("SHA-224"); + } + } + // Nested class for SHA256withECDSA signatures public static final class SHA256 extends ECDSASignature { public SHA256() { diff --git a/jdk/src/share/classes/sun/security/ec/SunECEntries.java b/jdk/src/share/classes/sun/security/ec/SunECEntries.java index 91c56697339..6d2cb65a77a 100644 --- a/jdk/src/share/classes/sun/security/ec/SunECEntries.java +++ b/jdk/src/share/classes/sun/security/ec/SunECEntries.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2012, 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 @@ -133,17 +133,31 @@ final class SunECEntries { "sun.security.ec.ECDSASignature$Raw"); map.put("Signature.SHA1withECDSA", "sun.security.ec.ECDSASignature$SHA1"); + map.put("Signature.SHA224withECDSA", + "sun.security.ec.ECDSASignature$SHA224"); + map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.1", "SHA224withECDSA"); + map.put("Alg.Alias.Signature.1.2.840.10045.4.3.1", "SHA224withECDSA"); + map.put("Signature.SHA256withECDSA", "sun.security.ec.ECDSASignature$SHA256"); + map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.2", "SHA256withECDSA"); + map.put("Alg.Alias.Signature.1.2.840.10045.4.3.2", "SHA256withECDSA"); + map.put("Signature.SHA384withECDSA", "sun.security.ec.ECDSASignature$SHA384"); + map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.3", "SHA384withECDSA"); + map.put("Alg.Alias.Signature.1.2.840.10045.4.3.3", "SHA384withECDSA"); + map.put("Signature.SHA512withECDSA", "sun.security.ec.ECDSASignature$SHA512"); + map.put("Alg.Alias.Signature.OID.1.2.840.10045.4.3.4", "SHA512withECDSA"); + map.put("Alg.Alias.Signature.1.2.840.10045.4.3.4", "SHA512withECDSA"); String ecKeyClasses = "java.security.interfaces.ECPublicKey" + "|java.security.interfaces.ECPrivateKey"; map.put("Signature.NONEwithECDSA SupportedKeyClasses", ecKeyClasses); map.put("Signature.SHA1withECDSA SupportedKeyClasses", ecKeyClasses); + map.put("Signature.SHA224withECDSA SupportedKeyClasses", ecKeyClasses); map.put("Signature.SHA256withECDSA SupportedKeyClasses", ecKeyClasses); map.put("Signature.SHA384withECDSA SupportedKeyClasses", ecKeyClasses); map.put("Signature.SHA512withECDSA SupportedKeyClasses", ecKeyClasses); @@ -152,6 +166,7 @@ final class SunECEntries { map.put("Signature.NONEwithECDSA ImplementedIn", "Software"); map.put("Signature.SHA1withECDSA ImplementedIn", "Software"); + map.put("Signature.SHA224withECDSA ImplementedIn", "Software"); map.put("Signature.SHA256withECDSA ImplementedIn", "Software"); map.put("Signature.SHA384withECDSA ImplementedIn", "Software"); map.put("Signature.SHA512withECDSA ImplementedIn", "Software"); diff --git a/jdk/src/share/classes/sun/security/pkcs11/P11Digest.java b/jdk/src/share/classes/sun/security/pkcs11/P11Digest.java index 08f22fffc11..2dc66d2368b 100644 --- a/jdk/src/share/classes/sun/security/pkcs11/P11Digest.java +++ b/jdk/src/share/classes/sun/security/pkcs11/P11Digest.java @@ -39,7 +39,7 @@ import static sun.security.pkcs11.wrapper.PKCS11Constants.*; /** * MessageDigest implementation class. This class currently supports - * MD2, MD5, SHA-1, SHA-256, SHA-384, and SHA-512. + * MD2, MD5, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512. * * Note that many digest operations are on fairly small amounts of data * (less than 100 bytes total). For example, the 2nd hashing in HMAC or @@ -99,6 +99,9 @@ final class P11Digest extends MessageDigestSpi implements Cloneable { case (int)CKM_SHA_1: digestLength = 20; break; + case (int)CKM_SHA224: + digestLength = 28; + break; case (int)CKM_SHA256: digestLength = 32; break; diff --git a/jdk/src/share/classes/sun/security/pkcs11/P11Mac.java b/jdk/src/share/classes/sun/security/pkcs11/P11Mac.java index b32ee7affeb..2b0cbbcdf50 100644 --- a/jdk/src/share/classes/sun/security/pkcs11/P11Mac.java +++ b/jdk/src/share/classes/sun/security/pkcs11/P11Mac.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -40,8 +40,8 @@ import static sun.security.pkcs11.wrapper.PKCS11Constants.*; /** * MAC implementation class. This class currently supports HMAC using - * MD5, SHA-1, SHA-256, SHA-384, and SHA-512 and the SSL3 MAC using MD5 - * and SHA-1. + * MD5, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 and the SSL3 MAC + * using MD5 and SHA-1. * * Note that unlike other classes (e.g. Signature), this does not * composite various operations if the token only supports part of the @@ -107,6 +107,9 @@ final class P11Mac extends MacSpi { case (int)CKM_SHA_1_HMAC: macLength = 20; break; + case (int)CKM_SHA224_HMAC: + macLength = 28; + break; case (int)CKM_SHA256_HMAC: macLength = 32; break; diff --git a/jdk/src/share/classes/sun/security/pkcs11/P11Signature.java b/jdk/src/share/classes/sun/security/pkcs11/P11Signature.java index 70a79e46bdf..3c94ad6d3ab 100644 --- a/jdk/src/share/classes/sun/security/pkcs11/P11Signature.java +++ b/jdk/src/share/classes/sun/security/pkcs11/P11Signature.java @@ -53,12 +53,14 @@ import static sun.security.pkcs11.wrapper.PKCS11Constants.*; * . MD2withRSA * . MD5withRSA * . SHA1withRSA + * . SHA224withRSA * . SHA256withRSA * . SHA384withRSA * . SHA512withRSA * . ECDSA * . NONEwithECDSA * . SHA1withECDSA + * . SHA224withECDSA * . SHA256withECDSA * . SHA384withECDSA * . SHA512withECDSA @@ -143,6 +145,7 @@ final class P11Signature extends SignatureSpi { case (int)CKM_MD2_RSA_PKCS: case (int)CKM_MD5_RSA_PKCS: case (int)CKM_SHA1_RSA_PKCS: + case (int)CKM_SHA224_RSA_PKCS: case (int)CKM_SHA256_RSA_PKCS: case (int)CKM_SHA384_RSA_PKCS: case (int)CKM_SHA512_RSA_PKCS: @@ -181,6 +184,8 @@ final class P11Signature extends SignatureSpi { String digestAlg; if (algorithm.equals("SHA1withECDSA")) { digestAlg = "SHA-1"; + } else if (algorithm.equals("SHA224withECDSA")) { + digestAlg = "SHA-224"; } else if (algorithm.equals("SHA256withECDSA")) { digestAlg = "SHA-256"; } else if (algorithm.equals("SHA384withECDSA")) { @@ -207,6 +212,9 @@ final class P11Signature extends SignatureSpi { } else if (algorithm.equals("MD2withRSA")) { md = MessageDigest.getInstance("MD2"); digestOID = AlgorithmId.MD2_oid; + } else if (algorithm.equals("SHA224withRSA")) { + md = MessageDigest.getInstance("SHA-224"); + digestOID = AlgorithmId.SHA224_oid; } else if (algorithm.equals("SHA256withRSA")) { md = MessageDigest.getInstance("SHA-256"); digestOID = AlgorithmId.SHA256_oid; @@ -332,6 +340,8 @@ final class P11Signature extends SignatureSpi { encodedLength = 34; } else if (algorithm.equals("SHA1withRSA")) { encodedLength = 35; + } else if (algorithm.equals("SHA224withRSA")) { + encodedLength = 47; } else if (algorithm.equals("SHA256withRSA")) { encodedLength = 51; } else if (algorithm.equals("SHA384withRSA")) { diff --git a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java index 8c432571e3a..bac38137f16 100644 --- a/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java +++ b/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java @@ -342,6 +342,7 @@ public final class SunPKCS11 extends AuthProvider { System.out.println("Library info:"); System.out.println(p11Info); } + if ((slotID < 0) || showInfo) { long[] slots = p11.C_GetSlotList(false); if (showInfo) { @@ -520,24 +521,37 @@ public final class SunPKCS11 extends AuthProvider { m(CKM_MD2)); d(MD, "MD5", P11Digest, m(CKM_MD5)); - d(MD, "SHA1", P11Digest, s("SHA", "SHA-1"), + d(MD, "SHA1", P11Digest, s("SHA", "SHA-1"), m(CKM_SHA_1)); + + d(MD, "SHA-224", P11Digest, + s("2.16.840.1.101.3.4.2.4", "OID.2.16.840.1.101.3.4.2.4"), + m(CKM_SHA224)); d(MD, "SHA-256", P11Digest, + s("2.16.840.1.101.3.4.2.1", "OID.2.16.840.1.101.3.4.2.1"), m(CKM_SHA256)); d(MD, "SHA-384", P11Digest, + s("2.16.840.1.101.3.4.2.2", "OID.2.16.840.1.101.3.4.2.2"), m(CKM_SHA384)); d(MD, "SHA-512", P11Digest, + s("2.16.840.1.101.3.4.2.3", "OID.2.16.840.1.101.3.4.2.3"), m(CKM_SHA512)); d(MAC, "HmacMD5", P11MAC, m(CKM_MD5_HMAC)); d(MAC, "HmacSHA1", P11MAC, m(CKM_SHA_1_HMAC)); + d(MAC, "HmacSHA224", P11MAC, + s("1.2.840.113549.2.8", "OID.1.2.840.113549.2.8"), + m(CKM_SHA224_HMAC)); d(MAC, "HmacSHA256", P11MAC, + s("1.2.840.113549.2.9", "OID.1.2.840.113549.2.9"), m(CKM_SHA256_HMAC)); d(MAC, "HmacSHA384", P11MAC, + s("1.2.840.113549.2.10", "OID.1.2.840.113549.2.10"), m(CKM_SHA384_HMAC)); d(MAC, "HmacSHA512", P11MAC, + s("1.2.840.113549.2.11", "OID.1.2.840.113549.2.11"), m(CKM_SHA512_HMAC)); d(MAC, "SslMacMD5", P11MAC, m(CKM_SSL3_MD5_MAC)); @@ -648,11 +662,17 @@ public final class SunPKCS11 extends AuthProvider { m(CKM_ECDSA)); d(SIG, "SHA1withECDSA", P11Signature, s("ECDSA"), m(CKM_ECDSA_SHA1, CKM_ECDSA)); + d(SIG, "SHA224withECDSA", P11Signature, + s("1.2.840.10045.4.3.1", "OID.1.2.840.10045.4.3.1"), + m(CKM_ECDSA)); d(SIG, "SHA256withECDSA", P11Signature, + s("1.2.840.10045.4.3.2", "OID.1.2.840.10045.4.3.2"), m(CKM_ECDSA)); d(SIG, "SHA384withECDSA", P11Signature, + s("1.2.840.10045.4.3.3", "OID.1.2.840.10045.4.3.3"), m(CKM_ECDSA)); d(SIG, "SHA512withECDSA", P11Signature, + s("1.2.840.10045.4.3.4", "OID.1.2.840.10045.4.3.4"), m(CKM_ECDSA)); d(SIG, "MD2withRSA", P11Signature, m(CKM_MD2_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); @@ -660,11 +680,17 @@ public final class SunPKCS11 extends AuthProvider { m(CKM_MD5_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); d(SIG, "SHA1withRSA", P11Signature, m(CKM_SHA1_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); + d(SIG, "SHA224withRSA", P11Signature, + s("1.2.840.113549.1.1.14", "OID.1.2.840.113549.1.1.14"), + m(CKM_SHA224_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); d(SIG, "SHA256withRSA", P11Signature, + s("1.2.840.113549.1.1.11", "OID.1.2.840.113549.1.1.11"), m(CKM_SHA256_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); d(SIG, "SHA384withRSA", P11Signature, + s("1.2.840.113549.1.1.12", "OID.1.2.840.113549.1.1.12"), m(CKM_SHA384_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); d(SIG, "SHA512withRSA", P11Signature, + s("1.2.840.113549.1.1.13", "OID.1.2.840.113549.1.1.13"), m(CKM_SHA512_RSA_PKCS, CKM_RSA_PKCS, CKM_RSA_X_509)); /* diff --git a/jdk/src/share/classes/sun/security/pkcs11/wrapper/Functions.java b/jdk/src/share/classes/sun/security/pkcs11/wrapper/Functions.java index fa7ad073598..58f778ebbe2 100644 --- a/jdk/src/share/classes/sun/security/pkcs11/wrapper/Functions.java +++ b/jdk/src/share/classes/sun/security/pkcs11/wrapper/Functions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. */ /* Copyright (c) 2002 Graz University of Technology. All rights reserved. @@ -630,6 +630,7 @@ public class Functions { addMech(CKM_X9_42_DH_DERIVE, "CKM_X9_42_DH_DERIVE"); addMech(CKM_X9_42_DH_HYBRID_DERIVE, "CKM_X9_42_DH_HYBRID_DERIVE"); addMech(CKM_X9_42_MQV_DERIVE, "CKM_X9_42_MQV_DERIVE"); + addMech(CKM_SHA224_RSA_PKCS, "CKM_SHA224_RSA_PKCS"); addMech(CKM_SHA256_RSA_PKCS, "CKM_SHA256_RSA_PKCS"); addMech(CKM_SHA384_RSA_PKCS, "CKM_SHA384_RSA_PKCS"); addMech(CKM_SHA512_RSA_PKCS, "CKM_SHA512_RSA_PKCS"); @@ -675,6 +676,9 @@ public class Functions { addMech(CKM_RIPEMD160, "CKM_RIPEMD160"); addMech(CKM_RIPEMD160_HMAC, "CKM_RIPEMD160_HMAC"); addMech(CKM_RIPEMD160_HMAC_GENERAL, "CKM_RIPEMD160_HMAC_GENERAL"); + addMech(CKM_SHA224, "CKM_SHA224"); + addMech(CKM_SHA224_HMAC, "CKM_SHA224_HMAC"); + addMech(CKM_SHA224_HMAC_GENERAL, "CKM_SHA224_HMAC_GENERAL"); addMech(CKM_SHA256, "CKM_SHA256"); addMech(CKM_SHA256_HMAC, "CKM_SHA256_HMAC"); addMech(CKM_SHA256_HMAC_GENERAL, "CKM_SHA256_HMAC_GENERAL"); @@ -734,6 +738,7 @@ public class Functions { addMech(CKM_MD5_KEY_DERIVATION, "CKM_MD5_KEY_DERIVATION"); addMech(CKM_MD2_KEY_DERIVATION, "CKM_MD2_KEY_DERIVATION"); addMech(CKM_SHA1_KEY_DERIVATION, "CKM_SHA1_KEY_DERIVATION"); + addMech(CKM_SHA224_KEY_DERIVATION, "CKM_SHA224_KEY_DERIVATION"); addMech(CKM_SHA256_KEY_DERIVATION, "CKM_SHA256_KEY_DERIVATION"); addMech(CKM_SHA384_KEY_DERIVATION, "CKM_SHA384_KEY_DERIVATION"); addMech(CKM_SHA512_KEY_DERIVATION, "CKM_SHA512_KEY_DERIVATION"); diff --git a/jdk/src/share/classes/sun/security/provider/DigestBase.java b/jdk/src/share/classes/sun/security/provider/DigestBase.java index 2c7b719b0bc..cbca1235fe6 100644 --- a/jdk/src/share/classes/sun/security/provider/DigestBase.java +++ b/jdk/src/share/classes/sun/security/provider/DigestBase.java @@ -39,7 +39,6 @@ import java.security.ProviderException; * . abstract void implCompress(byte[] b, int ofs); * . abstract void implDigest(byte[] out, int ofs); * . abstract void implReset(); - * . public abstract Object clone(); * * See the inline documentation for details. * @@ -61,7 +60,7 @@ abstract class DigestBase extends MessageDigestSpi implements Cloneable { // buffer to store partial blocks, blockSize bytes large // Subclasses should not access this array directly except possibly in their // implDigest() method. See MD5.java as an example. - final byte[] buffer; + byte[] buffer; // offset into buffer private int bufOfs; @@ -83,18 +82,6 @@ abstract class DigestBase extends MessageDigestSpi implements Cloneable { buffer = new byte[blockSize]; } - /** - * Constructor for cloning. Replicates common data. - */ - DigestBase(DigestBase base) { - this.algorithm = base.algorithm; - this.digestLength = base.digestLength; - this.blockSize = base.blockSize; - this.buffer = base.buffer.clone(); - this.bufOfs = base.bufOfs; - this.bytesProcessed = base.bytesProcessed; - } - // return digest length. See JCA doc. protected final int engineGetDigestLength() { return digestLength; @@ -206,12 +193,11 @@ abstract class DigestBase extends MessageDigestSpi implements Cloneable { */ abstract void implReset(); - /** - * Clone this digest. Should be implemented as "return new MyDigest(this)". - * That constructor should first call "super(baseDigest)" and then copy - * subclass specific data. - */ - public abstract Object clone(); + public Object clone() throws CloneNotSupportedException { + DigestBase copy = (DigestBase) super.clone(); + copy.buffer = copy.buffer.clone(); + return copy; + } // padding used for the MD5, and SHA-* message digests static final byte[] padding; @@ -223,5 +209,4 @@ abstract class DigestBase extends MessageDigestSpi implements Cloneable { padding = new byte[136]; padding[0] = (byte)0x80; } - } diff --git a/jdk/src/share/classes/sun/security/provider/MD2.java b/jdk/src/share/classes/sun/security/provider/MD2.java index c0c116ae84a..5d0a3e3e827 100644 --- a/jdk/src/share/classes/sun/security/provider/MD2.java +++ b/jdk/src/share/classes/sun/security/provider/MD2.java @@ -39,14 +39,14 @@ import java.util.Arrays; public final class MD2 extends DigestBase { // state, 48 ints - private final int[] X; + private int[] X; // checksum, 16 ints. they are really bytes, but byte arithmetic in // the JVM is much slower that int arithmetic. - private final int[] C; + private int[] C; // temporary store for checksum C during final digest - private final byte[] cBytes; + private byte[] cBytes; /** * Create a new MD2 digest. Called by the JCA framework @@ -58,15 +58,12 @@ public final class MD2 extends DigestBase { cBytes = new byte[16]; } - private MD2(MD2 base) { - super(base); - this.X = base.X.clone(); - this.C = base.C.clone(); - cBytes = new byte[16]; - } - - public Object clone() { - return new MD2(this); + public Object clone() throws CloneNotSupportedException { + MD2 copy = (MD2) super.clone(); + copy.X = copy.X.clone(); + copy.C = copy.C.clone(); + copy.cBytes = new byte[16]; + return copy; } // reset state and checksum diff --git a/jdk/src/share/classes/sun/security/provider/MD4.java b/jdk/src/share/classes/sun/security/provider/MD4.java index 56ff5a06ae3..e51b2485499 100644 --- a/jdk/src/share/classes/sun/security/provider/MD4.java +++ b/jdk/src/share/classes/sun/security/provider/MD4.java @@ -44,9 +44,9 @@ import static sun.security.provider.ByteArrayAccess.*; public final class MD4 extends DigestBase { // state of this object - private final int[] state; + private int[] state; // temporary buffer, used by implCompress() - private final int[] x; + private int[] x; // rotation constants private static final int S11 = 3; @@ -93,16 +93,12 @@ public final class MD4 extends DigestBase { implReset(); } - // Cloning constructor - private MD4(MD4 base) { - super(base); - this.state = base.state.clone(); - this.x = new int[16]; - } - // clone this object - public Object clone() { - return new MD4(this); + public Object clone() throws CloneNotSupportedException { + MD4 copy = (MD4) super.clone(); + copy.state = copy.state.clone(); + copy.x = new int[16]; + return copy; } /** diff --git a/jdk/src/share/classes/sun/security/provider/MD5.java b/jdk/src/share/classes/sun/security/provider/MD5.java index 85830e55010..32e42e5ecd7 100644 --- a/jdk/src/share/classes/sun/security/provider/MD5.java +++ b/jdk/src/share/classes/sun/security/provider/MD5.java @@ -39,9 +39,9 @@ import static sun.security.provider.ByteArrayAccess.*; public final class MD5 extends DigestBase { // state of this object - private final int[] state; + private int[] state; // temporary buffer, used by implCompress() - private final int[] x; + private int[] x; // rotation constants private static final int S11 = 7; @@ -69,16 +69,12 @@ public final class MD5 extends DigestBase { implReset(); } - // Cloning constructor - private MD5(MD5 base) { - super(base); - this.state = base.state.clone(); - this.x = new int[16]; - } - // clone this object - public Object clone() { - return new MD5(this); + public Object clone() throws CloneNotSupportedException { + MD5 copy = (MD5) super.clone(); + copy.state = copy.state.clone(); + copy.x = new int[16]; + return copy; } /** diff --git a/jdk/src/share/classes/sun/security/provider/SHA.java b/jdk/src/share/classes/sun/security/provider/SHA.java index 723c64a2b5b..0f13f41b25c 100644 --- a/jdk/src/share/classes/sun/security/provider/SHA.java +++ b/jdk/src/share/classes/sun/security/provider/SHA.java @@ -47,10 +47,10 @@ public final class SHA extends DigestBase { // 64 bytes are included in each hash block so the low order // bits of count are used to know how to pack the bytes into ints // and to know when to compute the block and start the next one. - private final int[] W; + private int[] W; // state of this - private final int[] state; + private int[] state; /** * Creates a new SHA object. @@ -62,19 +62,14 @@ public final class SHA extends DigestBase { implReset(); } - /** - * Creates a SHA object.with state (for cloning) */ - private SHA(SHA base) { - super(base); - this.state = base.state.clone(); - this.W = new int[80]; - } - /* * Clones this object. */ - public Object clone() { - return new SHA(this); + public Object clone() throws CloneNotSupportedException { + SHA copy = (SHA) super.clone(); + copy.state = copy.state.clone(); + copy.W = new int[80]; + return copy; } /** diff --git a/jdk/src/share/classes/sun/security/provider/SHA2.java b/jdk/src/share/classes/sun/security/provider/SHA2.java index a04ada05a34..54f34545918 100644 --- a/jdk/src/share/classes/sun/security/provider/SHA2.java +++ b/jdk/src/share/classes/sun/security/provider/SHA2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2012, 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 @@ -40,7 +40,7 @@ import static sun.security.provider.ByteArrayAccess.*; * @author Valerie Peng * @author Andreas Sterbenz */ -public final class SHA2 extends DigestBase { +abstract class SHA2 extends DigestBase { private static final int ITERATION = 64; // Constants for each round @@ -64,46 +64,30 @@ public final class SHA2 extends DigestBase { }; // buffer used by implCompress() - private final int[] W; + private int[] W; // state of this object - private final int[] state; + private int[] state; + + // initial state value. different between SHA-224 and SHA-256 + private final int[] initialHashes; /** * Creates a new SHA object. */ - public SHA2() { - super("SHA-256", 32, 64); + SHA2(String name, int digestLength, int[] initialHashes) { + super(name, digestLength, 64); + this.initialHashes = initialHashes; state = new int[8]; W = new int[64]; implReset(); } - /** - * Creates a SHA2 object.with state (for cloning) - */ - private SHA2(SHA2 base) { - super(base); - this.state = base.state.clone(); - this.W = new int[64]; - } - - public Object clone() { - return new SHA2(this); - } - /** * Resets the buffers and hash value to start a new hash. */ void implReset() { - state[0] = 0x6a09e667; - state[1] = 0xbb67ae85; - state[2] = 0x3c6ef372; - state[3] = 0xa54ff53a; - state[4] = 0x510e527f; - state[5] = 0x9b05688c; - state[6] = 0x1f83d9ab; - state[7] = 0x5be0cd19; + System.arraycopy(initialHashes, 0, state, 0, state.length); } void implDigest(byte[] out, int ofs) { @@ -242,4 +226,38 @@ public final class SHA2 extends DigestBase { state[7] += h; } + public Object clone() throws CloneNotSupportedException { + SHA2 copy = (SHA2) super.clone(); + copy.state = copy.state.clone(); + copy.W = new int[64]; + return copy; + } + + /** + * SHA-224 implementation class. + */ + public static final class SHA224 extends SHA2 { + private static final int[] INITIAL_HASHES = { + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 + }; + + public SHA224() { + super("SHA-224", 28, INITIAL_HASHES); + } + } + + /** + * SHA-256 implementation class. + */ + public static final class SHA256 extends SHA2 { + private static final int[] INITIAL_HASHES = { + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 + }; + + public SHA256() { + super("SHA-256", 32, INITIAL_HASHES); + } + } } diff --git a/jdk/src/share/classes/sun/security/provider/SHA5.java b/jdk/src/share/classes/sun/security/provider/SHA5.java index 413770cc542..851c0706b1c 100644 --- a/jdk/src/share/classes/sun/security/provider/SHA5.java +++ b/jdk/src/share/classes/sun/security/provider/SHA5.java @@ -82,10 +82,10 @@ abstract class SHA5 extends DigestBase { }; // buffer used by implCompress() - private final long[] W; + private long[] W; // state of this object - private final long[] state; + private long[] state; // initial state value. different between SHA-384 and SHA-512 private final long[] initialHashes; @@ -101,16 +101,6 @@ abstract class SHA5 extends DigestBase { implReset(); } - /** - * Creates a SHA object with state (for cloning) - */ - SHA5(SHA5 base) { - super(base); - this.initialHashes = base.initialHashes; - this.state = base.state.clone(); - this.W = new long[80]; - } - final void implReset() { System.arraycopy(initialHashes, 0, state, 0, state.length); } @@ -255,6 +245,13 @@ abstract class SHA5 extends DigestBase { state[7] += h; } + public Object clone() throws CloneNotSupportedException { + SHA5 copy = (SHA5) super.clone(); + copy.state = copy.state.clone(); + copy.W = new long[80]; + return copy; + } + /** * SHA-512 implementation class. */ @@ -270,14 +267,6 @@ abstract class SHA5 extends DigestBase { public SHA512() { super("SHA-512", 64, INITIAL_HASHES); } - - private SHA512(SHA512 base) { - super(base); - } - - public Object clone() { - return new SHA512(this); - } } /** @@ -295,14 +284,5 @@ abstract class SHA5 extends DigestBase { public SHA384() { super("SHA-384", 48, INITIAL_HASHES); } - - private SHA384(SHA384 base) { - super(base); - } - - public Object clone() { - return new SHA384(this); - } } - } diff --git a/jdk/src/share/classes/sun/security/provider/SecureRandom.java b/jdk/src/share/classes/sun/security/provider/SecureRandom.java index aee8846ed14..e79e9d7f49a 100644 --- a/jdk/src/share/classes/sun/security/provider/SecureRandom.java +++ b/jdk/src/share/classes/sun/security/provider/SecureRandom.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2012, 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 @@ -102,7 +102,7 @@ implements java.io.Serializable { try { digest = MessageDigest.getInstance ("SHA"); } catch (NoSuchAlgorithmException e) { - throw new InternalError("internal error: SHA-1 not available."); + throw new InternalError("internal error: SHA-1 not available.", e); } if (seed != null) { diff --git a/jdk/src/share/classes/sun/security/provider/SunEntries.java b/jdk/src/share/classes/sun/security/provider/SunEntries.java index 6421afd0fb3..3f0ef1084ce 100644 --- a/jdk/src/share/classes/sun/security/provider/SunEntries.java +++ b/jdk/src/share/classes/sun/security/provider/SunEntries.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, 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 @@ -43,6 +43,10 @@ import java.security.*; * identifier strings "OID.1.3.14.3.2.13", "OID.1.3.14.3.2.27" and * "OID.1.2.840.10040.4.3". * + * - SHA-2 is a set of message digest schemes described in FIPS 180-2. + * SHA-2 family of hash functions includes SHA-224, SHA-256, SHA-384, + * and SHA-512. + * * - DSA is the key generation scheme as described in FIPS 186. * Aliases for DSA include the OID strings "OID.1.3.14.3.2.12" * and "OID.1.2.840.10040.4.1". @@ -140,9 +144,19 @@ final class SunEntries { map.put("Alg.Alias.MessageDigest.SHA-1", "SHA"); map.put("Alg.Alias.MessageDigest.SHA1", "SHA"); - map.put("MessageDigest.SHA-256", "sun.security.provider.SHA2"); + map.put("MessageDigest.SHA-224", "sun.security.provider.SHA2$SHA224"); + map.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.4", "SHA-224"); + map.put("Alg.Alias.MessageDigest.OID.2.16.840.1.101.3.4.2.4", "SHA-224"); + + map.put("MessageDigest.SHA-256", "sun.security.provider.SHA2$SHA256"); + map.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.1", "SHA-256"); + map.put("Alg.Alias.MessageDigest.OID.2.16.840.1.101.3.4.2.1", "SHA-256"); map.put("MessageDigest.SHA-384", "sun.security.provider.SHA5$SHA384"); + map.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.2", "SHA-384"); + map.put("Alg.Alias.MessageDigest.OID.2.16.840.1.101.3.4.2.2", "SHA-384"); map.put("MessageDigest.SHA-512", "sun.security.provider.SHA5$SHA512"); + map.put("Alg.Alias.MessageDigest.2.16.840.1.101.3.4.2.3", "SHA-512"); + map.put("Alg.Alias.MessageDigest.OID.2.16.840.1.101.3.4.2.3", "SHA-512"); /* * Algorithm Parameter Generator engines diff --git a/jdk/src/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java b/jdk/src/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java index c88c37b3bf7..b3daf348566 100644 --- a/jdk/src/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java +++ b/jdk/src/share/classes/sun/security/provider/certpath/SunCertPathBuilder.java @@ -318,7 +318,9 @@ public final class SunCertPathBuilder extends CertPathBuilderSpi { } // break out of loop if search is successful - break; + if (pathCompleted) { + break; + } } if (debug != null) { diff --git a/jdk/src/share/classes/sun/security/rsa/RSASignature.java b/jdk/src/share/classes/sun/security/rsa/RSASignature.java index a98ed881d1c..435e283ad23 100644 --- a/jdk/src/share/classes/sun/security/rsa/RSASignature.java +++ b/jdk/src/share/classes/sun/security/rsa/RSASignature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -39,8 +39,8 @@ import sun.security.x509.AlgorithmId; * PKCS#1 RSA signatures with the various message digest algorithms. * This file contains an abstract base class with all the logic plus * a nested static class for each of the message digest algorithms - * (see end of the file). We support MD2, MD5, SHA-1, SHA-256, SHA-384, - * and SHA-512. + * (see end of the file). We support MD2, MD5, SHA-1, SHA-224, SHA-256, + * SHA-384, and SHA-512. * * @since 1.5 * @author Andreas Sterbenz @@ -276,6 +276,13 @@ public abstract class RSASignature extends SignatureSpi { } } + // Nested class for SHA224withRSA signatures + public static final class SHA224withRSA extends RSASignature { + public SHA224withRSA() { + super("SHA-224", AlgorithmId.SHA224_oid, 11); + } + } + // Nested class for SHA256withRSA signatures public static final class SHA256withRSA extends RSASignature { public SHA256withRSA() { diff --git a/jdk/src/share/classes/sun/security/rsa/SunRsaSignEntries.java b/jdk/src/share/classes/sun/security/rsa/SunRsaSignEntries.java index fc8f5576339..836fc5f201c 100644 --- a/jdk/src/share/classes/sun/security/rsa/SunRsaSignEntries.java +++ b/jdk/src/share/classes/sun/security/rsa/SunRsaSignEntries.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -52,6 +52,8 @@ public final class SunRsaSignEntries { "sun.security.rsa.RSASignature$MD5withRSA"); map.put("Signature.SHA1withRSA", "sun.security.rsa.RSASignature$SHA1withRSA"); + map.put("Signature.SHA224withRSA", + "sun.security.rsa.RSASignature$SHA224withRSA"); map.put("Signature.SHA256withRSA", "sun.security.rsa.RSASignature$SHA256withRSA"); map.put("Signature.SHA384withRSA", @@ -66,6 +68,7 @@ public final class SunRsaSignEntries { map.put("Signature.MD2withRSA SupportedKeyClasses", rsaKeyClasses); map.put("Signature.MD5withRSA SupportedKeyClasses", rsaKeyClasses); map.put("Signature.SHA1withRSA SupportedKeyClasses", rsaKeyClasses); + map.put("Signature.SHA224withRSA SupportedKeyClasses", rsaKeyClasses); map.put("Signature.SHA256withRSA SupportedKeyClasses", rsaKeyClasses); map.put("Signature.SHA384withRSA SupportedKeyClasses", rsaKeyClasses); map.put("Signature.SHA512withRSA SupportedKeyClasses", rsaKeyClasses); @@ -88,6 +91,9 @@ public final class SunRsaSignEntries { map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.5", "SHA1withRSA"); map.put("Alg.Alias.Signature.1.3.14.3.2.29", "SHA1withRSA"); + map.put("Alg.Alias.Signature.1.2.840.113549.1.1.14", "SHA224withRSA"); + map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.14", "SHA224withRSA"); + map.put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256withRSA"); map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.11", "SHA256withRSA"); diff --git a/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java b/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java index 9814f9f5010..1a5a8cf78ef 100644 --- a/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java +++ b/jdk/src/share/classes/sun/security/ssl/SSLContextImpl.java @@ -267,36 +267,42 @@ public abstract class SSLContextImpl extends SSLContextSpi { // Get suported CipherSuiteList. CipherSuiteList getSuportedCipherSuiteList() { - // Clear cache of available ciphersuites. - clearAvailableCache(); + // The maintenance of cipher suites needs to be synchronized. + synchronized (this) { + // Clear cache of available ciphersuites. + clearAvailableCache(); - if (supportedCipherSuiteList == null) { - supportedCipherSuiteList = - getApplicableCipherSuiteList(getSuportedProtocolList(), false); + if (supportedCipherSuiteList == null) { + supportedCipherSuiteList = getApplicableCipherSuiteList( + getSuportedProtocolList(), false); + } + + return supportedCipherSuiteList; } - - return supportedCipherSuiteList; } // Get default CipherSuiteList. CipherSuiteList getDefaultCipherSuiteList(boolean roleIsServer) { - // Clear cache of available ciphersuites. - clearAvailableCache(); + // The maintenance of cipher suites needs to be synchronized. + synchronized (this) { + // Clear cache of available ciphersuites. + clearAvailableCache(); - if (roleIsServer) { - if (defaultServerCipherSuiteList == null) { - defaultServerCipherSuiteList = getApplicableCipherSuiteList( + if (roleIsServer) { + if (defaultServerCipherSuiteList == null) { + defaultServerCipherSuiteList = getApplicableCipherSuiteList( getDefaultProtocolList(true), true); - } + } - return defaultServerCipherSuiteList; - } else { - if (defaultClientCipherSuiteList == null) { - defaultClientCipherSuiteList = getApplicableCipherSuiteList( + return defaultServerCipherSuiteList; + } else { + if (defaultClientCipherSuiteList == null) { + defaultClientCipherSuiteList = getApplicableCipherSuiteList( getDefaultProtocolList(false), true); - } + } - return defaultClientCipherSuiteList; + return defaultClientCipherSuiteList; + } } } @@ -364,8 +370,11 @@ public abstract class SSLContextImpl extends SSLContextSpi { * Clear cache of available ciphersuites. If we support all ciphers * internally, there is no need to clear the cache and calling this * method has no effect. + * + * Note that every call to clearAvailableCache() and the maintenance of + * cipher suites need to be synchronized with this instance. */ - synchronized void clearAvailableCache() { + private void clearAvailableCache() { if (CipherSuite.DYNAMIC_AVAILABILITY) { supportedCipherSuiteList = null; defaultServerCipherSuiteList = null; diff --git a/jdk/src/share/classes/sun/security/validator/SimpleValidator.java b/jdk/src/share/classes/sun/security/validator/SimpleValidator.java index 94698427b92..a0f4f8b9e7e 100644 --- a/jdk/src/share/classes/sun/security/validator/SimpleValidator.java +++ b/jdk/src/share/classes/sun/security/validator/SimpleValidator.java @@ -311,7 +311,7 @@ public final class SimpleValidator extends Validator { // if the certificate is self-issued, ignore the pathLenConstraint // checking. if (!X509CertImpl.isSelfIssued(cert)) { - if (maxPathLen <= 1) { // reserved one for end-entity certificate + if (maxPathLen <= 0) { throw new ValidatorException("Violated path length constraints", ValidatorException.T_CA_EXTENSIONS, cert); } diff --git a/jdk/src/share/classes/sun/security/x509/AlgorithmId.java b/jdk/src/share/classes/sun/security/x509/AlgorithmId.java index 4602248c1f3..0504707fa8a 100644 --- a/jdk/src/share/classes/sun/security/x509/AlgorithmId.java +++ b/jdk/src/share/classes/sun/security/x509/AlgorithmId.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, 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 @@ -175,9 +175,9 @@ public class AlgorithmId implements Serializable, DerEncoder { // it's NULL. They are --- // rfc3370 2.1: Implementations SHOULD generate SHA-1 // AlgorithmIdentifiers with absent parameters. - // rfc3447 C1: When id-sha1, id-sha256, id-sha384 and id-sha512 - // are used in an AlgorithmIdentifier the parameters (which are - // optional) SHOULD be omitted. + // rfc3447 C1: When id-sha1, id-sha224, id-sha256, id-sha384 and + // id-sha512 are used in an AlgorithmIdentifier the parameters + // (which are optional) SHOULD be omitted. // rfc3279 2.3.2: The id-dsa algorithm syntax includes optional // domain parameters... When omitted, the parameters component // MUST be omitted entirely @@ -185,6 +185,7 @@ public class AlgorithmId implements Serializable, DerEncoder { // is used, the AlgorithmIdentifier parameters field MUST be absent. /*if ( algid.equals((Object)SHA_oid) || + algid.equals((Object)SHA224_oid) || algid.equals((Object)SHA256_oid) || algid.equals((Object)SHA384_oid) || algid.equals((Object)SHA512_oid) || @@ -488,7 +489,10 @@ public class AlgorithmId implements Serializable, DerEncoder { name.equalsIgnoreCase("SHA512")) { return AlgorithmId.SHA512_oid; } - + if (name.equalsIgnoreCase("SHA-224") || + name.equalsIgnoreCase("SHA224")) { + return AlgorithmId.SHA224_oid; + } // Various public key algorithms if (name.equalsIgnoreCase("RSA")) { @@ -625,6 +629,9 @@ public class AlgorithmId implements Serializable, DerEncoder { public static final ObjectIdentifier SHA_oid = ObjectIdentifier.newInternal(new int[] {1, 3, 14, 3, 2, 26}); + public static final ObjectIdentifier SHA224_oid = + ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 4}); + public static final ObjectIdentifier SHA256_oid = ObjectIdentifier.newInternal(new int[] {2, 16, 840, 1, 101, 3, 4, 2, 1}); @@ -664,6 +671,8 @@ public class AlgorithmId implements Serializable, DerEncoder { { 1, 2, 840, 113549, 1, 1, 5 }; private static final int sha1WithRSAEncryption_OIW_data[] = { 1, 3, 14, 3, 2, 29 }; + private static final int sha224WithRSAEncryption_data[] = + { 1, 2, 840, 113549, 1, 1, 14 }; private static final int sha256WithRSAEncryption_data[] = { 1, 2, 840, 113549, 1, 1, 11 }; private static final int sha384WithRSAEncryption_data[] = @@ -681,6 +690,7 @@ public class AlgorithmId implements Serializable, DerEncoder { public static final ObjectIdentifier md5WithRSAEncryption_oid; public static final ObjectIdentifier sha1WithRSAEncryption_oid; public static final ObjectIdentifier sha1WithRSAEncryption_OIW_oid; + public static final ObjectIdentifier sha224WithRSAEncryption_oid; public static final ObjectIdentifier sha256WithRSAEncryption_oid; public static final ObjectIdentifier sha384WithRSAEncryption_oid; public static final ObjectIdentifier sha512WithRSAEncryption_oid; @@ -809,6 +819,14 @@ public class AlgorithmId implements Serializable, DerEncoder { sha1WithRSAEncryption_OIW_oid = ObjectIdentifier.newInternal(sha1WithRSAEncryption_OIW_data); + /** + * Identifies a signing algorithm where a SHA224 digest is + * encrypted using an RSA private key; defined by PKCS #1. + * OID = 1.2.840.113549.1.1.14 + */ + sha224WithRSAEncryption_oid = + ObjectIdentifier.newInternal(sha224WithRSAEncryption_data); + /** * Identifies a signing algorithm where a SHA256 digest is * encrypted using an RSA private key; defined by PKCS #1. @@ -859,6 +877,7 @@ public class AlgorithmId implements Serializable, DerEncoder { nameTable.put(MD5_oid, "MD5"); nameTable.put(MD2_oid, "MD2"); nameTable.put(SHA_oid, "SHA"); + nameTable.put(SHA224_oid, "SHA224"); nameTable.put(SHA256_oid, "SHA256"); nameTable.put(SHA384_oid, "SHA384"); nameTable.put(SHA512_oid, "SHA512"); @@ -881,6 +900,7 @@ public class AlgorithmId implements Serializable, DerEncoder { nameTable.put(shaWithDSA_OIW_oid, "SHA1withDSA"); nameTable.put(sha1WithRSAEncryption_oid, "SHA1withRSA"); nameTable.put(sha1WithRSAEncryption_OIW_oid, "SHA1withRSA"); + nameTable.put(sha224WithRSAEncryption_oid, "SHA224withRSA"); nameTable.put(sha256WithRSAEncryption_oid, "SHA256withRSA"); nameTable.put(sha384WithRSAEncryption_oid, "SHA384withRSA"); nameTable.put(sha512WithRSAEncryption_oid, "SHA512withRSA"); diff --git a/jdk/src/share/classes/sun/tools/jcmd/JCmd.java b/jdk/src/share/classes/sun/tools/jcmd/JCmd.java index 3ec79968fed..4690a5bc4f6 100644 --- a/jdk/src/share/classes/sun/tools/jcmd/JCmd.java +++ b/jdk/src/share/classes/sun/tools/jcmd/JCmd.java @@ -142,8 +142,11 @@ public class JCmd { // Cast to HotSpotVirtualMachine as this is an // implementation specific method. HotSpotVirtualMachine hvm = (HotSpotVirtualMachine) vm; - String lines[] = command .split("\\n"); + String lines[] = command.split("\\n"); for (String line : lines) { + if (line.trim().equals("stop")) { + break; + } try (InputStream in = hvm.executeJCmd(line);) { // read to EOF and just print output byte b[] = new byte[256]; diff --git a/jdk/src/share/demo/management/MemoryMonitor/README.txt b/jdk/src/share/demo/management/MemoryMonitor/README.txt index 9b264c7f18c..2009e1339e2 100644 --- a/jdk/src/share/demo/management/MemoryMonitor/README.txt +++ b/jdk/src/share/demo/management/MemoryMonitor/README.txt @@ -38,7 +38,7 @@ and plots the memory usage history graph. To run the MemoryMonitor demo - java -jar /demo/management/MemoryMonitor.jar + java -jar /demo/management/MemoryMonitor/MemoryMonitor.jar These instructions assume that this installation's version of the java command is in your path. If it isn't, then you should either diff --git a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java index d68388a97f3..44d3e809993 100644 --- a/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java +++ b/jdk/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java @@ -651,7 +651,11 @@ public class ZipFileSystem extends FileSystem { } public int read(ByteBuffer dst) throws IOException { - return rbc.read(dst); + int n = rbc.read(dst); + if (n > 0) { + read += n; + } + return n; } public SeekableByteChannel truncate(long size) diff --git a/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp b/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp index e77e99f33c5..bedecda5391 100644 --- a/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp +++ b/jdk/src/share/native/com/sun/java/util/jar/pack/jni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -82,7 +82,11 @@ static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) { static unpacker* get_unpacker() { //fprintf(stderr, "get_unpacker()\n"); JavaVM* vm = null; - JNI_GetCreatedJavaVMs(&vm, 1, null); + jsize nVM = 0; + jint retval = JNI_GetCreatedJavaVMs(&vm, 1, &nVM); + // other VM implements may differ, thus for correctness, we need these checks + if (retval != JNI_OK || nVM != 1) + return null; void* envRaw = null; vm->GetEnv(&envRaw, JNI_VERSION_1_1); JNIEnv* env = (JNIEnv*) envRaw; diff --git a/jdk/src/share/native/java/net/net_util.h b/jdk/src/share/native/java/net/net_util.h index d87ffdad280..923520bb2e1 100644 --- a/jdk/src/share/native/java/net/net_util.h +++ b/jdk/src/share/native/java/net/net_util.h @@ -139,6 +139,9 @@ NET_IPv4MappedToIPv4(jbyte* caddr); int NET_IsEqual(jbyte* caddr1, jbyte* caddr2); +int +NET_IsZeroAddr(jbyte* caddr); + /* Socket operations * * These work just like the JVM_* procedures, except that they may do some diff --git a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c index 28e8448bdd1..a6f7ddc1a00 100644 --- a/jdk/src/solaris/native/java/net/Inet4AddressImpl.c +++ b/jdk/src/solaris/native/java/net/Inet4AddressImpl.c @@ -671,12 +671,19 @@ ping4(JNIEnv *env, jint fd, struct sockaddr_in* him, jint timeout, * We did receive something, but is it what we were expecting? * I.E.: A ICMP_ECHOREPLY packet with the proper PID. */ - if (icmplen >= 8 && icmp->icmp_type == ICMP_ECHOREPLY && - (ntohs(icmp->icmp_id) == pid) && - (him->sin_addr.s_addr == sa_recv.sin_addr.s_addr)) { - close(fd); - return JNI_TRUE; - } + if (icmplen >= 8 && icmp->icmp_type == ICMP_ECHOREPLY + && (ntohs(icmp->icmp_id) == pid)) { + if ((him->sin_addr.s_addr == sa_recv.sin_addr.s_addr)) { + close(fd); + return JNI_TRUE; + } + + if (him->sin_addr.s_addr == 0) { + close(fd); + return JNI_TRUE; + } + } + } } while (tmout2 > 0); timeout -= 1000; diff --git a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c index e612131b95c..63addd9fb70 100644 --- a/jdk/src/solaris/native/java/net/Inet6AddressImpl.c +++ b/jdk/src/solaris/native/java/net/Inet6AddressImpl.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2012, 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 @@ -73,7 +73,7 @@ Java_java_net_Inet6AddressImpl_getLocalHostName(JNIEnv *env, jobject this) { } else { // ensure null-terminated hostname[NI_MAXHOST] = '\0'; -#if defined(__linux__) && defined(_ALLBSD_SOURCE) +#if defined(__linux__) || defined(_ALLBSD_SOURCE) /* On Linux/FreeBSD gethostname() says "host.domain.sun.com". On * Solaris gethostname() says "host", so extra work is needed. */ @@ -532,10 +532,15 @@ ping6(JNIEnv *env, jint fd, struct sockaddr_in6* him, jint timeout, * from the host that we are trying to determine is reachable. */ if (n >= 8 && icmp6->icmp6_type == ICMP6_ECHO_REPLY && - (ntohs(icmp6->icmp6_id) == pid) && - NET_IsEqual(caddr, recv_caddr)) { - close(fd); - return JNI_TRUE; + (ntohs(icmp6->icmp6_id) == pid)) { + if (NET_IsEqual(caddr, recv_caddr)) { + close(fd); + return JNI_TRUE; + } + if (NET_IsZeroAddr(caddr)) { + close(fd); + return JNI_TRUE; + } } } } while (tmout2 > 0); diff --git a/jdk/src/solaris/native/java/net/net_util_md.c b/jdk/src/solaris/native/java/net/net_util_md.c index ccbe4b15a72..35330916214 100644 --- a/jdk/src/solaris/native/java/net/net_util_md.c +++ b/jdk/src/solaris/native/java/net/net_util_md.c @@ -961,6 +961,16 @@ NET_IsEqual(jbyte* caddr1, jbyte* caddr2) { return 1; } +int NET_IsZeroAddr(jbyte* caddr) { + int i; + for (i = 0; i < 16; i++) { + if (caddr[i] != 0) { + return 0; + } + } + return 1; +} + /* * Map the Java level socket option to the platform specific * level and option name. diff --git a/jdk/src/solaris/native/java/util/TimeZone_md.c b/jdk/src/solaris/native/java/util/TimeZone_md.c index 3af5d72657f..ce2fa5aca8c 100644 --- a/jdk/src/solaris/native/java/util/TimeZone_md.c +++ b/jdk/src/solaris/native/java/util/TimeZone_md.c @@ -651,7 +651,7 @@ findJavaTZ_md(const char *java_home_dir, const char *country) } #ifdef __solaris__ - if (strcmp(tz, "localtime") == 0) { + if (tz != NULL && strcmp(tz, "localtime") == 0) { tz = getSolarisDefaultZoneID(); freetz = tz; } diff --git a/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c b/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c index 3d4f05100d1..7f7a3e82690 100644 --- a/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c +++ b/jdk/src/solaris/native/sun/nio/ch/EPollArrayWrapper.c @@ -30,40 +30,10 @@ #include "sun_nio_ch_EPollArrayWrapper.h" -#include #include #include #include - -#ifdef __cplusplus -extern "C" { -#endif - -/* epoll_wait(2) man page */ - -typedef union epoll_data { - void *ptr; - int fd; - __uint32_t u32; - __uint64_t u64; -} epoll_data_t; - - -/* x86-64 has same alignment as 32-bit */ -#ifdef __x86_64__ -#define EPOLL_PACKED __attribute__((packed)) -#else -#define EPOLL_PACKED -#endif - -struct epoll_event { - __uint32_t events; /* Epoll events */ - epoll_data_t data; /* User data variable */ -} EPOLL_PACKED; - -#ifdef __cplusplus -} -#endif +#include #define RESTARTABLE(_cmd, _result) do { \ do { \ @@ -71,18 +41,6 @@ struct epoll_event { } while((_result == -1) && (errno == EINTR)); \ } while(0) -/* - * epoll event notification is new in 2.6 kernel. As the offical build - * platform for the JDK is on a 2.4-based distribution then we must - * obtain the addresses of the epoll functions dynamically. - */ -typedef int (*epoll_create_t)(int size); -typedef int (*epoll_ctl_t) (int epfd, int op, int fd, struct epoll_event *event); -typedef int (*epoll_wait_t) (int epfd, struct epoll_event *events, int maxevents, int timeout); - -static epoll_create_t epoll_create_func; -static epoll_ctl_t epoll_ctl_func; -static epoll_wait_t epoll_wait_func; static int iepoll(int epfd, struct epoll_event *events, int numfds, jlong timeout) @@ -96,7 +54,7 @@ iepoll(int epfd, struct epoll_event *events, int numfds, jlong timeout) start = t.tv_sec * 1000 + t.tv_usec / 1000; for (;;) { - int res = (*epoll_wait_func)(epfd, events, numfds, timeout); + int res = epoll_wait(epfd, events, numfds, timeout); if (res < 0 && errno == EINTR) { if (remaining >= 0) { gettimeofday(&t, NULL); @@ -117,14 +75,6 @@ iepoll(int epfd, struct epoll_event *events, int numfds, jlong timeout) JNIEXPORT void JNICALL Java_sun_nio_ch_EPollArrayWrapper_init(JNIEnv *env, jclass this) { - epoll_create_func = (epoll_create_t) dlsym(RTLD_DEFAULT, "epoll_create"); - epoll_ctl_func = (epoll_ctl_t) dlsym(RTLD_DEFAULT, "epoll_ctl"); - epoll_wait_func = (epoll_wait_t) dlsym(RTLD_DEFAULT, "epoll_wait"); - - if ((epoll_create_func == NULL) || (epoll_ctl_func == NULL) || - (epoll_wait_func == NULL)) { - JNU_ThrowInternalError(env, "unable to get address of epoll functions, pre-2.6 kernel?"); - } } JNIEXPORT jint JNICALL @@ -134,7 +84,7 @@ Java_sun_nio_ch_EPollArrayWrapper_epollCreate(JNIEnv *env, jobject this) * epoll_create expects a size as a hint to the kernel about how to * dimension internal structures. We can't predict the size in advance. */ - int epfd = (*epoll_create_func)(256); + int epfd = epoll_create(256); if (epfd < 0) { JNU_ThrowIOExceptionWithLastError(env, "epoll_create failed"); } @@ -173,7 +123,7 @@ Java_sun_nio_ch_EPollArrayWrapper_epollCtl(JNIEnv *env, jobject this, jint epfd, event.events = events; event.data.fd = fd; - RESTARTABLE((*epoll_ctl_func)(epfd, (int)opcode, (int)fd, &event), res); + RESTARTABLE(epoll_ctl(epfd, (int)opcode, (int)fd, &event), res); /* * A channel may be registered with several Selectors. When each Selector @@ -199,7 +149,7 @@ Java_sun_nio_ch_EPollArrayWrapper_epollWait(JNIEnv *env, jobject this, int res; if (timeout <= 0) { /* Indefinite or no wait */ - RESTARTABLE((*epoll_wait_func)(epfd, events, numfds, timeout), res); + RESTARTABLE(epoll_wait(epfd, events, numfds, timeout), res); } else { /* Bounded wait; bounded restarts */ res = iepoll(epfd, events, numfds, timeout); } diff --git a/jdk/src/windows/classes/sun/security/mscapi/RSASignature.java b/jdk/src/windows/classes/sun/security/mscapi/RSASignature.java index 488c2365b00..d8d8849e13c 100644 --- a/jdk/src/windows/classes/sun/security/mscapi/RSASignature.java +++ b/jdk/src/windows/classes/sun/security/mscapi/RSASignature.java @@ -57,8 +57,8 @@ import sun.security.rsa.RSAKeyFactory; * * NOTE: NONEwithRSA must be supplied with a pre-computed message digest. * Only the following digest algorithms are supported: MD5, SHA-1, - * SHA-256, SHA-384, SHA-512 and a special-purpose digest algorithm - * which is a concatenation of SHA-1 and MD5 digests. + * SHA-256, SHA-384, SHA-512 and a special-purpose digest + * algorithm which is a concatenation of SHA-1 and MD5 digests. * * @since 1.6 * @author Stanley Man-Kit Ho diff --git a/jdk/src/windows/classes/sun/security/mscapi/SunMSCAPI.java b/jdk/src/windows/classes/sun/security/mscapi/SunMSCAPI.java index f7df7ce4a8f..1af669415ee 100644 --- a/jdk/src/windows/classes/sun/security/mscapi/SunMSCAPI.java +++ b/jdk/src/windows/classes/sun/security/mscapi/SunMSCAPI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, 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 @@ -81,18 +81,26 @@ public final class SunMSCAPI extends Provider { */ // NONEwithRSA must be supplied with a pre-computed message digest. // Only the following digest algorithms are supported: MD5, SHA-1, - // SHA-256, SHA-384, SHA-512 and a special-purpose digest algorithm - // which is a concatenation of SHA-1 and MD5 digests. + // SHA-256, SHA-384, SHA-512 and a special-purpose digest + // algorithm which is a concatenation of SHA-1 and MD5 digests. map.put("Signature.NONEwithRSA", "sun.security.mscapi.RSASignature$Raw"); map.put("Signature.SHA1withRSA", "sun.security.mscapi.RSASignature$SHA1"); map.put("Signature.SHA256withRSA", "sun.security.mscapi.RSASignature$SHA256"); + map.put("Alg.Alias.Signature.1.2.840.113549.1.1.11", "SHA256withRSA"); + map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.11", "SHA256withRSA"); map.put("Signature.SHA384withRSA", "sun.security.mscapi.RSASignature$SHA384"); + map.put("Alg.Alias.Signature.1.2.840.113549.1.1.12", "SHA384withRSA"); + map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.12", "SHA384withRSA"); + map.put("Signature.SHA512withRSA", "sun.security.mscapi.RSASignature$SHA512"); + map.put("Alg.Alias.Signature.1.2.840.113549.1.1.13", "SHA512withRSA"); + map.put("Alg.Alias.Signature.OID.1.2.840.113549.1.1.13", "SHA512withRSA"); + map.put("Signature.MD5withRSA", "sun.security.mscapi.RSASignature$MD5"); map.put("Signature.MD2withRSA", diff --git a/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c b/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c index a956730d8ca..2ee38039823 100644 --- a/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c +++ b/jdk/src/windows/native/sun/tools/attach/WindowsVirtualMachine.c @@ -466,7 +466,17 @@ JNIEXPORT void JNICALL Java_sun_tools_attach_WindowsVirtualMachine_enqueue } CloseHandle(hThread); } else { - JNU_ThrowIOExceptionWithLastError(env, "CreateRemoteThread failed"); + if (GetLastError() == ERROR_NOT_ENOUGH_MEMORY) { + // + // This error will occur when attaching to a process belonging to + // another terminal session. See "Remarks": + // http://msdn.microsoft.com/en-us/library/ms682437%28VS.85%29.aspx + // + JNU_ThrowIOException(env, + "Insufficient memory or insufficient privileges to attach"); + } else { + JNU_ThrowIOExceptionWithLastError(env, "CreateRemoteThread failed"); + } } VirtualFreeEx(hProcess, pCode, 0, MEM_RELEASE); diff --git a/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEP.java b/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEP.java index 2d7d8863b08..55b501ebf36 100644 --- a/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEP.java +++ b/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEP.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -58,6 +58,7 @@ public class TestOAEP { Cipher.getInstance("RSA/ECB/OAEPwithMD5andMGF1Padding"); Cipher.getInstance("RSA/ECB/OAEPwithSHA1andMGF1Padding"); Cipher.getInstance("RSA/ECB/OAEPwithSHA-1andMGF1Padding"); + Cipher.getInstance("RSA/ECB/OAEPwithSHA-224andMGF1Padding"); Cipher.getInstance("RSA/ECB/OAEPwithSHA-256andMGF1Padding"); Cipher.getInstance("RSA/ECB/OAEPwithSHA-384andMGF1Padding"); Cipher.getInstance("RSA/ECB/OAEPwithSHA-512andMGF1Padding"); @@ -88,6 +89,18 @@ public class TestOAEP { // tests alias works testEncryptDecrypt("SHA-1", 16); + // basic test using SHA-224 + testEncryptDecrypt("SHA-224", 0); + testEncryptDecrypt("SHA-224", 16); + testEncryptDecrypt("SHA-224", 38); + try { + testEncryptDecrypt("SHA-224", 39); + throw new Exception("Unexpectedly completed call"); + } catch (IllegalBlockSizeException e) { + // ok + System.out.println(e); + } + // basic test using SHA-256 testEncryptDecrypt("SHA-256", 0); testEncryptDecrypt("SHA-256", 16); @@ -195,6 +208,7 @@ public class TestOAEP { System.out.println("Done (" + (stop - start) + " ms)."); } + // NOTE: OAEP can process up to (modLen - 2*digestLen - 2) bytes of data private static void testEncryptDecrypt(String hashAlg, int dataLength) throws Exception { System.out.println("Testing OAEP with hash " + hashAlg + ", " + dataLength + " bytes"); Cipher c = Cipher.getInstance("RSA/ECB/OAEPwith" + hashAlg + "andMGF1Padding", cp); diff --git a/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPParameterSpec.java b/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPParameterSpec.java index 366467b2bf6..1a152859f35 100644 --- a/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPParameterSpec.java +++ b/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPParameterSpec.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -121,6 +121,7 @@ public class TestOAEPParameterSpec { public static void main(String[] argv) throws Exception { boolean status = true; byte[] p = { (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 }; + status &= runTest("SHA-224", MGF1ParameterSpec.SHA224, p); status &= runTest("SHA-256", MGF1ParameterSpec.SHA256, p); status &= runTest("SHA-384", MGF1ParameterSpec.SHA384, p); status &= runTest("SHA-512", MGF1ParameterSpec.SHA512, p); diff --git a/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPWithParams.java b/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPWithParams.java index 97ee3a82ead..13bdfe1a31b 100644 --- a/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPWithParams.java +++ b/jdk/test/com/sun/crypto/provider/Cipher/RSA/TestOAEPWithParams.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -47,10 +47,10 @@ public class TestOAEPWithParams { private static Random random = new Random(); private static String MD[] = { - "MD5", "SHA1", "SHA-256" + "MD5", "SHA1", "SHA-224", "SHA-256" }; private static int DATA_LENGTH[] = { - 62, 54, 30 + 62, 54, 34, 30 }; public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); diff --git a/jdk/test/com/sun/crypto/provider/KeyGenerator/Test4628062.java b/jdk/test/com/sun/crypto/provider/KeyGenerator/Test4628062.java index d037c2290ef..3fc55b7f8c3 100644 --- a/jdk/test/com/sun/crypto/provider/KeyGenerator/Test4628062.java +++ b/jdk/test/com/sun/crypto/provider/KeyGenerator/Test4628062.java @@ -23,7 +23,7 @@ /* * @test - * @bug 4628062 + * @bug 4628062 4963723 * @summary Verify that AES KeyGenerator supports default initialization * when init is not called * @author Valerie Peng @@ -34,39 +34,45 @@ import java.util.*; public class Test4628062 { - private static final String ALGO = "AES"; - private static final int[] KEYSIZES = - { 16, 24, 32 }; // in bytes + private static final int[] AES_SIZES = { 16, 24, 32 }; // in bytes + private static final int[] HMACSHA224_SIZES = { 28 }; + private static final int[] HMACSHA256_SIZES = { 32 }; + private static final int[] HMACSHA384_SIZES = { 48 }; + private static final int[] HMACSHA512_SIZES = { 64 }; - public boolean execute() throws Exception { - KeyGenerator kg = KeyGenerator.getInstance(ALGO, "SunJCE"); + public boolean execute(String algo, int[] keySizes) throws Exception { + KeyGenerator kg = KeyGenerator.getInstance(algo, "SunJCE"); // TEST FIX 4628062 Key keyWithDefaultSize = kg.generateKey(); byte[] encoding = keyWithDefaultSize.getEncoded(); - if (encoding.length == 0) { + int defKeyLen = encoding.length ; + if (defKeyLen == 0) { throw new Exception("default key length is 0!"); + } else if (defKeyLen != keySizes[0]) { + throw new Exception("default key length mismatch!"); } // BONUS TESTS - // 1. call init(int keysize) with various valid key sizes - // and see if the generated key is the right size. - for (int i=0; i 1) { + // 1. call init(int keysize) with various valid key sizes + // and see if the generated key is the right size. + for (int i=0; i nics = Collections.list(NetworkInterface + .getNetworkInterfaces()); + for (NetworkInterface nic : nics) { + List addrs = Collections.list(nic.getInetAddresses()); + for (InetAddress addr : addrs) { + if (addr instanceof Inet6Address) + return true; + } + } + + return false; + } + + public static void main(String args[]) throws Exception { + if (System.getProperty("os.name").startsWith("Windows")) { + return; + } + + boolean preferIPv4Stack = "true".equals(System + .getProperty("java.net.preferIPv4Stack")); + List addrs = new ArrayList(); + InetAddress inetAddress = null; + + addrs.add("0.0.0.0"); + if (!preferIPv4Stack) { + if (hasIPv6()) { + addrs.add("::0"); + } + } + + for (String addr : addrs) { + inetAddress = InetAddress.getByName(addr); + System.out.println("The target ip is " + + inetAddress.getHostAddress()); + boolean isReachable = inetAddress.isReachable(3000); + System.out.println("the target is reachable: " + isReachable); + if (isReachable) { + System.out.println("Test passed "); + } else { + System.out.println("Test failed "); + throw new Exception("address " + inetAddress.getHostAddress() + + " can not be reachable!"); + } + } + } +} diff --git a/jdk/test/java/nio/MappedByteBuffer/Truncate.java b/jdk/test/java/nio/MappedByteBuffer/Truncate.java index 09dee07e60c..be74c80df93 100644 --- a/jdk/test/java/nio/MappedByteBuffer/Truncate.java +++ b/jdk/test/java/nio/MappedByteBuffer/Truncate.java @@ -88,6 +88,11 @@ public class Truncate { } }; Thread t = new Thread(r); + t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + e.printStackTrace(); + } + }); t.start(); try { t.join(); } catch (InterruptedException ignore) { } } diff --git a/jdk/test/java/rmi/activation/checkusage/CheckUsage.java b/jdk/test/java/rmi/activation/checkusage/CheckUsage.java index 7f3f041f9c6..095bdc2782e 100644 --- a/jdk/test/java/rmi/activation/checkusage/CheckUsage.java +++ b/jdk/test/java/rmi/activation/checkusage/CheckUsage.java @@ -53,12 +53,9 @@ public class CheckUsage { rmidVM.start(); // wait for registry exit + int rmidVMExitStatus = rmidVM.getVM().waitFor(); System.err.println("rmid exited with status: " + - rmidVM.getVM().waitFor()); - try { - Thread.sleep(7000); - } catch (InterruptedException ie) { - } + rmidVMExitStatus); String usage = new String(berr.toByteArray()); diff --git a/jdk/test/java/rmi/testlibrary/ActivationLibrary.java b/jdk/test/java/rmi/testlibrary/ActivationLibrary.java index 2dd27343685..86c1744ef71 100644 --- a/jdk/test/java/rmi/testlibrary/ActivationLibrary.java +++ b/jdk/test/java/rmi/testlibrary/ActivationLibrary.java @@ -63,19 +63,30 @@ public class ActivationLibrary { */ public static void deactivate(Remote remote, ActivationID id) { - for (int i = 0; i < 5; i ++) { + // We do as much as 50 deactivation trials, each separated by + // at least 100 milliseconds sleep time (max sleep time of 5 secs). + final long deactivateSleepTime = 100; + for (int i = 0; i < 50; i ++) { try { if (Activatable.inactive(id) == true) { mesg("inactive successful"); return; } else { - Thread.sleep(1000); + mesg("inactive trial failed. Sleeping " + + deactivateSleepTime + + " milliseconds before next trial"); + Thread.sleep(deactivateSleepTime); } } catch (InterruptedException e) { - continue; + Thread.currentThread().interrupt(); + mesg("Thread interrupted while trying to deactivate activatable. Exiting deactivation"); + return; } catch (Exception e) { try { // forcibly unexport the object + mesg("Unexpected exception. Have to forcibly unexport the object." + + " Exception was :"); + e.printStackTrace(); Activatable.unexportObject(remote, true); } catch (NoSuchObjectException ex) { } @@ -99,37 +110,61 @@ public class ActivationLibrary { * activation system. */ public static boolean rmidRunning(int port) { - int allowedNotReady = 10; + int allowedNotReady = 50; int connectionRefusedExceptions = 0; - for (int i = 0; i < 15 ; i++) { + /* We wait as much as a total of 7.5 secs trying to see Rmid running. + * We do this by pausing steps of 100 milliseconds (so up to 75 steps), + * right after trying to lookup and find RMID running in the other vm. + */ + final long rmidWaitingStepTime = 100; + for (int i = 0; i <= 74; i++) { try { - Thread.sleep(500); LocateRegistry.getRegistry(port).lookup(SYSTEM_NAME); + mesg("Activation System available after " + + (i * rmidWaitingStepTime) + " milliseconds"); return true; } catch (java.rmi.ConnectException e) { - // ignore connect exceptions until we decide rmid is not up + mesg("Remote connection refused after " + + (i * rmidWaitingStepTime) + " milliseconds"); + // ignore connect exceptions until we decide rmid is not up if ((connectionRefusedExceptions ++) >= allowedNotReady) { return false; } - } catch (NotBoundException e) { + } catch (java.rmi.NoSuchObjectException nsoe) { + /* Activation System still unavailable. + * Ignore this since we are just waiting for its availibility. + * Just signal unavailibility. + */ + mesg("Activation System still unavailable after more than " + + (i * rmidWaitingStepTime) + " milliseconds"); + } catch (NotBoundException e) { return false; } catch (Exception e) { - // print out other types of exceptions as an FYI. - // test should not fail as rmid is likely to be in an - // undetermined state at this point. - + /* print out other types of exceptions as an FYI. + * test should not fail as rmid is likely to be in an + * undetermined state at this point. + */ mesg("caught an exception trying to" + " start rmid, last exception was: " + e.getMessage()); e.printStackTrace(); } + + // Waiting for another 100 milliseconds. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + mesg("Thread interrupted while checking if Activation System is running. Exiting check"); + return false; + } } return false; } diff --git a/jdk/test/java/rmi/testlibrary/JavaVM.java b/jdk/test/java/rmi/testlibrary/JavaVM.java index 4356f34a803..62be87d8279 100644 --- a/jdk/test/java/rmi/testlibrary/JavaVM.java +++ b/jdk/test/java/rmi/testlibrary/JavaVM.java @@ -36,7 +36,6 @@ import java.util.StringTokenizer; */ public class JavaVM { - // need to protected Process vm = null; private String classname = ""; @@ -46,6 +45,10 @@ public class JavaVM { private OutputStream errorStream = System.err; private String policyFileName = null; + // This is used to shorten waiting time at startup. + private volatile boolean started = false; + private boolean forcesOutput = true; // default behavior + private static void mesg(Object mesg) { System.err.println("JAVAVM: " + mesg.toString()); } @@ -79,6 +82,25 @@ public class JavaVM { this.errorStream = err; } + /* This constructor will instantiate a JavaVM object for which caller + * can ask for forcing initial version output on child vm process + * (if forcesVersionOutput is true), or letting the started vm behave freely + * (when forcesVersionOutput is false). + */ + public JavaVM(String classname, + String options, String args, + OutputStream out, OutputStream err, + boolean forcesVersionOutput) { + this(classname, options, args, out, err); + this.forcesOutput = forcesVersionOutput; + } + + + public void setStarted() { + started = true; + } + + // Prepends passed opts array to current options public void addOptions(String[] opts) { String newOpts = ""; for (int i = 0 ; i < opts.length ; i ++) { @@ -87,6 +109,8 @@ public class JavaVM { newOpts += " "; options = newOpts + options; } + + // Prepends passed arguments array to current args public void addArguments(String[] arguments) { String newArgs = ""; for (int i = 0 ; i < arguments.length ; i ++) { @@ -127,6 +151,18 @@ public class JavaVM { addOptions(new String[] { getCodeCoverageOptions() }); + /* + * If forcesOutput is true : + * We force the new starting vm to output something so that we can know + * when it is effectively started by redirecting standard output through + * the next StreamPipe call (the vm is considered started when a first + * output has been streamed out). + * We do this by prepnding a "-showversion" option in the command line. + */ + if (forcesOutput) { + addOptions(new String[] {"-showversion"}); + } + StringTokenizer optionsTokenizer = new StringTokenizer(options); StringTokenizer argsTokenizer = new StringTokenizer(args); int optionsCount = optionsTokenizer.countTokens(); @@ -150,15 +186,43 @@ public class JavaVM { vm = Runtime.getRuntime().exec(javaCommand); /* output from the execed process may optionally be captured. */ - StreamPipe.plugTogether(vm.getInputStream(), this.outputStream); - StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream); + StreamPipe.plugTogether(this, vm.getInputStream(), this.outputStream); + StreamPipe.plugTogether(this, vm.getErrorStream(), this.errorStream); try { - Thread.sleep(2000); - } catch (Exception ignore) { - } + if (forcesOutput) { + // Wait distant vm to start, by using waiting time slices of 100 ms. + // Wait at most for 2secs, after it considers the vm to be started. + final long vmStartSleepTime = 100; + final int maxTrials = 20; + int numTrials = 0; + while (!started && numTrials < maxTrials) { + numTrials++; + Thread.sleep(vmStartSleepTime); + } - mesg("finished starting vm."); + // Outputs running status of distant vm + String message = + "after " + (numTrials * vmStartSleepTime) + " milliseconds"; + if (started) { + mesg("distant vm process running, " + message); + } + else { + mesg("unknown running status of distant vm process, " + message); + } + } + else { + // Since we have no way to know if the distant vm is started, + // we just consider the vm to be started after a 2secs waiting time. + Thread.sleep(2000); + mesg("distant vm considered to be started after a waiting time of 2 secs"); + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + mesg("Thread interrupted while checking if distant vm is started. Giving up check."); + mesg("Distant vm state unknown"); + return; + } } public void destroy() { diff --git a/jdk/test/java/rmi/testlibrary/RMID.java b/jdk/test/java/rmi/testlibrary/RMID.java index 0663fdf73b2..8a8ac3978ca 100644 --- a/jdk/test/java/rmi/testlibrary/RMID.java +++ b/jdk/test/java/rmi/testlibrary/RMID.java @@ -218,20 +218,30 @@ public class RMID extends JavaVM { } catch (NumberFormatException ignore) {} waitTime = waitTime * slopFactor; - // give rmid time to come up + // We check several times (as many as provides passed waitTime) to + // see if Rmid is currently running. Waiting steps last 100 msecs. + final long rmidStartSleepTime = 100; do { + // Sleeping for another rmidStartSleepTime time slice. try { - Thread.sleep(Math.min(waitTime, 10000)); + Thread.sleep(Math.min(waitTime, rmidStartSleepTime)); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); + mesg("Thread interrupted while checking for start of Activation System. Giving up check."); + mesg("Activation System state unknown"); + return; } - waitTime -= 10000; + waitTime -= rmidStartSleepTime; - // is rmid present? + // Checking if rmid is present if (ActivationLibrary.rmidRunning(port)) { mesg("finished starting rmid."); return; } + else { + mesg("rmid still not started"); + } + } while (waitTime > 0); TestLibrary.bomb("start rmid failed... giving up", null); } @@ -264,6 +274,8 @@ public class RMID extends JavaVM { port + "/java.rmi.activation.ActivationSystem"); mesg("obtained a reference to the activation system"); + } catch (RemoteException re) { + mesg("could not contact registry while trying to shutdown activation system"); } catch (java.net.MalformedURLException mue) { } @@ -272,19 +284,14 @@ public class RMID extends JavaVM { } system.shutdown(); + } catch (RemoteException re) { + mesg("shutting down the activation daemon failed"); } catch (Exception e) { mesg("caught exception trying to shutdown rmid"); mesg(e.getMessage()); e.printStackTrace(); } - try { - // wait for the shutdown to happen - Thread.sleep(5000); - } catch (InterruptedException ie) { - Thread.currentThread().interrupt(); - } - mesg("testlibrary finished shutting down rmid"); } @@ -301,18 +308,47 @@ public class RMID extends JavaVM { if (vm != null) { try { - // destroy rmid if it is still running... - try { - vm.exitValue(); - mesg("rmid exited on shutdown request"); - } catch (IllegalThreadStateException illegal) { - mesg("Had to destroy RMID's process " + - "using Process.destroy()"); + /* Waiting for distant RMID process to shutdown. + * Waiting is bounded at a hardcoded max of 60 secs (1 min). + * Waiting by steps of 200 msecs, thus at most 300 such attempts + * for termination of distant RMID process. If process is not + * known to be terminated properly after that time, + * we give up for a gracefull termination, and thus go for + * forcibly destroying the process. + */ + boolean vmEnded = false; + int waitingTrials = 0; + final int maxTrials = 300; + final long vmProcessEndWaitInterval = 200; + int vmExitValue; + do { + try { + Thread.sleep(vmProcessEndWaitInterval); + waitingTrials++; + vmExitValue = vm.exitValue(); + mesg("rmid exited on shutdown request"); + vmEnded = true; + } catch (IllegalThreadStateException illegal) { + mesg("RMID's process still not terminated after more than " + + (waitingTrials * vmProcessEndWaitInterval) + " milliseconds"); + } + } + while (!vmEnded && + (waitingTrials < maxTrials)); + + if (waitingTrials >= maxTrials) { + mesg("RMID's process still not terminated after more than " + + (waitingTrials * vmProcessEndWaitInterval) + " milliseconds." + + "Givinp up gracefull termination..."); + mesg("destroying RMID's process using Process.destroy()"); super.destroy(); } + } catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + mesg("Thread interrupted while checking for termination of distant rmid vm. Giving up check."); } catch (Exception e) { - mesg("caught exception trying to destroy rmid: " + + mesg("caught unexpected exception trying to destroy rmid: " + e.getMessage()); e.printStackTrace(); } diff --git a/jdk/test/java/rmi/testlibrary/StreamPipe.java b/jdk/test/java/rmi/testlibrary/StreamPipe.java index e68eefe41af..9278539bfdf 100644 --- a/jdk/test/java/rmi/testlibrary/StreamPipe.java +++ b/jdk/test/java/rmi/testlibrary/StreamPipe.java @@ -35,46 +35,89 @@ public class StreamPipe extends Thread { private InputStream in; private OutputStream out; private String preamble; + private JavaVM javaVM; private static Object lock = new Object(); private static int count = 0; - public StreamPipe(InputStream in, OutputStream out, String name) { + + /* StreamPipe constructor : should only be called by plugTogether() method !! + * If passed vm is not null : + * - This is StreamPipe usage when streams to pipe come from a given + * vm (JavaVM) process (the vm process must be started with a prefixed + * "-showversion" option to be able to determine as soon as possible when + * the vm process is started through the redirection of the streams). + * There must be a close connection between the StreamPipe instance and + * the JavaVM object on which a start() call has been done. + * run() method will flag distant JavaVM as started. + * If passed vm is null : + * - We don't have control on the process which we want to redirect the passed + * streams. + * run() method will ignore distant process. + */ + private StreamPipe(JavaVM vm, InputStream in, OutputStream out, String name) { super(name); this.in = in; this.out = out; this.preamble = "# "; + this.javaVM = vm; } - public void run() { - BufferedReader r = new BufferedReader(new InputStreamReader(in), 1); - BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out)); - byte[] buf = new byte[256]; - boolean bol = true; // beginning-of-line - int count; - - try { - String line; - while ((line = r.readLine()) != null) { - w.write(preamble); - w.write(line); - w.newLine(); - w.flush(); - } - } catch (IOException e) { - System.err.println("*** IOException in StreamPipe.run:"); - e.printStackTrace(); - } - } - - public static void plugTogether(InputStream in, OutputStream out) { + // Install redirection of passed InputStream and OutputStream from passed JavaVM + // to this vm standard output and input streams. + public static void plugTogether(JavaVM vm, InputStream in, OutputStream out) { String name = null; synchronized (lock) { name = "TestLibrary: StreamPipe-" + (count ++ ); } - Thread pipe = new StreamPipe(in, out, name); + Thread pipe = new StreamPipe(vm, in, out, name); pipe.setDaemon(true); pipe.start(); } + + /* Redirects the InputStream and OutputStream passed by caller to this + * vm standard output and input streams. + * (we just have to use fully parametered plugTogether() call with a null + * JavaVM input to do this). + */ + public static void plugTogether(InputStream in, OutputStream out) { + plugTogether(null, in, out); + } + + // Starts redirection of streams. + public void run() { + BufferedReader r = new BufferedReader(new InputStreamReader(in), 1); + BufferedWriter w = new BufferedWriter(new OutputStreamWriter(out)); + byte[] buf = new byte[256]; + + try { + String line; + + /* This is to check that the distant vm has started, + * if such a vm has been provided at construction : + * - As soon as we can read something from r BufferedReader, + * that means the distant vm is already started. + * Thus we signal associated JavaVM object that it is now started. + */ + if (((line = r.readLine()) != null) && + (javaVM != null)) { + javaVM.setStarted(); + } + + // Redirects r on w. + while (line != null) { + w.write(preamble); + w.write(line); + w.newLine(); + w.flush(); + line = r.readLine(); + } + + } catch (IOException e) { + System.err.println("*** IOException in StreamPipe.run:"); + e.printStackTrace(); + } + } + } diff --git a/jdk/test/java/util/UUID/UUIDTest.java b/jdk/test/java/util/UUID/UUIDTest.java index d9161c2eab2..dca2d775232 100644 --- a/jdk/test/java/util/UUID/UUIDTest.java +++ b/jdk/test/java/util/UUID/UUIDTest.java @@ -58,6 +58,12 @@ public class UUIDTest { List list = new LinkedList(); for (int i=0; i<100; i++) { UUID u1 = UUID.randomUUID(); + if (4 != u1.version()) { + throw new Exception("bad version"); + } + if (2 != u1.variant()) { + throw new Exception("bad variant"); + } if (list.contains(u1)) throw new Exception("random UUID collision very unlikely"); list.add(u1); @@ -70,10 +76,16 @@ public class UUIDTest { List list = new LinkedList(); for (int i=0; i<100; i++) { byteSource.nextBytes(someBytes); - UUID test = UUID.nameUUIDFromBytes(someBytes); - if (list.contains(test)) + UUID u1 = UUID.nameUUIDFromBytes(someBytes); + if (3 != u1.version()) { + throw new Exception("bad version"); + } + if (2 != u1.variant()) { + throw new Exception("bad variant"); + } + if (list.contains(u1)) throw new Exception("byte UUID collision very unlikely"); - list.add(test); + list.add(u1); } } diff --git a/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java b/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java new file mode 100644 index 00000000000..62d066914d2 --- /dev/null +++ b/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2012, 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 7103570 + * @author David Holmes + * @run main/othervm AtomicUpdaters + * @run main/othervm AtomicUpdaters UseSM + * @summary Checks the (in)ability to create field updaters for differently + * accessible fields in different locations with/without a security + * manager + */ +import java.util.concurrent.atomic.*; +import java.lang.reflect.*; +import java.security.AccessControlException; + +public class AtomicUpdaters { + enum TYPE { INT, LONG, REF } + + static class Config { + final Class clazz; + final String field; + final String access; + final boolean reflectOk; + final boolean updaterOk; + final String desc; + final TYPE type; + + Config(Class clazz, String field, String access, + boolean reflectOk, boolean updaterOk, String desc, TYPE type) { + this.clazz = clazz; + this.field = field; + this.access = access; + this.reflectOk = reflectOk; + this.updaterOk = updaterOk; + this.desc = desc; + this.type =type; + } + + public String toString() { + return desc + ": " + access + " " + clazz.getName() + "." + field; + } + } + + static Config[] tests; + + static void initTests(boolean hasSM) { + tests = new Config[] { + new Config(AtomicUpdaters.class, "pub_int", "public", true, true, "public int field of current class", TYPE.INT), + new Config(AtomicUpdaters.class, "priv_int", "private", true, true, "private int field of current class", TYPE.INT), + new Config(AtomicUpdaters.class, "pub_long", "public", true, true, "public long field of current class", TYPE.LONG), + new Config(AtomicUpdaters.class, "priv_long", "private", true, true, "private long field of current class", TYPE.LONG), + new Config(AtomicUpdaters.class, "pub_ref", "public", true, true, "public ref field of current class", TYPE.REF), + new Config(AtomicUpdaters.class, "priv_ref", "private", true, true, "private ref field of current class", TYPE.REF), + + // Would like to test a public volatile in a class in another + // package - but of course there aren't any + new Config(java.util.concurrent.atomic.AtomicInteger.class, "value", "private", hasSM ? false : true, false, "private int field of class in different package", TYPE.INT), + new Config(java.util.concurrent.atomic.AtomicLong.class, "value", "private", hasSM ? false : true, false, "private long field of class in different package", TYPE.LONG), + new Config(java.util.concurrent.atomic.AtomicReference.class, "value", "private", hasSM ? false : true, false, "private reference field of class in different package", TYPE.REF), + }; + } + + public volatile int pub_int; + private volatile int priv_int; + public volatile long pub_long; + private volatile long priv_long; + public volatile Object pub_ref; + private volatile Object priv_ref; + + + // This should be set dynamically at runtime using a System property, but + // ironically we get a SecurityException if we try to do that with a + // SecurityManager installed + static boolean verbose; + + public static void main(String[] args) throws Throwable { + boolean hasSM = false; + for (String arg : args) { + if ("-v".equals(arg)) { + verbose = true; + } + else if ("UseSM".equals(arg)) { + SecurityManager m = System.getSecurityManager(); + if (m != null) + throw new RuntimeException("No security manager should initially be installed"); + System.setSecurityManager(new java.lang.SecurityManager()); + hasSM = true; + } + else { + throw new IllegalArgumentException("Unexpected option: " + arg); + } + } + initTests(hasSM); + + int failures = 0; + + System.out.printf("Testing with%s a SecurityManager present\n", hasSM ? "" : "out"); + for (Config c : tests) { + System.out.println("Testing: " + c); + Error reflectionFailure = null; + Error updaterFailure = null; + Class clazz = c.clazz; + // See if we can reflectively access the field + System.out.println(" - testing getDeclaredField"); + try { + Field f = clazz.getDeclaredField(c.field); + if (!c.reflectOk) + reflectionFailure = new Error("Unexpected reflective access: " + c); + } + catch (AccessControlException e) { + if (c.reflectOk) + reflectionFailure = new Error("Unexpected reflective access failure: " + c, e); + else if (verbose) { + System.out.println("Got expected reflection exception: " + e); + e.printStackTrace(System.out); + } + } + + if (reflectionFailure != null) { + reflectionFailure.printStackTrace(System.out); + } + + // see if we can create an atomic updater for the field + Object u = null; + try { + switch (c.type) { + case INT: + System.out.println(" - testing AtomicIntegerFieldUpdater"); + u = AtomicIntegerFieldUpdater.newUpdater(clazz, c.field); + break; + case LONG: + System.out.println(" - testing AtomicLongFieldUpdater"); + u = AtomicLongFieldUpdater.newUpdater(clazz, c.field); + break; + case REF: + System.out.println(" - testing AtomicReferenceFieldUpdater"); + u = AtomicReferenceFieldUpdater.newUpdater(clazz, Object.class, c.field); + break; + } + + if (!c.updaterOk) + updaterFailure = new Error("Unexpected updater access: " + c); + } + catch (Exception e) { + if (c.updaterOk) + updaterFailure = new Error("Unexpected updater access failure: " + c, e); + else if (verbose) { + System.out.println("Got expected updater exception: " + e); + e.printStackTrace(System.out); + } + } + + if (updaterFailure != null) { + updaterFailure.printStackTrace(System.out); + } + + if (updaterFailure != null || reflectionFailure != null) { + failures++; + + } + } + + if (failures > 0) { + throw new Error("Some tests failed - see previous stacktraces"); + } + } +} diff --git a/jdk/test/java/util/prefs/RemoveNullKeyCheck.java b/jdk/test/java/util/prefs/RemoveNullKeyCheck.java index e45459b4495..c74f0d82d37 100644 --- a/jdk/test/java/util/prefs/RemoveNullKeyCheck.java +++ b/jdk/test/java/util/prefs/RemoveNullKeyCheck.java @@ -22,23 +22,77 @@ */ /* @test - * @bug 7160242 + * @bug 7160242 7165118 * @summary Check if NullPointerException is thrown if the key passed * to remove() is null. */ import java.util.prefs.Preferences; +import java.util.prefs.AbstractPreferences; +import java.util.prefs.BackingStoreException; public class RemoveNullKeyCheck { + private static boolean failed = false; + public static void main(String[] args) throws Exception { - try { - Preferences node = Preferences.userRoot().node("N1"); - node.remove(null); - throw new RuntimeException("Expected NullPointerException " + - "not thrown"); - } catch (NullPointerException npe) { - System.out.println("NullPointerException thrown"); - } + checkPreferencesRemove(); + checkAbstractPreferencesRemove(); + if (failed) { + throw new RuntimeException("Expected NullPointerException " + + "not thrown"); + } + } + + public static void checkPreferencesRemove() { + try { + Preferences node = Preferences.userRoot().node("N1"); + node.remove(null); + failed = true; + } catch (NullPointerException npe) { + } + } + + public static void checkAbstractPreferencesRemove() { + + Preferences abstrPrefs = new AbstractPreferences(null, "") { + @Override + protected void putSpi(String key, String value) { + } + @Override + protected String getSpi(String key) { + return null; + } + @Override + protected void removeSpi(String key) { + } + @Override + protected void removeNodeSpi() throws BackingStoreException { + } + @Override + protected String[] keysSpi() throws BackingStoreException { + return new String[0]; + } + @Override + protected String[] childrenNamesSpi() throws BackingStoreException { + return new String[0]; + } + @Override + protected AbstractPreferences childSpi(String name) { + return null; + } + @Override + protected void syncSpi() throws BackingStoreException { + } + @Override + protected void flushSpi() throws BackingStoreException { + } + }; + + try { + abstrPrefs.remove(null); + failed = true; + } catch(NullPointerException npe) { + } } } diff --git a/jdk/test/java/util/regex/RegExTest.java b/jdk/test/java/util/regex/RegExTest.java index f583769ecb2..7846f5c05e3 100644 --- a/jdk/test/java/util/regex/RegExTest.java +++ b/jdk/test/java/util/regex/RegExTest.java @@ -33,7 +33,7 @@ * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940 * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133 * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066 - * 7067045 + * 7067045 7014640 */ import java.util.regex.*; @@ -141,6 +141,8 @@ public class RegExTest { unicodePropertiesTest(); unicodeHexNotationTest(); unicodeClassesTest(); + horizontalAndVerticalWSTest(); + linebreakTest(); if (failure) { throw new RuntimeException("RegExTest failed, 1st failure: " + @@ -857,13 +859,18 @@ public class RegExTest { // in replacement string try { "\uac00".replaceAll("\uac00", "$"); + failCount++; + } catch (IllegalArgumentException iie) { + } catch (Exception e) { + failCount++; + } + try { "\uac00".replaceAll("\uac00", "\\"); failCount++; } catch (IllegalArgumentException iie) { } catch (Exception e) { failCount++; } - report("Literal replacement"); } @@ -3838,4 +3845,77 @@ public class RegExTest { failCount++; report("unicodePredefinedClasses"); } + + private static void horizontalAndVerticalWSTest() throws Exception { + String hws = new String (new char[] { + 0x09, 0x20, 0xa0, 0x1680, 0x180e, + 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, + 0x2006, 0x2007, 0x2008, 0x2009, 0x200a, + 0x202f, 0x205f, 0x3000 }); + String vws = new String (new char[] { + 0x0a, 0x0b, 0x0c, 0x0d, 0x85, 0x2028, 0x2029 }); + if (!Pattern.compile("\\h+").matcher(hws).matches() || + !Pattern.compile("[\\h]+").matcher(hws).matches()) + failCount++; + if (Pattern.compile("\\H").matcher(hws).find() || + Pattern.compile("[\\H]").matcher(hws).find()) + failCount++; + if (!Pattern.compile("\\v+").matcher(vws).matches() || + !Pattern.compile("[\\v]+").matcher(vws).matches()) + failCount++; + if (Pattern.compile("\\V").matcher(vws).find() || + Pattern.compile("[\\V]").matcher(vws).find()) + failCount++; + String prefix = "abcd"; + String suffix = "efgh"; + String ng = "A"; + for (int i = 0; i < hws.length(); i++) { + String c = String.valueOf(hws.charAt(i)); + Matcher m = Pattern.compile("\\h").matcher(prefix + c + suffix); + if (!m.find() || !c.equals(m.group())) + failCount++; + m = Pattern.compile("[\\h]").matcher(prefix + c + suffix); + if (!m.find() || !c.equals(m.group())) + failCount++; + + m = Pattern.compile("\\H").matcher(hws.substring(0, i) + ng + hws.substring(i)); + if (!m.find() || !ng.equals(m.group())) + failCount++; + m = Pattern.compile("[\\H]").matcher(hws.substring(0, i) + ng + hws.substring(i)); + if (!m.find() || !ng.equals(m.group())) + failCount++; + } + for (int i = 0; i < vws.length(); i++) { + String c = String.valueOf(vws.charAt(i)); + Matcher m = Pattern.compile("\\v").matcher(prefix + c + suffix); + if (!m.find() || !c.equals(m.group())) + failCount++; + m = Pattern.compile("[\\v]").matcher(prefix + c + suffix); + if (!m.find() || !c.equals(m.group())) + failCount++; + + m = Pattern.compile("\\V").matcher(vws.substring(0, i) + ng + vws.substring(i)); + if (!m.find() || !ng.equals(m.group())) + failCount++; + m = Pattern.compile("[\\V]").matcher(vws.substring(0, i) + ng + vws.substring(i)); + if (!m.find() || !ng.equals(m.group())) + failCount++; + } + // \v in range is interpreted as 0x0B. This is the undocumented behavior + if (!Pattern.compile("[\\v-\\v]").matcher(String.valueOf((char)0x0B)).matches()) + failCount++; + report("horizontalAndVerticalWSTest"); + } + + private static void linebreakTest() throws Exception { + String linebreaks = new String (new char[] { + 0x0A, 0x0B, 0x0C, 0x0D, 0x85, 0x2028, 0x2029 }); + String crnl = "\r\n"; + if (!Pattern.compile("\\R+").matcher(linebreaks).matches() || + !Pattern.compile("\\R").matcher(crnl).matches() || + Pattern.compile("\\R\\R").matcher(crnl).matches()) + failCount++; + report("linebreakTest"); + } + } diff --git a/jdk/test/sun/management/AgentCMETest.java b/jdk/test/sun/management/AgentCMETest.java new file mode 100644 index 00000000000..f8bfd5355c2 --- /dev/null +++ b/jdk/test/sun/management/AgentCMETest.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2012 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. + */ + +/* + * Portions Copyright (c) 2012 IBM Corporation + */ + +/** + * @test + * @bug 7164191 + * @summary properties.putAll API may fail with ConcurrentModifcationException on multi-thread scenario + * @author Deven You + */ + +import java.util.Properties; +import sun.management.Agent; + +public class AgentCMETest { + static Class agentClass; + + /** + * In sun.management.Agent.loadManagementProperties(), call + * properties.putAll API may fail with ConcurrentModifcationException if the + * system properties are modified simultaneously by another thread + * + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { + System.out.println("Start..."); + + final Properties properties = System.getProperties(); + Thread t1 = new Thread(new Runnable() { + public void run() { + for (int i = 0; i < 100; i++) { + properties.put(String.valueOf(i), ""); + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // do nothing + } + } + } + }); + t1.start(); + + for (int i = 0; i < 10000; i++) { + Agent.loadManagementProperties(); + } + + System.out.println("Finished..."); + } +} diff --git a/jdk/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java b/jdk/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java index 7ecfd5e8483..cd1541ccbb7 100644 --- a/jdk/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java +++ b/jdk/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java @@ -60,9 +60,12 @@ public class NoConsoleOutput { File.separatorChar + "logging.properties"; ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); + + // We instantiate a JavaVM that should not produce any console output + // (neither on standard output, nor on standard err streams). JavaVM vm = new JavaVM(DoRMIStuff.class.getName(), "-Djava.util.logging.config.file=" + loggingPropertiesFile, - "", out, err); + "", out, err, false); vm.start(); vm.getVM().waitFor(); diff --git a/jdk/test/sun/security/krb5/auto/SSL.java b/jdk/test/sun/security/krb5/auto/SSL.java index 496097bbc8c..7ad0bd82c70 100644 --- a/jdk/test/sun/security/krb5/auto/SSL.java +++ b/jdk/test/sun/security/krb5/auto/SSL.java @@ -53,6 +53,9 @@ public class SSL { private static volatile String server; private static volatile int port; + // 0-Not started, 1-Start OK, 2-Failure + private static volatile int serverState = 0; + public static void main(String[] args) throws Exception { krb5Cipher = args[0]; @@ -109,14 +112,20 @@ public class SSL { s.doAs(new JsseServerAction(), null); } catch (Exception e) { e.printStackTrace(); + serverState = 2; } } }); server.setDaemon(true); server.start(); - // Warm the server - Thread.sleep(2000); + while (serverState == 0) { + Thread.sleep(50); + } + + if (serverState == 2) { + throw new Exception("Server already failed"); + } // Now create the keytab @@ -214,6 +223,7 @@ public class SSL { (SSLServerSocket) sslssf.createServerSocket(0); // any port port = sslServerSocket.getLocalPort(); System.out.println("Listening on " + port); + serverState = 1; // Enable only a KRB5 cipher suite. String enabledSuites[] = {krb5Cipher}; diff --git a/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh b/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh index b446143ecb1..9caeed46c39 100644 --- a/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh +++ b/jdk/test/sun/security/mscapi/ShortRSAKey1024.sh @@ -46,11 +46,20 @@ if [ "${TESTJAVA}" = "" ] ; then fi OS=`uname -s` +case "$OS" in + SunOS | Linux | Darwin | CYGWIN* ) + FS="/" + ;; + Windows_* ) + FS="\\" + ;; +esac + case "$OS" in Windows* | CYGWIN* ) echo "Creating a temporary RSA keypair in the Windows-My store..." - ${TESTJAVA}/bin/keytool \ + ${TESTJAVA}${FS}bin${FS}keytool \ -genkeypair \ -storetype Windows-My \ -keyalg RSA \ @@ -59,22 +68,28 @@ case "$OS" in -dname "cn=localhost,c=US" \ -noprompt + if [ "$?" -ne "0" ]; then + echo "Unable to generate key pair in Windows-My keystore" + exit 1 + fi + echo echo "Running the test..." - ${TESTJAVA}/bin/javac -d . ${TESTSRC}\\ShortRSAKeyWithinTLS.java - ${TESTJAVA}/bin/java ShortRSAKeyWithinTLS 7106773.1024 1024 \ + ${TESTJAVA}${FS}bin${FS}javac -d . \ + ${TESTSRC}${FS}ShortRSAKeyWithinTLS.java + ${TESTJAVA}${FS}bin${FS}java ShortRSAKeyWithinTLS 7106773.1024 1024 \ TLSv1.2 TLS_DHE_RSA_WITH_AES_128_CBC_SHA rc=$? echo echo "Removing the temporary RSA keypair from the Windows-My store..." - ${TESTJAVA}/bin/keytool \ + ${TESTJAVA}${FS}bin${FS}keytool \ -delete \ -storetype Windows-My \ -alias 7106773.1024 - echo done. + echo "Done". exit $rc ;; diff --git a/jdk/test/sun/security/mscapi/ShortRSAKey512.sh b/jdk/test/sun/security/mscapi/ShortRSAKey512.sh index e4cae406383..b8cb84076a3 100644 --- a/jdk/test/sun/security/mscapi/ShortRSAKey512.sh +++ b/jdk/test/sun/security/mscapi/ShortRSAKey512.sh @@ -46,11 +46,20 @@ if [ "${TESTJAVA}" = "" ] ; then fi OS=`uname -s` +case "$OS" in + SunOS | Linux | Darwin | CYGWIN* ) + FS="/" + ;; + Windows_* ) + FS="\\" + ;; +esac + case "$OS" in Windows* | CYGWIN* ) echo "Creating a temporary RSA keypair in the Windows-My store..." - ${TESTJAVA}/bin/keytool \ + ${TESTJAVA}${FS}bin${FS}keytool \ -genkeypair \ -storetype Windows-My \ -keyalg RSA \ @@ -59,10 +68,16 @@ case "$OS" in -dname "cn=localhost,c=US" \ -noprompt + if [ "$?" -ne "0" ]; then + echo "Unable to generate key pair in Windows-My keystore" + exit 1 + fi + echo echo "Running the test..." - ${TESTJAVA}/bin/javac -d . ${TESTSRC}\\ShortRSAKeyWithinTLS.java - ${TESTJAVA}/bin/java ShortRSAKeyWithinTLS 7106773.512 512 \ + ${TESTJAVA}${FS}bin${FS}javac -d . \ + ${TESTSRC}${FS}ShortRSAKeyWithinTLS.java + ${TESTJAVA}${FS}bin${FS}java ShortRSAKeyWithinTLS 7106773.512 512 \ TLSv1.2 TLS_DHE_RSA_WITH_AES_128_CBC_SHA @@ -70,12 +85,12 @@ case "$OS" in echo echo "Removing the temporary RSA keypair from the Windows-My store..." - ${TESTJAVA}/bin/keytool \ + ${TESTJAVA}${FS}bin${FS}keytool \ -delete \ -storetype Windows-My \ -alias 7106773.512 - echo done. + echo "Done". exit $rc ;; diff --git a/jdk/test/sun/security/mscapi/ShortRSAKey768.sh b/jdk/test/sun/security/mscapi/ShortRSAKey768.sh index a81903b818c..0732f9a1029 100644 --- a/jdk/test/sun/security/mscapi/ShortRSAKey768.sh +++ b/jdk/test/sun/security/mscapi/ShortRSAKey768.sh @@ -46,11 +46,20 @@ if [ "${TESTJAVA}" = "" ] ; then fi OS=`uname -s` +case "$OS" in + SunOS | Linux | Darwin | CYGWIN* ) + FS="/" + ;; + Windows_* ) + FS="\\" + ;; +esac + case "$OS" in Windows* | CYGWIN* ) echo "Creating a temporary RSA keypair in the Windows-My store..." - ${TESTJAVA}/bin/keytool \ + ${TESTJAVA}${FS}bin${FS}keytool \ -genkeypair \ -storetype Windows-My \ -keyalg RSA \ @@ -59,22 +68,28 @@ case "$OS" in -dname "cn=localhost,c=US" \ -noprompt + if [ "$?" -ne "0" ]; then + echo "Unable to generate key pair in Windows-My keystore" + exit 1 + fi + echo echo "Running the test..." - ${TESTJAVA}/bin/javac -d . ${TESTSRC}\\ShortRSAKeyWithinTLS.java - ${TESTJAVA}/bin/java ShortRSAKeyWithinTLS 7106773.768 768 \ + ${TESTJAVA}${FS}bin${FS}javac -d . \ + ${TESTSRC}${FS}ShortRSAKeyWithinTLS.java + ${TESTJAVA}${FS}bin${FS}java ShortRSAKeyWithinTLS 7106773.768 768 \ TLSv1.2 TLS_DHE_RSA_WITH_AES_128_CBC_SHA rc=$? echo echo "Removing the temporary RSA keypair from the Windows-My store..." - ${TESTJAVA}/bin/keytool \ + ${TESTJAVA}${FS}bin${FS}keytool \ -delete \ -storetype Windows-My \ -alias 7106773.768 - echo done. + echo "Done". exit $rc ;; diff --git a/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.java b/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.java index 58934767cd8..02cf4f67c80 100644 --- a/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.java +++ b/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2012, 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 diff --git a/jdk/test/sun/security/mscapi/SignUsingSHA2withRSA.java b/jdk/test/sun/security/mscapi/SignUsingSHA2withRSA.java index e2bd06b1905..6835bd3f959 100644 --- a/jdk/test/sun/security/mscapi/SignUsingSHA2withRSA.java +++ b/jdk/test/sun/security/mscapi/SignUsingSHA2withRSA.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2012, 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 diff --git a/jdk/test/sun/security/pkcs11/MessageDigest/DigestKAT.java b/jdk/test/sun/security/pkcs11/MessageDigest/DigestKAT.java index 86cb520d774..e6f948d064f 100644 --- a/jdk/test/sun/security/pkcs11/MessageDigest/DigestKAT.java +++ b/jdk/test/sun/security/pkcs11/MessageDigest/DigestKAT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -174,6 +174,12 @@ public class DigestKAT extends PKCS11Test { t("SHA1", s("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), "50:ab:f5:70:6a:15:09:90:a0:8b:2c:5e:a4:0f:a0:e5:85:55:47:32"), t("SHA1", ALONG, "ce:56:53:59:08:04:ba:a9:36:9f:72:d4:83:ed:9e:ba:72:f0:4d:29"), + t("SHA-224", s(""), "d1:4a:02:8c:2a:3a:2b:c9:47:61:02:bb:28:82:34:c4:15:a2:b0:1f:82:8e:a6:2a:c5:b3:e4:2f"), + t("SHA-224", s("abc"), "23:09:7d:22:34:05:d8:22:86:42:a4:77:bd:a2:55:b3:2a:ad:bc:e4:bd:a0:b3:f7:e3:6c:9d:a7"), + t("SHA-224", s("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), "75:38:8b:16:51:27:76:cc:5d:ba:5d:a1:fd:89:01:50:b0:c6:45:5c:b4:f5:8b:19:52:52:25:25"), + t("SHA-224", s("The quick brown fox jumps over the lazy dog"), "73:0e:10:9b:d7:a8:a3:2b:1c:b9:d9:a0:9a:a2:32:5d:24:30:58:7d:db:c0:c3:8b:ad:91:15:25"), + t("SHA-224", s("The quick brown fox jumps over the lazy dog."), "61:9c:ba:8e:8e:05:82:6e:9b:8c:51:9c:0a:5c:68:f4:fb:65:3e:8a:3d:8a:a0:4b:b2:c8:cd:4c"), + t("SHA-256", s(""), "e3:b0:c4:42:98:fc:1c:14:9a:fb:f4:c8:99:6f:b9:24:27:ae:41:e4:64:9b:93:4c:a4:95:99:1b:78:52:b8:55"), t("SHA-256", s("a"), "ca:97:81:12:ca:1b:bd:ca:fa:c2:31:b3:9a:23:dc:4d:a7:86:ef:f8:14:7c:4e:72:b9:80:77:85:af:ee:48:bb"), t("SHA-256", s("abc"), "ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad"), diff --git a/jdk/test/sun/security/pkcs11/MessageDigest/TestCloning.java b/jdk/test/sun/security/pkcs11/MessageDigest/TestCloning.java index b25acf04905..c998e8092e0 100644 --- a/jdk/test/sun/security/pkcs11/MessageDigest/TestCloning.java +++ b/jdk/test/sun/security/pkcs11/MessageDigest/TestCloning.java @@ -36,7 +36,7 @@ import java.security.*; public class TestCloning extends PKCS11Test { private static final String[] ALGOS = { - "MD2", "MD5", "SHA1", "SHA-256", "SHA-384", "SHA-512" + "MD2", "MD5", "SHA1", "SHA-224", "SHA-256", "SHA-384", "SHA-512" }; public static void main(String[] args) throws Exception { diff --git a/jdk/test/sun/security/pkcs11/Signature/TestRSAKeyLength.java b/jdk/test/sun/security/pkcs11/Signature/TestRSAKeyLength.java index 4a977f2a4e3..81309213b35 100644 --- a/jdk/test/sun/security/pkcs11/Signature/TestRSAKeyLength.java +++ b/jdk/test/sun/security/pkcs11/Signature/TestRSAKeyLength.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2012, 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 @@ -37,7 +37,7 @@ public class TestRSAKeyLength extends PKCS11Test { } public void main(Provider p) throws Exception { boolean isValidKeyLength[] = { true, true, false, false }; - String algos[] = { "SHA1withRSA", "SHA256withRSA", + String algos[] = { "SHA1withRSA", "SHA224withRSA", "SHA256withRSA", "SHA384withRSA", "SHA512withRSA" }; KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", p); kpg.initialize(512); diff --git a/jdk/test/sun/security/pkcs11/ec/TestCurves.java b/jdk/test/sun/security/pkcs11/ec/TestCurves.java index 1d55e573473..aa19e33745f 100644 --- a/jdk/test/sun/security/pkcs11/ec/TestCurves.java +++ b/jdk/test/sun/security/pkcs11/ec/TestCurves.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2012, 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 @@ -68,6 +68,7 @@ public class TestCurves extends PKCS11Test { kp2 = kpg.generateKeyPair(); testSigning(p, "SHA1withECDSA", data, kp1, kp2); + testSigning(p, "SHA224withECDSA", data, kp1, kp2); testSigning(p, "SHA256withECDSA", data, kp1, kp2); testSigning(p, "SHA384withECDSA", data, kp1, kp2); testSigning(p, "SHA512withECDSA", data, kp1, kp2); diff --git a/jdk/test/sun/security/pkcs11/rsa/TestKeyPairGenerator.java b/jdk/test/sun/security/pkcs11/rsa/TestKeyPairGenerator.java index 742ad47452d..85818721b8a 100644 --- a/jdk/test/sun/security/pkcs11/rsa/TestKeyPairGenerator.java +++ b/jdk/test/sun/security/pkcs11/rsa/TestKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -61,6 +61,7 @@ public class TestKeyPairGenerator extends PKCS11Test { testSignature("MD2withRSA", privateKey, publicKey); testSignature("MD5withRSA", privateKey, publicKey); testSignature("SHA1withRSA", privateKey, publicKey); + testSignature("SHA224withRSA", privateKey, publicKey); testSignature("SHA256withRSA", privateKey, publicKey); RSAPublicKey rsaKey = (RSAPublicKey)publicKey; if (rsaKey.getModulus().bitLength() > 512) { diff --git a/jdk/test/sun/security/pkcs11/rsa/TestSignatures.java b/jdk/test/sun/security/pkcs11/rsa/TestSignatures.java index 13c55339429..fd11d0cb67b 100644 --- a/jdk/test/sun/security/pkcs11/rsa/TestSignatures.java +++ b/jdk/test/sun/security/pkcs11/rsa/TestSignatures.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -81,6 +81,7 @@ public class TestSignatures extends PKCS11Test { testSignature("MD2withRSA", privateKey, publicKey); testSignature("MD5withRSA", privateKey, publicKey); testSignature("SHA1withRSA", privateKey, publicKey); + testSignature("SHA224withRSA", privateKey, publicKey); testSignature("SHA256withRSA", privateKey, publicKey); RSAPublicKey rsaKey = (RSAPublicKey)publicKey; if (rsaKey.getModulus().bitLength() > 512) { diff --git a/jdk/test/sun/security/provider/MessageDigest/DigestKAT.java b/jdk/test/sun/security/provider/MessageDigest/DigestKAT.java index a49c5ce8707..c6746de867b 100644 --- a/jdk/test/sun/security/provider/MessageDigest/DigestKAT.java +++ b/jdk/test/sun/security/provider/MessageDigest/DigestKAT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -23,7 +23,7 @@ /** * @test - * @bug 4819771 4834179 5008306 + * @bug 4819771 4834179 5008306 4963723 * @summary Basic known-answer-test for all our MessageDigest algorithms * @author Andreas Sterbenz */ @@ -190,6 +190,12 @@ public class DigestKAT { t("SHA1", ALONG, "ce:56:53:59:08:04:ba:a9:36:9f:72:d4:83:ed:9e:ba:72:f0:4d:29"), t("SHA1", BLONG, "1d:a8:1a:de:8d:1e:d0:82:ba:12:13:e2:56:26:30:fc:05:b8:8d:a6"), + t("SHA-224", s(""), "d1:4a:02:8c:2a:3a:2b:c9:47:61:02:bb:28:82:34:c4:15:a2:b0:1f:82:8e:a6:2a:c5:b3:e4:2f"), + t("SHA-224", s("abc"), "23:09:7d:22:34:05:d8:22:86:42:a4:77:bd:a2:55:b3:2a:ad:bc:e4:bd:a0:b3:f7:e3:6c:9d:a7"), + t("SHA-224", s("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), "75:38:8b:16:51:27:76:cc:5d:ba:5d:a1:fd:89:01:50:b0:c6:45:5c:b4:f5:8b:19:52:52:25:25"), + t("SHA-224", s("The quick brown fox jumps over the lazy dog"), "73:0e:10:9b:d7:a8:a3:2b:1c:b9:d9:a0:9a:a2:32:5d:24:30:58:7d:db:c0:c3:8b:ad:91:15:25"), + t("SHA-224", s("The quick brown fox jumps over the lazy dog."), "61:9c:ba:8e:8e:05:82:6e:9b:8c:51:9c:0a:5c:68:f4:fb:65:3e:8a:3d:8a:a0:4b:b2:c8:cd:4c"), + t("SHA-256", s(""), "e3:b0:c4:42:98:fc:1c:14:9a:fb:f4:c8:99:6f:b9:24:27:ae:41:e4:64:9b:93:4c:a4:95:99:1b:78:52:b8:55"), t("SHA-256", s("a"), "ca:97:81:12:ca:1b:bd:ca:fa:c2:31:b3:9a:23:dc:4d:a7:86:ef:f8:14:7c:4e:72:b9:80:77:85:af:ee:48:bb"), t("SHA-256", s("abc"), "ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad"), diff --git a/jdk/test/sun/security/provider/MessageDigest/Offsets.java b/jdk/test/sun/security/provider/MessageDigest/Offsets.java index 691278e3d18..eaa98fcbd75 100644 --- a/jdk/test/sun/security/provider/MessageDigest/Offsets.java +++ b/jdk/test/sun/security/provider/MessageDigest/Offsets.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2012, 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 @@ -80,6 +80,7 @@ public class Offsets { test("MD2", 0, 64, 0, 128); test("MD5", 0, 64, 0, 128); test("SHA1", 0, 64, 0, 128); + test("SHA-224", 0, 64, 0, 128); test("SHA-256", 0, 64, 0, 128); test("SHA-384", 0, 128, 0, 256); test("SHA-512", 0, 128, 0, 256); diff --git a/jdk/test/sun/security/provider/MessageDigest/TestSHAClone.java b/jdk/test/sun/security/provider/MessageDigest/TestSHAClone.java index 376bb4696a4..f1d1089f39a 100644 --- a/jdk/test/sun/security/provider/MessageDigest/TestSHAClone.java +++ b/jdk/test/sun/security/provider/MessageDigest/TestSHAClone.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2012, 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 @@ -24,7 +24,7 @@ /** * @test * @bug 4775971 - * @summary test the clone implementation of SHA, SHA-256, + * @summary test the clone implementation of SHA, SHA-224, SHA-256, * SHA-384, SHA-512 MessageDigest implementation. */ import java.security.*; @@ -33,7 +33,7 @@ import java.util.*; public class TestSHAClone { private static final String[] ALGOS = { - "SHA", "SHA-256", "SHA-512", "SHA-384" + "SHA", "SHA-224", "SHA-256", "SHA-512", "SHA-384" }; private static byte[] input1 = { diff --git a/jdk/test/sun/security/provider/certpath/ReverseBuilder/ReverseBuild.java b/jdk/test/sun/security/provider/certpath/ReverseBuilder/ReverseBuild.java new file mode 100644 index 00000000000..21736eac623 --- /dev/null +++ b/jdk/test/sun/security/provider/certpath/ReverseBuilder/ReverseBuild.java @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2012, 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 7167988 + * @summary PKIX CertPathBuilder in reverse mode doesn't work if more than + * one trust anchor is specified + */ +import java.io.*; +import java.util.*; +import java.security.cert.*; + +import sun.security.provider.certpath.SunCertPathBuilderParameters; + +public class ReverseBuild { + // Certificate information: + // Issuer: C=US, ST=Some-State, L=Some-City, O=Some-Org + // Validity + // Not Before: Dec 8 02:43:36 2008 GMT + // Not After : Aug 25 02:43:36 2028 GMT + // Subject: C=US, ST=Some-State, L=Some-City, O=Some-Org + // X509v3 Subject Key Identifier: + // FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14 + // X509v3 Authority Key Identifier: + // keyid:FA:B9:51:BF:4C:E7:D9:86:98:33:F9:E7:CB:1E:F1:33:49:F7:A8:14 + // DirName:/C=US/ST=Some-State/L=Some-City/O=Some-Org + // serial:00 + static String NoiceTrusedCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICrDCCAhWgAwIBAgIBADANBgkqhkiG9w0BAQQFADBJMQswCQYDVQQGEwJVUzET\n" + + "MBEGA1UECBMKU29tZS1TdGF0ZTESMBAGA1UEBxMJU29tZS1DaXR5MREwDwYDVQQK\n" + + "EwhTb21lLU9yZzAeFw0wODEyMDgwMjQzMzZaFw0yODA4MjUwMjQzMzZaMEkxCzAJ\n" + + "BgNVBAYTAlVTMRMwEQYDVQQIEwpTb21lLVN0YXRlMRIwEAYDVQQHEwlTb21lLUNp\n" + + "dHkxETAPBgNVBAoTCFNvbWUtT3JnMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB\n" + + "gQDLxDggB76Ip5OwoUNRLdeOha9U3a2ieyNbz5kTU5lFfe5tui2/461uPZ8a+QOX\n" + + "4BdVrhEmV94BKY4FPyH35zboLjfXSKxT1mAOx1Bt9sWF94umxZE1cjyU7vEX8HHj\n" + + "7BvOyk5AQrBt7moO1uWtPA/JuoJPePiJl4kqlRJM2Akq6QIDAQABo4GjMIGgMB0G\n" + + "A1UdDgQWBBT6uVG/TOfZhpgz+efLHvEzSfeoFDBxBgNVHSMEajBogBT6uVG/TOfZ\n" + + "hpgz+efLHvEzSfeoFKFNpEswSTELMAkGA1UEBhMCVVMxEzARBgNVBAgTClNvbWUt\n" + + "U3RhdGUxEjAQBgNVBAcTCVNvbWUtQ2l0eTERMA8GA1UEChMIU29tZS1PcmeCAQAw\n" + + "DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQBcIm534U123Hz+rtyYO5uA\n" + + "ofd81G6FnTfEAV8Kw9fGyyEbQZclBv34A9JsFKeMvU4OFIaixD7nLZ/NZ+IWbhmZ\n" + + "LovmJXyCkOufea73pNiZ+f/4/ScZaIlM/PRycQSqbFNd4j9Wott+08qxHPLpsf3P\n" + + "6Mvf0r1PNTY2hwTJLJmKtg==\n" + + "-----END CERTIFICATE-----"; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce + // Validity + // Not Before: Aug 19 01:52:19 2011 GMT + // Not After : Jul 29 01:52:19 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce + + // X509v3 Subject Key Identifier: + // B9:7C:D5:D9:DF:A7:4C:03:AE:FD:0E:27:5B:31:95:6C:C7:F3:75:E1 + // X509v3 Authority Key Identifier: + // keyid:B9:7C:D5:D9:DF:A7:4C:03:AE:FD:0E:27:5B:31:95:6C:C7:F3:75:E1 + // DirName:/C=US/O=Java/OU=SunJSSE Test Serivce + // serial:00 + static String NoiceTrusedCertStr_2nd = + "-----BEGIN CERTIFICATE-----\n" + + "MIICkjCCAfugAwIBAgIBADANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" + + "MTEwODE5MDE1MjE5WhcNMzIwNzI5MDE1MjE5WjA7MQswCQYDVQQGEwJVUzENMAsG\n" + + "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwgZ8wDQYJ\n" + + "KoZIhvcNAQEBBQADgY0AMIGJAoGBAM8orG08DtF98TMSscjGsidd1ZoN4jiDpi8U\n" + + "ICz+9dMm1qM1d7O2T+KH3/mxyox7Rc2ZVSCaUD0a3CkhPMnlAx8V4u0H+E9sqso6\n" + + "iDW3JpOyzMExvZiRgRG/3nvp55RMIUV4vEHOZ1QbhuqG4ebN0Vz2DkRft7+flthf\n" + + "vDld6f5JAgMBAAGjgaUwgaIwHQYDVR0OBBYEFLl81dnfp0wDrv0OJ1sxlWzH83Xh\n" + + "MGMGA1UdIwRcMFqAFLl81dnfp0wDrv0OJ1sxlWzH83XhoT+kPTA7MQswCQYDVQQG\n" + + "EwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2\n" + + "Y2WCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEE\n" + + "BQADgYEALlgaH1gWtoBZ84EW8Hu6YtGLQ/L9zIFmHonUPZwn3Pr//icR9Sqhc3/l\n" + + "pVTxOINuFHLRz4BBtEylzRIOPzK3tg8XwuLb1zd0db90x3KBCiAL6E6cklGEPwLe\n" + + "XYMHDn9eDsaq861Tzn6ZwzMgw04zotPMoZN0mVd/3Qca8UJFucE=\n" + + "-----END CERTIFICATE-----"; + + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce + // Validity + // Not Before: May 5 02:40:50 2012 GMT + // Not After : Apr 15 02:40:50 2033 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce + // X509v3 Subject Key Identifier: + // DD:4E:8D:2A:11:C0:83:03:F0:AC:EB:A2:BF:F9:F2:7D:C8:69:1F:9B + // X509v3 Authority Key Identifier: + // keyid:DD:4E:8D:2A:11:C0:83:03:F0:AC:EB:A2:BF:F9:F2:7D:C8:69:1F:9B + // DirName:/C=US/O=Java/OU=SunJSSE Test Serivce + // serial:00 + static String trustedCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICkjCCAfugAwIBAgIBADANBgkqhkiG9w0BAQIFADA7MQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" + + "MTIwNTA1MDI0MDUwWhcNMzMwNDE1MDI0MDUwWjA7MQswCQYDVQQGEwJVUzENMAsG\n" + + "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwgZ8wDQYJ\n" + + "KoZIhvcNAQEBBQADgY0AMIGJAoGBANtiq0AIJK+iVRwFrqcD7fYXTCbMYC5Qz/k6\n" + + "AXBy7/1rI8wDhEJLE3m/+NSqiJwZcmdq2dNh/1fJFrwvzuURbc9+paOBWeHbN+Sc\n" + + "x3huw91oPZme385VpoK3G13rSE114S/rF4DM9mz4EStFhSHXATjtdbskNOAYGLTV\n" + + "x8uEy9GbAgMBAAGjgaUwgaIwHQYDVR0OBBYEFN1OjSoRwIMD8Kzror/58n3IaR+b\n" + + "MGMGA1UdIwRcMFqAFN1OjSoRwIMD8Kzror/58n3IaR+boT+kPTA7MQswCQYDVQQG\n" + + "EwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2\n" + + "Y2WCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEC\n" + + "BQADgYEAjjkJesQrkbr36N40egybaIxw7RcqT6iy5fkAGS1JYlBDk8uSCK1o6bCH\n" + + "ls5EpYcGeEoabSS73WRdkO1lgeyWDduO4ef8cCCSpmpT6/YdZG0QS1PtcREeVig+\n" + + "Zr25jNemS4ADHX0aaXP4kiV/G80cR7nX5t5XCUm4bYdbwM07NgI=\n" + + "-----END CERTIFICATE-----"; + static String trustedPrivateKey = // Private key in the format of PKCS#8 + "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANtiq0AIJK+iVRwF\n" + + "rqcD7fYXTCbMYC5Qz/k6AXBy7/1rI8wDhEJLE3m/+NSqiJwZcmdq2dNh/1fJFrwv\n" + + "zuURbc9+paOBWeHbN+Scx3huw91oPZme385VpoK3G13rSE114S/rF4DM9mz4EStF\n" + + "hSHXATjtdbskNOAYGLTVx8uEy9GbAgMBAAECgYEA2VjHkIiA0ABjkX+PqKeb+VLb\n" + + "fxS7tSca5C8zfdRhLxAWRui0/3ihst0eCJNrBDuxvAOACovsDWyLuaUjtI2v2ysz\n" + + "vz6SPyGy82PhQOFzyKQuQ814N6EpothpiZzF0yFchfKIGhUsdY89UrGs9nM7m6NT\n" + + "rztYvgIu4avg2VPR2AECQQD+pFAqipR2BplQRIuuRSZfHRxvoEyDjT1xnHJsC6WP\n" + + "I5hCLghL91MhQGWbP4EJMKYQOTRVukWlcp2Kycpf+P5hAkEA3I43gmVUAPEdyZdY\n" + + "fatW7OaLlbbYJb6qEtpCZ1Rwe/BIvm6H6E3qSi/lpz7Ia7WDulpbF6BawHH3pRFq\n" + + "CUY5ewJBAP3pUDqrRpBN0jB0uSeDslhjSciQ+dqvSpZv3rSYBHUvlBJhnkpJiy37\n" + + "7ZUZhIxqYxyIPgRBolLwb+FFh7OdL+ECQCtldDic9WVmC+VheRDpCKZ+SlK/8lGi\n" + + "7VXeShiIvcU1JysJFoa35fSI7hf1O3wt7+hX5PqGG7Un94EsJwACKEcCQQC1TWt6\n" + + "ArKH6tRxKjOxFtqfs8fgEVYUaOr3j1jF4KBUuX2mtQtddZe3VfJ2wPsuKMMxmhkB\n" + + "e7xWWZnJsErt2e+E"; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce + // Validity + // Not Before: May 5 02:40:53 2012 GMT + // Not After : Jan 21 02:40:53 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce, CN=casigner + // X509v3 Subject Key Identifier: + // 13:07:E0:11:07:DB:EB:33:23:87:31:D0:DB:7E:16:56:BE:11:90:0A + // X509v3 Authority Key Identifier: + // keyid:DD:4E:8D:2A:11:C0:83:03:F0:AC:EB:A2:BF:F9:F2:7D:C8:69:1F:9B + // DirName:/C=US/O=Java/OU=SunJSSE Test Serivce + // serial:00 + static String caSignerStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICqDCCAhGgAwIBAgIBAjANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" + + "MTIwNTA1MDI0MDUzWhcNMzIwMTIxMDI0MDUzWjBOMQswCQYDVQQGEwJVUzENMAsG\n" + + "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxETAPBgNV\n" + + "BAMTCGNhc2lnbmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+x8+o7oM0\n" + + "ct/LZmZLXBL4CQ8jrULD5P7NtEW0hg/zxBFZfBHf+44Oo2eMPYZj+7xaREOH5BmV\n" + + "KRYlzRtONAaC5Ng4Mrm5UKNPcMIIUjUOvm7vWM4oSTMSfoEcSX+vp99uUAkw3w7Z\n" + + "+frYDm1M4At/j0b+lLij71GFN2L8drpgPQIDAQABo4GoMIGlMB0GA1UdDgQWBBQT\n" + + "B+ARB9vrMyOHMdDbfhZWvhGQCjBjBgNVHSMEXDBagBTdTo0qEcCDA/Cs66K/+fJ9\n" + + "yGkfm6E/pD0wOzELMAkGA1UEBhMCVVMxDTALBgNVBAoTBEphdmExHTAbBgNVBAsT\n" + + "FFN1bkpTU0UgVGVzdCBTZXJpdmNlggEAMBIGA1UdEwEB/wQIMAYBAf8CAQEwCwYD\n" + + "VR0PBAQDAgEGMA0GCSqGSIb3DQEBBAUAA4GBAI+LXA/UCPkTANablUkt80JNPWsl\n" + + "pS4XLNgPxWaN0bkRDs5oI4ooWAz1rwpeJ/nfetOvWlpmrVjSeovBFja5Hl+dUHTf\n" + + "VfuyzkxXbhuNiJIpo1mVBpNsjwu9YRxuwX6UA2LTUQpgvtVJEE012x3zRvxBCbu2\n" + + "Y/v1R5fZ4c+hXDfC\n" + + "-----END CERTIFICATE-----"; + static String caSignerPrivateKey = // Private key in the format of PKCS#8 + "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL7Hz6jugzRy38tm\n" + + "ZktcEvgJDyOtQsPk/s20RbSGD/PEEVl8Ed/7jg6jZ4w9hmP7vFpEQ4fkGZUpFiXN\n" + + "G040BoLk2DgyublQo09wwghSNQ6+bu9YzihJMxJ+gRxJf6+n325QCTDfDtn5+tgO\n" + + "bUzgC3+PRv6UuKPvUYU3Yvx2umA9AgMBAAECgYBYvu30cW8LONyt62Zua9hPFTe7\n" + + "qt9B7QYyfkdmoG5PQMepTrOp84SzfoOukvgvDm0huFuJnSvhXQl2cCDhkgXskvFj\n" + + "Hh7KBCFViVXokGdq5YoS0/KYMyQV0TZfJUvILBl51uc4/siQ2tClC/N4sa+1JhgW\n" + + "a6dFGfRjiUKSSlmMwQJBAPWpIz3Q/c+DYMvoQr5OD8EaYwYIevlTdXb97RnJJh2b\n" + + "UnhB9jrqesJiHYVzPmP0ukyPOXOwlp2T5Am4Kw0LFOkCQQDGz150NoHOp28Mvyc4\n" + + "CTqz/zYzUhy2eCJESl196uyP4N65Y01VYQ3JDww4DlsXiU17tVSbgA9TCcfTYOzy\n" + + "vyw1AkARUky+1hafZCcWGZljK8PmnMKwsTZikCTvL/Zg5BMA8Wu+OQBwpQnk3OAy\n" + + "Aa87gw0DyvGFG8Vy9POWT9sRP1/JAkBqP0hrMvYMSs6+MSn0eHo2151PsAJIQcuO\n" + + "U2/Da1khSzu8N6WMi2GiobgV/RYRbf9KrY2ZzMZjykZQYOxAjopBAkEAghCu38cN\n" + + "aOsW6ueo24uzsWI1FTdE+qWNVEi3RSP120xXBCyhaBjIq4WVSlJK9K2aBaJpit3j\n" + + "iQ5tl6zrLlxQhg=="; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce, CN=casigner + // Validity + // Not Before: May 5 02:40:57 2012 GMT + // Not After : Jan 21 02:40:57 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce, CN=certissuer + // X509v3 Subject Key Identifier: + // 39:0E:C6:33:B1:50:BC:73:07:31:E5:D8:04:F7:BB:97:55:CF:9B:C8 + // X509v3 Authority Key Identifier: + // keyid:13:07:E0:11:07:DB:EB:33:23:87:31:D0:DB:7E:16:56:BE:11:90:0A + // DirName:/C=US/O=Java/OU=SunJSSE Test Serivce + // serial:02 + static String certIssuerStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICvjCCAiegAwIBAgIBAzANBgkqhkiG9w0BAQQFADBOMQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxETAP\n" + + "BgNVBAMTCGNhc2lnbmVyMB4XDTEyMDUwNTAyNDA1N1oXDTMyMDEyMTAyNDA1N1ow\n" + + "UDELMAkGA1UEBhMCVVMxDTALBgNVBAoTBEphdmExHTAbBgNVBAsTFFN1bkpTU0Ug\n" + + "VGVzdCBTZXJpdmNlMRMwEQYDVQQDEwpjZXJ0aXNzdWVyMIGfMA0GCSqGSIb3DQEB\n" + + "AQUAA4GNADCBiQKBgQCyz55zinU6kNL/LeiTNiBI0QWYmDG0YTotuC4D75liBNqs\n" + + "7Mmladsh2mTtQUAwmuGaGzaZV25a+cUax0DXZoyBwdbTI09u1bUYsZcaUUKbPoCC\n" + + "HH26e4jLFL4olW13Sv4ZAd57tIYevMw+Fp5f4fLPFGegCJTFlv2Qjpmic/cuvQID\n" + + "AQABo4GpMIGmMB0GA1UdDgQWBBQ5DsYzsVC8cwcx5dgE97uXVc+byDBjBgNVHSME\n" + + "XDBagBQTB+ARB9vrMyOHMdDbfhZWvhGQCqE/pD0wOzELMAkGA1UEBhMCVVMxDTAL\n" + + "BgNVBAoTBEphdmExHTAbBgNVBAsTFFN1bkpTU0UgVGVzdCBTZXJpdmNlggECMBMG\n" + + "A1UdEwEB/wQJMAcBAf8CAgQAMAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQQFAAOB\n" + + "gQCQTagenCdClT98C+oTJGJrw/dUBD9K3tE6ZJKPMc/2bUia8G5ei1C0eXj4mWG2\n" + + "lu9umR6C90/A6qB050QB2h50qtqxSrkpu+ym1yypauZpg7U3nUY9wZWJNI1vqrQZ\n" + + "pqUMRcXY3iQIVKx+Qj+4/Za1wwFQzpEoGmqRW31V1SdMEw==\n" + + "-----END CERTIFICATE-----"; + static String certIssuerPrivateKey = // Private key in the format of PKCS#8 + "MIICeQIBADANBgkqhkiG9w0BAQEFAASCAmMwggJfAgEAAoGBALLPnnOKdTqQ0v8t\n" + + "6JM2IEjRBZiYMbRhOi24LgPvmWIE2qzsyaVp2yHaZO1BQDCa4ZobNplXblr5xRrH\n" + + "QNdmjIHB1tMjT27VtRixlxpRQps+gIIcfbp7iMsUviiVbXdK/hkB3nu0hh68zD4W\n" + + "nl/h8s8UZ6AIlMWW/ZCOmaJz9y69AgMBAAECgYEAjtew2tgm4gxDojqIauF4VPM1\n" + + "pzsdqd1p3pAdomNLgrQiBLZ8N7oiph6TNb1EjA+OXc+ThFgF/oM9ZDD8qZZwcvjN\n" + + "qDZlpTkFs2TaGcyEZfUaMB45NHVs6Nn+pSkagSNwwy3xeyAct7sQEzGNTDlEwVv5\n" + + "7V9LQutQtBd6xT48KzkCQQDpNRfv2OFNG/6GtzJoO68oJhpnpl2MsYNi4ntRkre/\n" + + "6uXpiCYaDskcrPMRwOOs0m7mxG+Ev+uKnLnSoEMm1GCbAkEAxEmDtiD0Psb8Z9BL\n" + + "ZRb83Jqho3xe2MCAh3xUfz9b/Mhae9dZ44o4OCgQZuwvW1mczF0NtpgZl93BmYa2\n" + + "hTwHhwJBAKHrEj6ep/fA6x0gD2idoATRR94VfbiU+7NpqtO9ecVP0+gsdr/66hn1\n" + + "3yLBeZLh3MxvMTrLgkAQh1i9m0JXjOcCQQClLXAHHegrw+u3uNMZeKTFR+Lp3sk6\n" + + "AZSnbvr0Me9I45kxSeG81x3ENALJecvIRbrrRws5MvmmkNhQR8rkh8WVAkEAk6b+\n" + + "aVtmBgUaTS5+FFlHGHJY9HFrfT1a1C/dwyMuqlmbC3YsBmZaMOlKli5TXNybLff8\n" + + "5KMeGEpXMzgC7AscGA=="; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce, CN=certissuer + // Validity + // Not Before: May 5 02:41:01 2012 GMT + // Not After : Jan 21 02:41:01 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce, CN=localhost + // X509v3 Subject Key Identifier: + // AD:C0:2C:4C:E4:C2:2E:A1:BB:5D:92:BE:66:E0:4E:E0:0D:2F:11:EF + // X509v3 Authority Key Identifier: + // keyid:39:0E:C6:33:B1:50:BC:73:07:31:E5:D8:04:F7:BB:97:55:CF:9B:C8 + static String targetCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICjTCCAfagAwIBAgIBBDANBgkqhkiG9w0BAQQFADBQMQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxEzAR\n" + + "BgNVBAMTCmNlcnRpc3N1ZXIwHhcNMTIwNTA1MDI0MTAxWhcNMzIwMTIxMDI0MTAx\n" + + "WjBPMQswCQYDVQQGEwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNT\n" + + "RSBUZXN0IFNlcml2Y2UxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0B\n" + + "AQEFAAOBjQAwgYkCgYEAvwaUd7wmBSKqycEstYLWD26vkU08DM39EtaT8wL9HnQ0\n" + + "fgPblwBFI4zdLa2cuYXRZcFUb04N8nrkcpR0D6kkE+AlFAoRWrrZF80B7JTbtEK4\n" + + "1PIeurihXvUT+4MpzGLOojIihMfvM4ufelblD56SInso4WFHm7t4qCln88J1gjkC\n" + + "AwEAAaN4MHYwCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBStwCxM5MIuobtdkr5m4E7g\n" + + "DS8R7zAfBgNVHSMEGDAWgBQ5DsYzsVC8cwcx5dgE97uXVc+byDAnBgNVHSUEIDAe\n" + + "BggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDMA0GCSqGSIb3DQEBBAUAA4GB\n" + + "AGfwcfdvEG/nSCiAn2MGbYHp34mgF3OA1SJLWUW0LvWJhwm2cn4AXlSoyvbwrkaB\n" + + "IDDCwhJvvc0vUyL2kTx7sqVaFTq3mDs+ktlB/FfH0Pb+i8FE+g+7T42Iw/j0qxHL\n" + + "YmgbrjBQf5WYN1AvBE/rrPt9aOtS3UsqtVGW574b0shW\n" + + "-----END CERTIFICATE-----"; + static String targetPrivateKey = // Private key in the format of PKCS#8 + "MIICdAIBADANBgkqhkiG9w0BAQEFAASCAl4wggJaAgEAAoGBAL8GlHe8JgUiqsnB\n" + + "LLWC1g9ur5FNPAzN/RLWk/MC/R50NH4D25cARSOM3S2tnLmF0WXBVG9ODfJ65HKU\n" + + "dA+pJBPgJRQKEVq62RfNAeyU27RCuNTyHrq4oV71E/uDKcxizqIyIoTH7zOLn3pW\n" + + "5Q+ekiJ7KOFhR5u7eKgpZ/PCdYI5AgMBAAECf3CscOYvFD3zNMnMJ5LomVqA7w3F\n" + + "gKYM2jlCWAH+wU41PMEXhW6Lujw92jgXL1o+lERwxFzirVdZJWZwKgUSvzP1G0h3\n" + + "fkucq1/UWnToK+8NSXNM/yS8hXbBgSEoJo5f7LKcIi1Ev6doBVofMxs+njzyWKbM\n" + + "Nb7rOLHadghoon0CQQDgQzbzzSN8Dc1YmmylhI5v+0sQRHH0DL7D24k4Weh4vInG\n" + + "EAbt4x8M7ZKEo8/dv0s4hbmNmAnJl93/RRxIyEqLAkEA2g87DiswSQam2pZ8GlrO\n" + + "+w4Qg9mH8uxx8ou2rl0XlHzH1XiTNbkjfY0EZoL7L31BHFk9n11Fb2P85g6ws+Hy\n" + + "ywJAM/xgyLNM/nzUlS128geAXUULaYH0SHaL4isJ7B4rXZGW/mrIsGxtzjlkNYsj\n" + + "rGujrD6TfNc5rZmexIXowJZtcQJBAIww+pCzZ4mrgx5JXWQ8OZHiiu+ZrPOa2+9J\n" + + "r5sOMpi+WGN/73S8oHqZbNjTINZ5OqEVJq8MchWZPQBTNXuQql0CQHEjUzzkCQa3\n" + + "j6JTa2KAdqyvLOx0XF9zcc1gA069uNQI2gPUHS8V215z57f/gMGnDNhVfLs/vMKz\n" + + "sFkVZ3zg7As="; + + + public static void main(String args[]) throws Exception { + + // generate certificate from cert string + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + // create a set of trust anchors + LinkedHashSet trustAnchors = new LinkedHashSet<>(); + + ByteArrayInputStream is = + new ByteArrayInputStream(NoiceTrusedCertStr.getBytes()); + Certificate trustedCert = cf.generateCertificate(is); + is.close(); + TrustAnchor anchor = + new TrustAnchor((X509Certificate)trustedCert, null); + trustAnchors.add(anchor); + + is = new ByteArrayInputStream(trustedCertStr.getBytes()); + trustedCert = cf.generateCertificate(is); + is.close(); + anchor = new TrustAnchor((X509Certificate)trustedCert, null); + trustAnchors.add(anchor); + + is = new ByteArrayInputStream(NoiceTrusedCertStr_2nd.getBytes()); + trustedCert = cf.generateCertificate(is); + is.close(); + anchor = new TrustAnchor((X509Certificate)trustedCert, null); + trustAnchors.add(anchor); + + // create a list of certificates + List chainList = new ArrayList<>(); + + is = new ByteArrayInputStream(targetCertStr.getBytes()); + Certificate cert = cf.generateCertificate(is); + is.close(); + chainList.add(cert); + + is = new ByteArrayInputStream(certIssuerStr.getBytes()); + cert = cf.generateCertificate(is); + is.close(); + chainList.add(cert); + + is = new ByteArrayInputStream(caSignerStr.getBytes()); + cert = cf.generateCertificate(is); + is.close(); + chainList.add(cert); + + // create a certificate selector + X509CertSelector xcs = new X509CertSelector(); + X509Certificate eeCert = (X509Certificate)chainList.get(0); + xcs.setSubject(eeCert.getSubjectX500Principal()); + + // reverse build + SunCertPathBuilderParameters params = + new SunCertPathBuilderParameters(trustAnchors, xcs); + params.setBuildForward(false); + params.setRevocationEnabled(false); + + CollectionCertStoreParameters ccsp = + new CollectionCertStoreParameters(chainList); + params.addCertStore(CertStore.getInstance("Collection", ccsp)); + + CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX"); + CertPathBuilderResult res = cpb.build(params); + } +} diff --git a/jdk/test/sun/security/rsa/TestKeyPairGenerator.java b/jdk/test/sun/security/rsa/TestKeyPairGenerator.java index 88ab075bced..5e661b08ef1 100644 --- a/jdk/test/sun/security/rsa/TestKeyPairGenerator.java +++ b/jdk/test/sun/security/rsa/TestKeyPairGenerator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -23,7 +23,7 @@ /** * @test - * @bug 4853305 4865198 4888410 + * @bug 4853305 4865198 4888410 4963723 * @summary Verify that the RSA KeyPairGenerator works * @author Andreas Sterbenz */ @@ -60,6 +60,7 @@ public class TestKeyPairGenerator { testSignature("MD2withRSA", privateKey, publicKey); testSignature("MD5withRSA", privateKey, publicKey); testSignature("SHA1withRSA", privateKey, publicKey); + testSignature("SHA224withRSA", privateKey, publicKey); testSignature("SHA256withRSA", privateKey, publicKey); RSAPublicKey rsaKey = (RSAPublicKey)publicKey; if (rsaKey.getModulus().bitLength() > 512) { diff --git a/jdk/test/sun/security/rsa/TestSignatures.java b/jdk/test/sun/security/rsa/TestSignatures.java index 2293077dd20..1933f264295 100644 --- a/jdk/test/sun/security/rsa/TestSignatures.java +++ b/jdk/test/sun/security/rsa/TestSignatures.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2012, 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 @@ -23,7 +23,7 @@ /** * @test - * @bug 4853305 + * @bug 4853305 4963723 * @summary Test signing/verifying using all the signature algorithms * @author Andreas Sterbenz */ @@ -80,6 +80,7 @@ public class TestSignatures { testSignature("MD2withRSA", privateKey, publicKey); testSignature("MD5withRSA", privateKey, publicKey); testSignature("SHA1withRSA", privateKey, publicKey); + testSignature("SHA224withRSA", privateKey, publicKey); testSignature("SHA256withRSA", privateKey, publicKey); RSAPublicKey rsaKey = (RSAPublicKey)publicKey; if (rsaKey.getModulus().bitLength() > 512) { diff --git a/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/X509TrustManagerImpl/BasicConstraints.java b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/X509TrustManagerImpl/BasicConstraints.java new file mode 100644 index 00000000000..1756ba0cacd --- /dev/null +++ b/jdk/test/sun/security/ssl/com/sun/net/ssl/internal/ssl/X509TrustManagerImpl/BasicConstraints.java @@ -0,0 +1,555 @@ +/* + * Copyright (c) 2012, 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 7166570 + * @summary JSSE certificate validation has started to fail for + * certificate chains + * + * SunJSSE does not support dynamic system properties, no way to re-use + * system properties in samevm/agentvm mode. + * @run main/othervm BasicConstraints PKIX + * @run main/othervm BasicConstraints SunX509 + */ + +import java.net.*; +import java.util.*; +import java.io.*; +import javax.net.ssl.*; +import java.security.KeyStore; +import java.security.KeyFactory; +import java.security.cert.*; +import java.security.spec.*; +import java.security.interfaces.*; +import java.math.BigInteger; + +import sun.misc.BASE64Decoder; + +public class BasicConstraints { + + /* + * ============================================================= + * Set the various variables needed for the tests, then + * specify what tests to run on each side. + */ + + /* + * Should we run the client or server in a separate thread? + * Both sides can throw exceptions, but do you have a preference + * as to which side should be the main thread. + */ + static boolean separateServerThread = true; + + /* + * Where do we find the keystores? + */ + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce + // Validity + // Not Before: May 5 02:40:50 2012 GMT + // Not After : Apr 15 02:40:50 2033 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce + // X509v3 Subject Key Identifier: + // DD:4E:8D:2A:11:C0:83:03:F0:AC:EB:A2:BF:F9:F2:7D:C8:69:1F:9B + // X509v3 Authority Key Identifier: + // keyid:DD:4E:8D:2A:11:C0:83:03:F0:AC:EB:A2:BF:F9:F2:7D:C8:69:1F:9B + // DirName:/C=US/O=Java/OU=SunJSSE Test Serivce + // serial:00 + static String trusedCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICkjCCAfugAwIBAgIBADANBgkqhkiG9w0BAQIFADA7MQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" + + "MTIwNTA1MDI0MDUwWhcNMzMwNDE1MDI0MDUwWjA7MQswCQYDVQQGEwJVUzENMAsG\n" + + "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwgZ8wDQYJ\n" + + "KoZIhvcNAQEBBQADgY0AMIGJAoGBANtiq0AIJK+iVRwFrqcD7fYXTCbMYC5Qz/k6\n" + + "AXBy7/1rI8wDhEJLE3m/+NSqiJwZcmdq2dNh/1fJFrwvzuURbc9+paOBWeHbN+Sc\n" + + "x3huw91oPZme385VpoK3G13rSE114S/rF4DM9mz4EStFhSHXATjtdbskNOAYGLTV\n" + + "x8uEy9GbAgMBAAGjgaUwgaIwHQYDVR0OBBYEFN1OjSoRwIMD8Kzror/58n3IaR+b\n" + + "MGMGA1UdIwRcMFqAFN1OjSoRwIMD8Kzror/58n3IaR+boT+kPTA7MQswCQYDVQQG\n" + + "EwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2\n" + + "Y2WCAQAwDwYDVR0TAQH/BAUwAwEB/zALBgNVHQ8EBAMCAQYwDQYJKoZIhvcNAQEC\n" + + "BQADgYEAjjkJesQrkbr36N40egybaIxw7RcqT6iy5fkAGS1JYlBDk8uSCK1o6bCH\n" + + "ls5EpYcGeEoabSS73WRdkO1lgeyWDduO4ef8cCCSpmpT6/YdZG0QS1PtcREeVig+\n" + + "Zr25jNemS4ADHX0aaXP4kiV/G80cR7nX5t5XCUm4bYdbwM07NgI=\n" + + "-----END CERTIFICATE-----"; + static String trustedPrivateKey = // Private key in the format of PKCS#8 + "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANtiq0AIJK+iVRwF\n" + + "rqcD7fYXTCbMYC5Qz/k6AXBy7/1rI8wDhEJLE3m/+NSqiJwZcmdq2dNh/1fJFrwv\n" + + "zuURbc9+paOBWeHbN+Scx3huw91oPZme385VpoK3G13rSE114S/rF4DM9mz4EStF\n" + + "hSHXATjtdbskNOAYGLTVx8uEy9GbAgMBAAECgYEA2VjHkIiA0ABjkX+PqKeb+VLb\n" + + "fxS7tSca5C8zfdRhLxAWRui0/3ihst0eCJNrBDuxvAOACovsDWyLuaUjtI2v2ysz\n" + + "vz6SPyGy82PhQOFzyKQuQ814N6EpothpiZzF0yFchfKIGhUsdY89UrGs9nM7m6NT\n" + + "rztYvgIu4avg2VPR2AECQQD+pFAqipR2BplQRIuuRSZfHRxvoEyDjT1xnHJsC6WP\n" + + "I5hCLghL91MhQGWbP4EJMKYQOTRVukWlcp2Kycpf+P5hAkEA3I43gmVUAPEdyZdY\n" + + "fatW7OaLlbbYJb6qEtpCZ1Rwe/BIvm6H6E3qSi/lpz7Ia7WDulpbF6BawHH3pRFq\n" + + "CUY5ewJBAP3pUDqrRpBN0jB0uSeDslhjSciQ+dqvSpZv3rSYBHUvlBJhnkpJiy37\n" + + "7ZUZhIxqYxyIPgRBolLwb+FFh7OdL+ECQCtldDic9WVmC+VheRDpCKZ+SlK/8lGi\n" + + "7VXeShiIvcU1JysJFoa35fSI7hf1O3wt7+hX5PqGG7Un94EsJwACKEcCQQC1TWt6\n" + + "ArKH6tRxKjOxFtqfs8fgEVYUaOr3j1jF4KBUuX2mtQtddZe3VfJ2wPsuKMMxmhkB\n" + + "e7xWWZnJsErt2e+E"; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce + // Validity + // Not Before: May 5 02:40:53 2012 GMT + // Not After : Jan 21 02:40:53 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce, CN=casigner + // X509v3 Subject Key Identifier: + // 13:07:E0:11:07:DB:EB:33:23:87:31:D0:DB:7E:16:56:BE:11:90:0A + // X509v3 Authority Key Identifier: + // keyid:DD:4E:8D:2A:11:C0:83:03:F0:AC:EB:A2:BF:F9:F2:7D:C8:69:1F:9B + // DirName:/C=US/O=Java/OU=SunJSSE Test Serivce + // serial:00 + static String caSignerStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICqDCCAhGgAwIBAgIBAjANBgkqhkiG9w0BAQQFADA7MQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UwHhcN\n" + + "MTIwNTA1MDI0MDUzWhcNMzIwMTIxMDI0MDUzWjBOMQswCQYDVQQGEwJVUzENMAsG\n" + + "A1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxETAPBgNV\n" + + "BAMTCGNhc2lnbmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+x8+o7oM0\n" + + "ct/LZmZLXBL4CQ8jrULD5P7NtEW0hg/zxBFZfBHf+44Oo2eMPYZj+7xaREOH5BmV\n" + + "KRYlzRtONAaC5Ng4Mrm5UKNPcMIIUjUOvm7vWM4oSTMSfoEcSX+vp99uUAkw3w7Z\n" + + "+frYDm1M4At/j0b+lLij71GFN2L8drpgPQIDAQABo4GoMIGlMB0GA1UdDgQWBBQT\n" + + "B+ARB9vrMyOHMdDbfhZWvhGQCjBjBgNVHSMEXDBagBTdTo0qEcCDA/Cs66K/+fJ9\n" + + "yGkfm6E/pD0wOzELMAkGA1UEBhMCVVMxDTALBgNVBAoTBEphdmExHTAbBgNVBAsT\n" + + "FFN1bkpTU0UgVGVzdCBTZXJpdmNlggEAMBIGA1UdEwEB/wQIMAYBAf8CAQEwCwYD\n" + + "VR0PBAQDAgEGMA0GCSqGSIb3DQEBBAUAA4GBAI+LXA/UCPkTANablUkt80JNPWsl\n" + + "pS4XLNgPxWaN0bkRDs5oI4ooWAz1rwpeJ/nfetOvWlpmrVjSeovBFja5Hl+dUHTf\n" + + "VfuyzkxXbhuNiJIpo1mVBpNsjwu9YRxuwX6UA2LTUQpgvtVJEE012x3zRvxBCbu2\n" + + "Y/v1R5fZ4c+hXDfC\n" + + "-----END CERTIFICATE-----"; + static String caSignerPrivateKey = // Private key in the format of PKCS#8 + "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL7Hz6jugzRy38tm\n" + + "ZktcEvgJDyOtQsPk/s20RbSGD/PEEVl8Ed/7jg6jZ4w9hmP7vFpEQ4fkGZUpFiXN\n" + + "G040BoLk2DgyublQo09wwghSNQ6+bu9YzihJMxJ+gRxJf6+n325QCTDfDtn5+tgO\n" + + "bUzgC3+PRv6UuKPvUYU3Yvx2umA9AgMBAAECgYBYvu30cW8LONyt62Zua9hPFTe7\n" + + "qt9B7QYyfkdmoG5PQMepTrOp84SzfoOukvgvDm0huFuJnSvhXQl2cCDhkgXskvFj\n" + + "Hh7KBCFViVXokGdq5YoS0/KYMyQV0TZfJUvILBl51uc4/siQ2tClC/N4sa+1JhgW\n" + + "a6dFGfRjiUKSSlmMwQJBAPWpIz3Q/c+DYMvoQr5OD8EaYwYIevlTdXb97RnJJh2b\n" + + "UnhB9jrqesJiHYVzPmP0ukyPOXOwlp2T5Am4Kw0LFOkCQQDGz150NoHOp28Mvyc4\n" + + "CTqz/zYzUhy2eCJESl196uyP4N65Y01VYQ3JDww4DlsXiU17tVSbgA9TCcfTYOzy\n" + + "vyw1AkARUky+1hafZCcWGZljK8PmnMKwsTZikCTvL/Zg5BMA8Wu+OQBwpQnk3OAy\n" + + "Aa87gw0DyvGFG8Vy9POWT9sRP1/JAkBqP0hrMvYMSs6+MSn0eHo2151PsAJIQcuO\n" + + "U2/Da1khSzu8N6WMi2GiobgV/RYRbf9KrY2ZzMZjykZQYOxAjopBAkEAghCu38cN\n" + + "aOsW6ueo24uzsWI1FTdE+qWNVEi3RSP120xXBCyhaBjIq4WVSlJK9K2aBaJpit3j\n" + + "iQ5tl6zrLlxQhg=="; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce, CN=casigner + // Validity + // Not Before: May 5 02:40:57 2012 GMT + // Not After : Jan 21 02:40:57 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce, CN=certissuer + // X509v3 Subject Key Identifier: + // 39:0E:C6:33:B1:50:BC:73:07:31:E5:D8:04:F7:BB:97:55:CF:9B:C8 + // X509v3 Authority Key Identifier: + // keyid:13:07:E0:11:07:DB:EB:33:23:87:31:D0:DB:7E:16:56:BE:11:90:0A + // DirName:/C=US/O=Java/OU=SunJSSE Test Serivce + // serial:02 + static String certIssuerStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICvjCCAiegAwIBAgIBAzANBgkqhkiG9w0BAQQFADBOMQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxETAP\n" + + "BgNVBAMTCGNhc2lnbmVyMB4XDTEyMDUwNTAyNDA1N1oXDTMyMDEyMTAyNDA1N1ow\n" + + "UDELMAkGA1UEBhMCVVMxDTALBgNVBAoTBEphdmExHTAbBgNVBAsTFFN1bkpTU0Ug\n" + + "VGVzdCBTZXJpdmNlMRMwEQYDVQQDEwpjZXJ0aXNzdWVyMIGfMA0GCSqGSIb3DQEB\n" + + "AQUAA4GNADCBiQKBgQCyz55zinU6kNL/LeiTNiBI0QWYmDG0YTotuC4D75liBNqs\n" + + "7Mmladsh2mTtQUAwmuGaGzaZV25a+cUax0DXZoyBwdbTI09u1bUYsZcaUUKbPoCC\n" + + "HH26e4jLFL4olW13Sv4ZAd57tIYevMw+Fp5f4fLPFGegCJTFlv2Qjpmic/cuvQID\n" + + "AQABo4GpMIGmMB0GA1UdDgQWBBQ5DsYzsVC8cwcx5dgE97uXVc+byDBjBgNVHSME\n" + + "XDBagBQTB+ARB9vrMyOHMdDbfhZWvhGQCqE/pD0wOzELMAkGA1UEBhMCVVMxDTAL\n" + + "BgNVBAoTBEphdmExHTAbBgNVBAsTFFN1bkpTU0UgVGVzdCBTZXJpdmNlggECMBMG\n" + + "A1UdEwEB/wQJMAcBAf8CAgQAMAsGA1UdDwQEAwIBBjANBgkqhkiG9w0BAQQFAAOB\n" + + "gQCQTagenCdClT98C+oTJGJrw/dUBD9K3tE6ZJKPMc/2bUia8G5ei1C0eXj4mWG2\n" + + "lu9umR6C90/A6qB050QB2h50qtqxSrkpu+ym1yypauZpg7U3nUY9wZWJNI1vqrQZ\n" + + "pqUMRcXY3iQIVKx+Qj+4/Za1wwFQzpEoGmqRW31V1SdMEw==\n" + + "-----END CERTIFICATE-----"; + static String certIssuerPrivateKey = // Private key in the format of PKCS#8 + "MIICeQIBADANBgkqhkiG9w0BAQEFAASCAmMwggJfAgEAAoGBALLPnnOKdTqQ0v8t\n" + + "6JM2IEjRBZiYMbRhOi24LgPvmWIE2qzsyaVp2yHaZO1BQDCa4ZobNplXblr5xRrH\n" + + "QNdmjIHB1tMjT27VtRixlxpRQps+gIIcfbp7iMsUviiVbXdK/hkB3nu0hh68zD4W\n" + + "nl/h8s8UZ6AIlMWW/ZCOmaJz9y69AgMBAAECgYEAjtew2tgm4gxDojqIauF4VPM1\n" + + "pzsdqd1p3pAdomNLgrQiBLZ8N7oiph6TNb1EjA+OXc+ThFgF/oM9ZDD8qZZwcvjN\n" + + "qDZlpTkFs2TaGcyEZfUaMB45NHVs6Nn+pSkagSNwwy3xeyAct7sQEzGNTDlEwVv5\n" + + "7V9LQutQtBd6xT48KzkCQQDpNRfv2OFNG/6GtzJoO68oJhpnpl2MsYNi4ntRkre/\n" + + "6uXpiCYaDskcrPMRwOOs0m7mxG+Ev+uKnLnSoEMm1GCbAkEAxEmDtiD0Psb8Z9BL\n" + + "ZRb83Jqho3xe2MCAh3xUfz9b/Mhae9dZ44o4OCgQZuwvW1mczF0NtpgZl93BmYa2\n" + + "hTwHhwJBAKHrEj6ep/fA6x0gD2idoATRR94VfbiU+7NpqtO9ecVP0+gsdr/66hn1\n" + + "3yLBeZLh3MxvMTrLgkAQh1i9m0JXjOcCQQClLXAHHegrw+u3uNMZeKTFR+Lp3sk6\n" + + "AZSnbvr0Me9I45kxSeG81x3ENALJecvIRbrrRws5MvmmkNhQR8rkh8WVAkEAk6b+\n" + + "aVtmBgUaTS5+FFlHGHJY9HFrfT1a1C/dwyMuqlmbC3YsBmZaMOlKli5TXNybLff8\n" + + "5KMeGEpXMzgC7AscGA=="; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce, CN=certissuer + // Validity + // Not Before: May 5 02:41:01 2012 GMT + // Not After : Jan 21 02:41:01 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce, CN=localhost + // X509v3 Subject Key Identifier: + // AD:C0:2C:4C:E4:C2:2E:A1:BB:5D:92:BE:66:E0:4E:E0:0D:2F:11:EF + // X509v3 Authority Key Identifier: + // keyid:39:0E:C6:33:B1:50:BC:73:07:31:E5:D8:04:F7:BB:97:55:CF:9B:C8 + static String serverCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICjTCCAfagAwIBAgIBBDANBgkqhkiG9w0BAQQFADBQMQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxEzAR\n" + + "BgNVBAMTCmNlcnRpc3N1ZXIwHhcNMTIwNTA1MDI0MTAxWhcNMzIwMTIxMDI0MTAx\n" + + "WjBPMQswCQYDVQQGEwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNT\n" + + "RSBUZXN0IFNlcml2Y2UxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG9w0B\n" + + "AQEFAAOBjQAwgYkCgYEAvwaUd7wmBSKqycEstYLWD26vkU08DM39EtaT8wL9HnQ0\n" + + "fgPblwBFI4zdLa2cuYXRZcFUb04N8nrkcpR0D6kkE+AlFAoRWrrZF80B7JTbtEK4\n" + + "1PIeurihXvUT+4MpzGLOojIihMfvM4ufelblD56SInso4WFHm7t4qCln88J1gjkC\n" + + "AwEAAaN4MHYwCwYDVR0PBAQDAgPoMB0GA1UdDgQWBBStwCxM5MIuobtdkr5m4E7g\n" + + "DS8R7zAfBgNVHSMEGDAWgBQ5DsYzsVC8cwcx5dgE97uXVc+byDAnBgNVHSUEIDAe\n" + + "BggrBgEFBQcDAQYIKwYBBQUHAwIGCCsGAQUFBwMDMA0GCSqGSIb3DQEBBAUAA4GB\n" + + "AGfwcfdvEG/nSCiAn2MGbYHp34mgF3OA1SJLWUW0LvWJhwm2cn4AXlSoyvbwrkaB\n" + + "IDDCwhJvvc0vUyL2kTx7sqVaFTq3mDs+ktlB/FfH0Pb+i8FE+g+7T42Iw/j0qxHL\n" + + "YmgbrjBQf5WYN1AvBE/rrPt9aOtS3UsqtVGW574b0shW\n" + + "-----END CERTIFICATE-----"; + static String serverPrivateKey = // Private key in the format of PKCS#8 + "MIICdAIBADANBgkqhkiG9w0BAQEFAASCAl4wggJaAgEAAoGBAL8GlHe8JgUiqsnB\n" + + "LLWC1g9ur5FNPAzN/RLWk/MC/R50NH4D25cARSOM3S2tnLmF0WXBVG9ODfJ65HKU\n" + + "dA+pJBPgJRQKEVq62RfNAeyU27RCuNTyHrq4oV71E/uDKcxizqIyIoTH7zOLn3pW\n" + + "5Q+ekiJ7KOFhR5u7eKgpZ/PCdYI5AgMBAAECf3CscOYvFD3zNMnMJ5LomVqA7w3F\n" + + "gKYM2jlCWAH+wU41PMEXhW6Lujw92jgXL1o+lERwxFzirVdZJWZwKgUSvzP1G0h3\n" + + "fkucq1/UWnToK+8NSXNM/yS8hXbBgSEoJo5f7LKcIi1Ev6doBVofMxs+njzyWKbM\n" + + "Nb7rOLHadghoon0CQQDgQzbzzSN8Dc1YmmylhI5v+0sQRHH0DL7D24k4Weh4vInG\n" + + "EAbt4x8M7ZKEo8/dv0s4hbmNmAnJl93/RRxIyEqLAkEA2g87DiswSQam2pZ8GlrO\n" + + "+w4Qg9mH8uxx8ou2rl0XlHzH1XiTNbkjfY0EZoL7L31BHFk9n11Fb2P85g6ws+Hy\n" + + "ywJAM/xgyLNM/nzUlS128geAXUULaYH0SHaL4isJ7B4rXZGW/mrIsGxtzjlkNYsj\n" + + "rGujrD6TfNc5rZmexIXowJZtcQJBAIww+pCzZ4mrgx5JXWQ8OZHiiu+ZrPOa2+9J\n" + + "r5sOMpi+WGN/73S8oHqZbNjTINZ5OqEVJq8MchWZPQBTNXuQql0CQHEjUzzkCQa3\n" + + "j6JTa2KAdqyvLOx0XF9zcc1gA069uNQI2gPUHS8V215z57f/gMGnDNhVfLs/vMKz\n" + + "sFkVZ3zg7As="; + + // Certificate information: + // Issuer: C=US, O=Java, OU=SunJSSE Test Serivce, CN=certissuer + // Validity + // Not Before: May 5 02:41:02 2012 GMT + // Not After : Jan 21 02:41:02 2032 GMT + // Subject: C=US, O=Java, OU=SunJSSE Test Serivce, CN=InterOp Tester + // X509v3 Subject Key Identifier: + // 57:7D:E2:33:33:60:DF:DD:5E:ED:81:3F:EB:F2:1B:59:7F:50:9C:99 + // X509v3 Authority Key Identifier: + // keyid:39:0E:C6:33:B1:50:BC:73:07:31:E5:D8:04:F7:BB:97:55:CF:9B:C8 + static String clientCertStr = + "-----BEGIN CERTIFICATE-----\n" + + "MIICaTCCAdKgAwIBAgIBBTANBgkqhkiG9w0BAQQFADBQMQswCQYDVQQGEwJVUzEN\n" + + "MAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNTRSBUZXN0IFNlcml2Y2UxEzAR\n" + + "BgNVBAMTCmNlcnRpc3N1ZXIwHhcNMTIwNTA1MDI0MTAyWhcNMzIwMTIxMDI0MTAy\n" + + "WjBUMQswCQYDVQQGEwJVUzENMAsGA1UEChMESmF2YTEdMBsGA1UECxMUU3VuSlNT\n" + + "RSBUZXN0IFNlcml2Y2UxFzAVBgNVBAMTDkludGVyT3AgVGVzdGVyMIGfMA0GCSqG\n" + + "SIb3DQEBAQUAA4GNADCBiQKBgQC1pA71nDg1KhhnHjRdi/eVDUa7uFZAtN8R9huu\n" + + "pTwFoyqSX8lDMz8jDawOMmaI9dVZLjTh3hnf4KBEqQOearFVz45yBOjlgPLBuI4F\n" + + "D/ORhgmDaIu2NK+c1yj6YQlyiO0DPwh55GtPLVG3iuEpejU7gQyaMuTaddoXrO7s\n" + + "xwzanQIDAQABo08wTTALBgNVHQ8EBAMCA+gwHQYDVR0OBBYEFFd94jMzYN/dXu2B\n" + + "P+vyG1l/UJyZMB8GA1UdIwQYMBaAFDkOxjOxULxzBzHl2AT3u5dVz5vIMA0GCSqG\n" + + "SIb3DQEBBAUAA4GBAHTgB5W7wnl7Jnb4wNQcb6JdR8FRHIdslcRfnReFfZBHZZux\n" + + "ChpA1lf62KIzYohKoxQXXMul86vnVSHnXq5xctHEmxCBnALEnoAcCOv6wfWqEA7g\n" + + "2rX+ydmu+0ArbqKhSOypZ7K3ame0UOJJ6HDxdsgBYJuotmSou4KKq9e8GF+d\n" + + "-----END CERTIFICATE-----"; + static String clientPrivateKey = // Private key in the format of PKCS#8 + "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALWkDvWcODUqGGce\n" + + "NF2L95UNRru4VkC03xH2G66lPAWjKpJfyUMzPyMNrA4yZoj11VkuNOHeGd/goESp\n" + + "A55qsVXPjnIE6OWA8sG4jgUP85GGCYNoi7Y0r5zXKPphCXKI7QM/CHnka08tUbeK\n" + + "4Sl6NTuBDJoy5Np12hes7uzHDNqdAgMBAAECgYEAjLwygwapXjfhdHQoqpp6F9iT\n" + + "h3sKCVSaybXgOO75lHyZzZO9wv1/288KEm3mmBOxXEm6245UievnAYvaq/GKt93O\n" + + "pj2zRefBzZjGbz0v84fmna/MN6zUUYX1PcVRMKWLx9HKKmQihzwoXdBX0o9PPXdi\n" + + "LfzujNa/q8/mpI5PmEECQQDZwLSaL7OReWZTY4NoQuNzwhx5IKJUOtCFQfmHKZSW\n" + + "wtXntZf+E5W9tGaDY5wjpq5cilKDAHdEAlFWxDe1PoE1AkEA1YuTBpctOLBfquFn\n" + + "Y/S3lzGVlnIHDk3dj4bFglkoJ2bCdlwRNUyBSjAjBDcbYhper8S7GlEN5SiEdz9I\n" + + "3OjIyQJBAKEPMgYhZjYhjxf6sQV7A/VpC9pj0u1uGzGVXNUmYisorUKXRHa/UbBh\n" + + "MLnaAXE1Jh54iRMwUwbQmA0PUQ0T0EkCQQCcr6/umwhkWw2nHYK2Vf5LoudGn15M\n" + + "AZg7UsEjVnXfC0hOfllmCT+ohs96rVCbWAv33lsHAUg3x9YChV3aMbf5AkAj1kuV\n" + + "jUTgFKjediyQC6uof7YdLn+gQGiXK1XE0GBN4WMkzcLiS0jC+MFTgKfFnFdh9K0y\n" + + "fswYKdTA/o8RKaa5"; + + static char passphrase[] = "passphrase".toCharArray(); + + /* + * Is the server ready to serve? + */ + volatile static boolean serverReady = false; + + /* + * Turn on SSL debugging? + */ + static boolean debug = false; + + /* + * Define the server side of the test. + * + * If the server prematurely exits, serverReady will be set to true + * to avoid infinite hangs. + */ + void doServerSide() throws Exception { + SSLContext context = getSSLContext(true); + SSLServerSocketFactory sslssf = context.getServerSocketFactory(); + + SSLServerSocket sslServerSocket = + (SSLServerSocket)sslssf.createServerSocket(serverPort); + serverPort = sslServerSocket.getLocalPort(); + SSLSocket sslSocket = null; + try { + /* + * Signal Client, we're ready for his connect. + */ + serverReady = true; + + sslSocket = (SSLSocket) sslServerSocket.accept(); + sslSocket.setNeedClientAuth(true); + + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + + sslIS.read(); + sslOS.write(85); + sslOS.flush(); + } finally { + if (sslSocket != null) { + sslSocket.close(); + } + sslServerSocket.close(); + } + } + + /* + * Define the client side of the test. + * + * If the server prematurely exits, serverReady will be set to true + * to avoid infinite hangs. + */ + void doClientSide() throws Exception { + /* + * Wait for server to get started. + */ + while (!serverReady) { + Thread.sleep(50); + } + + SSLContext context = getSSLContext(false); + SSLSocketFactory sslsf = context.getSocketFactory(); + + SSLSocket sslSocket = + (SSLSocket)sslsf.createSocket("localhost", serverPort); + try { + InputStream sslIS = sslSocket.getInputStream(); + OutputStream sslOS = sslSocket.getOutputStream(); + + sslOS.write(280); + sslOS.flush(); + sslIS.read(); + } finally { + sslSocket.close(); + } + } + + // get the ssl context + private static SSLContext getSSLContext(boolean isServer) throws Exception { + + // generate certificate from cert string + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + + // create a key store + KeyStore ks = KeyStore.getInstance("JKS"); + ks.load(null, null); + + // import the trused cert + ByteArrayInputStream is = + new ByteArrayInputStream(trusedCertStr.getBytes()); + Certificate trusedCert = cf.generateCertificate(is); + is.close(); + + ks.setCertificateEntry("SunJSSE Test Serivce", trusedCert); + + // import the certificate chain and key + Certificate[] chain = new Certificate[3]; + + is = new ByteArrayInputStream(caSignerStr.getBytes()); + Certificate caSignerCert = cf.generateCertificate(is); + is.close(); + chain[2] = caSignerCert; + + is = new ByteArrayInputStream(certIssuerStr.getBytes()); + Certificate certIssuerCert = cf.generateCertificate(is); + is.close(); + chain[1] = certIssuerCert; + + PKCS8EncodedKeySpec priKeySpec = null; + if (isServer) { + priKeySpec = new PKCS8EncodedKeySpec( + new BASE64Decoder().decodeBuffer(serverPrivateKey)); + is = new ByteArrayInputStream(serverCertStr.getBytes()); + } else { + priKeySpec = new PKCS8EncodedKeySpec( + new BASE64Decoder().decodeBuffer(clientPrivateKey)); + is = new ByteArrayInputStream(clientCertStr.getBytes()); + } + KeyFactory kf = KeyFactory.getInstance("RSA"); + RSAPrivateKey priKey = (RSAPrivateKey)kf.generatePrivate(priKeySpec); + Certificate keyCert = cf.generateCertificate(is); + is.close(); + chain[0] = keyCert; + + ks.setKeyEntry("End Entity", priKey, passphrase, chain); + + // check the certification path + PKIXParameters paras = new PKIXParameters(ks); + paras.setRevocationEnabled(false); + CertPath path = cf.generateCertPath(Arrays.asList(chain)); + CertPathValidator cv = CertPathValidator.getInstance("PKIX"); + cv.validate(path, paras); + + // create SSL context + TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm); + tmf.init(ks); + + SSLContext ctx = SSLContext.getInstance("TLS"); + KeyManagerFactory kmf = KeyManagerFactory.getInstance("NewSunX509"); + kmf.init(ks, passphrase); + + ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); + ks = null; + + return ctx; + } + + private static String tmAlgorithm; // trust manager + + private static void parseArguments(String[] args) { + tmAlgorithm = args[0]; + } + + /* + * ============================================================= + * The remainder is just support stuff + */ + + // use any free port by default + volatile int serverPort = 0; + + volatile Exception serverException = null; + volatile Exception clientException = null; + + public static void main(String args[]) throws Exception { + if (debug) + System.setProperty("javax.net.debug", "all"); + + + /* + * Get the customized arguments. + */ + parseArguments(args); + + /* + * Start the tests. + */ + new BasicConstraints(); + } + + Thread clientThread = null; + Thread serverThread = null; + /* + * Primary constructor, used to drive remainder of the test. + * + * Fork off the other side, then do your work. + */ + BasicConstraints() throws Exception { + if (separateServerThread) { + startServer(true); + startClient(false); + } else { + startClient(true); + startServer(false); + } + + /* + * Wait for other side to close down. + */ + if (separateServerThread) { + serverThread.join(); + } else { + clientThread.join(); + } + + /* + * When we get here, the test is pretty much over. + * + * If the main thread excepted, that propagates back + * immediately. If the other thread threw an exception, we + * should report back. + */ + if (serverException != null) + throw serverException; + if (clientException != null) + throw clientException; + } + + void startServer(boolean newThread) throws Exception { + if (newThread) { + serverThread = new Thread() { + public void run() { + try { + doServerSide(); + } catch (Exception e) { + /* + * Our server thread just died. + * + * Release the client, if not active already... + */ + System.err.println("Server died..."); + serverReady = true; + serverException = e; + } + } + }; + serverThread.start(); + } else { + doServerSide(); + } + } + + void startClient(boolean newThread) throws Exception { + if (newThread) { + clientThread = new Thread() { + public void run() { + try { + doClientSide(); + } catch (Exception e) { + /* + * Our client thread just died. + */ + System.err.println("Client died..."); + clientException = e; + } + } + }; + clientThread.start(); + } else { + doClientSide(); + } + } + +} diff --git a/jdk/test/tools/launcher/Arrrghs.java b/jdk/test/tools/launcher/Arrrghs.java index e551bdf3cf2..fb9437228db 100644 --- a/jdk/test/tools/launcher/Arrrghs.java +++ b/jdk/test/tools/launcher/Arrrghs.java @@ -24,7 +24,7 @@ /** * @test * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938 - * 6894719 6968053 7151314 + * 6894719 6968053 7151434 * @summary Argument parsing validation. * @compile -XDignore.symbol.file Arrrghs.java * @run main Arrrghs @@ -238,7 +238,7 @@ public class Arrrghs extends TestHelper { tr.isNotZeroOutput(); System.out.println(tr); - // 7151314, test for non-negative exit value for an incorrectly formed + // 7151434, test for non-negative exit value for an incorrectly formed // command line, '% java -jar -W', note the bogus -W tr = doExec(javaCmd, "-jar", "-W"); tr.checkNegative(); diff --git a/langtools/.hgtags b/langtools/.hgtags index 82ba71bc3fc..56653f53587 100644 --- a/langtools/.hgtags +++ b/langtools/.hgtags @@ -159,3 +159,5 @@ be069d72dde2bfe6f996c46325a320961ca854c2 jdk8-b32 defd666a786334465496c8901fa302b779c7e045 jdk8-b35 94bbaa67686f44a124cd16fd9f1e8a6a3f684d2d jdk8-b36 5891b38985e8b2502296fc29e726b527d03116d2 jdk8-b37 +1f224f160aa852c9541380735a27a3439dfb7217 jdk8-b38 +a9f547c218d957306dfc0cdd710be041bb62a555 jdk8-b39 diff --git a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java index 5acdc2640bc..07e0c7184cb 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java @@ -1606,6 +1606,11 @@ public class Lower extends TreeTranslator { } private JCStatement makeResourceCloseInvocation(JCExpression resource) { + // convert to AutoCloseable if needed + if (types.asSuper(resource.type, syms.autoCloseableType.tsym) == null) { + resource = (JCExpression) convert(resource, syms.autoCloseableType); + } + // create resource.close() method invocation JCExpression resourceClose = makeCall(resource, names.close, diff --git a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java index 9e74b71c61c..dfde7b19bd3 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/langtools/src/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -2206,10 +2206,15 @@ public class JavacParser implements Parser { } else { JCExpression t = term(EXPR | TYPE); if ((lastmode & TYPE) != 0 && - (token.kind == IDENTIFIER || token.kind == ASSERT || token.kind == ENUM)) + (token.kind == IDENTIFIER || token.kind == ASSERT || + token.kind == ENUM)) { return variableDeclarators(modifiersOpt(), t, stats).toList(); - else + } else if ((lastmode & TYPE) != 0 && token.kind == COLON) { + error(pos, "bad.initializer", "for-loop"); + return List.of((JCStatement)F.at(pos).VarDef(null, null, t, null)); + } else { return moreStatementExpressions(pos, t, stats).toList(); + } } } diff --git a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java index eeeb0953609..bc6acc1a096 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java +++ b/langtools/src/share/classes/com/sun/tools/javac/processing/JavacMessager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2012, 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 @@ -99,6 +99,7 @@ public class JavacMessager implements Messager { if (treeTop != null) { newSource = treeTop.snd.sourcefile; if (newSource != null) { + // save the old version and reinstate it later oldSource = log.useSource(newSource); pos = treeTop.fst.pos(); } @@ -131,7 +132,8 @@ public class JavacMessager implements Messager { break; } } finally { - if (oldSource != null) + // reinstate the saved version, only if it was saved earlier + if (newSource != null) log.useSource(oldSource); } } diff --git a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties index 96e9e3f41ce..5ccfb341cf0 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/langtools/src/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -137,6 +137,10 @@ compiler.err.array.req.but.found=\ compiler.err.attribute.value.must.be.constant=\ attribute value must be constant +# 0: statement type +compiler.err.bad.initializer=\ + bad initializer for {0} + compiler.err.break.outside.switch.loop=\ break outside switch or loop diff --git a/langtools/test/tools/javac/TryWithResources/T7164542.java b/langtools/test/tools/javac/TryWithResources/T7164542.java new file mode 100644 index 00000000000..9e3f2c16731 --- /dev/null +++ b/langtools/test/tools/javac/TryWithResources/T7164542.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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 7164542 + * @summary try-with-resources: problem with intersection types + * @compile T7164542.java + */ + +public class T7164542 { + public static + void copy(S s, T t, int size) throws Exception { + /* + * compiler used to fail here with: + * symbol: method close() + * location: interface Readable + * Fatal Error: Unable to find method close + */ + try (S src = s; T trg = t) { + } + } +} diff --git a/langtools/test/tools/javac/diags/examples/ForeachBadInitialization.java b/langtools/test/tools/javac/diags/examples/ForeachBadInitialization.java new file mode 100644 index 00000000000..5a90de10933 --- /dev/null +++ b/langtools/test/tools/javac/diags/examples/ForeachBadInitialization.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012, 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. + */ + +// key: compiler.err.bad.initializer +import java.util.List; +class ForeachBadInitialization { + void m() { + List s = null; + for (a : s) {} + } +} diff --git a/langtools/test/tools/javac/parser/JavacParserTest.java b/langtools/test/tools/javac/parser/JavacParserTest.java index c297556fa78..e5a3e350350 100644 --- a/langtools/test/tools/javac/parser/JavacParserTest.java +++ b/langtools/test/tools/javac/parser/JavacParserTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 7073631 + * @bug 7073631 7159445 * @summary tests error and diagnostics positions * @author Jan Lahoda */ @@ -875,6 +875,7 @@ public class JavacParserTest extends TestCase { testMissingClassError(); testSwitchError(); testMethodError(); + testErrorRecoveryForEnhancedForLoop142381(); } public static void main(String... args) throws IOException { @@ -892,8 +893,10 @@ abstract class TestCase { } } - void assertFalse(String message, boolean empty) { - throw new UnsupportedOperationException("Not yet implemented"); + void assertFalse(String message, boolean bvalue) { + if (bvalue == true) { + fail(message); + } } void assertEquals(String message, int i, long l) { diff --git a/langtools/test/tools/javac/processing/messager/MessagerDiags.java b/langtools/test/tools/javac/processing/messager/MessagerDiags.java new file mode 100644 index 00000000000..6f333a36090 --- /dev/null +++ b/langtools/test/tools/javac/processing/messager/MessagerDiags.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2012, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 7166010 + * @summary warnings printed by annotation processors uses incorrect source + */ +import com.sun.source.util.JavacTask; +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Messager; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import javax.tools.DiagnosticCollector; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +import static javax.tools.Diagnostic.Kind.*; +import static javax.tools.JavaFileObject.Kind.*; + +@SupportedSourceVersion(SourceVersion.RELEASE_6) +@SupportedAnnotationTypes("*") +public class MessagerDiags extends AbstractProcessor { + static final String CNAME = "Test"; + static final String TEST_JAVA = CNAME + ".java"; + static final String TEST_JAVA_URI_NAME = "myfo:/" + TEST_JAVA; + static final String WRN_NO_SOURCE = "warning without source"; + static final String WRN_WITH_SOURCE = "warning with source"; + static final String NONE = ""; + static final String[] EXPECTED = { NONE + ":-1--1:" + WRN_NO_SOURCE, + TEST_JAVA + ":0-13:" + WRN_WITH_SOURCE, + NONE + ":-1--1:" + WRN_NO_SOURCE + }; + + @Override + public boolean process(Set annotations, + RoundEnvironment roundEnv) { + Messager messager = processingEnv.getMessager(); + for (Element e : roundEnv.getRootElements()) { + messager.printMessage(WARNING, WRN_NO_SOURCE); + messager.printMessage(WARNING, WRN_WITH_SOURCE, e); + messager.printMessage(WARNING, WRN_NO_SOURCE); + } + return false; + } + + public static void main(String... args) throws IOException { + final String bootPath = System.getProperty("sun.boot.class.path"); + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); + assert tool != null; + + DiagnosticCollector dc = new DiagnosticCollector<>(); + List options = new LinkedList<>(); + options.addAll(Arrays.asList("-bootclasspath", bootPath, + "-source", "1.6", "-classpath", + System.getProperty("java.class.path"))); + options.addAll(Arrays.asList("-processor", + MessagerDiags.class.getName())); + JavacTask ct = (JavacTask)tool.getTask(null, null, dc, options, null, + Arrays.asList(new MyFileObject("class " + CNAME + " {}"))); + ct.analyze(); + + List obtainedErrors = new ArrayList<>(); + + for (Diagnostic d : dc.getDiagnostics()) { + String dSource; + if (d.getSource() != null) { + dSource = d.getSource().toUri().getPath(); + dSource = dSource.substring(dSource.lastIndexOf('/') + 1); + } else { + dSource = NONE; + } + obtainedErrors.add(dSource + ":" + d.getStartPosition() + "-" + + d.getEndPosition() + ":" + d.getMessage(null)); + } + List expectedErrors = Arrays.asList(EXPECTED); + if (!expectedErrors.equals(obtainedErrors)) { + System.err.println("Expected: " + expectedErrors); + System.err.println("Obtained: " + obtainedErrors); + throw new AssertionError("Messages don't match"); + } + } + + static class MyFileObject extends SimpleJavaFileObject { + private String text; + public MyFileObject(String text) { + super(URI.create(TEST_JAVA_URI_NAME), SOURCE); + this.text = text; + } + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return text; + } + } +} diff --git a/make/scripts/hgforest.sh b/make/scripts/hgforest.sh index 7834826d8eb..515f1b54b52 100644 --- a/make/scripts/hgforest.sh +++ b/make/scripts/hgforest.sh @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2009, 2012, 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 @@ -24,6 +24,8 @@ # # Shell script for a fast parallel forest command +command="$1" +pull_extra_base="$2" tmp=/tmp/forest.$$ rm -f -r ${tmp} @@ -35,40 +37,58 @@ trap 'rm -f -r ${tmp}' EXIT # Only look in specific locations for possible forests (avoids long searches) pull_default="" -if [ "$1" = "clone" -o "$1" = "fclone" ] ; then +repos="" +repos_extra="" +if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then subrepos="corba jaxp jaxws langtools jdk hotspot" if [ -f .hg/hgrc ] ; then pull_default=`hg paths default` + if [ "${pull_default}" = "" ] ; then + echo "ERROR: Need initial clone with 'hg paths default' defined" + exit 1 + fi fi if [ "${pull_default}" = "" ] ; then - echo "ERROR: Need initial clone with 'hg paths default' defined" + echo "ERROR: Need initial repository to use this script" exit 1 fi - repos="" for i in ${subrepos} ; do if [ ! -f ${i}/.hg/hgrc ] ; then repos="${repos} ${i}" fi done + if [ "${pull_extra_base}" != "" ] ; then + subrepos_extra="jdk/src/closed jdk/make/closed jdk/test/closed hotspot/src/closed hotspot/test/closed deploy install sponsors pubs" + pull_default_tail=`echo ${pull_default} | sed -e 's@^.*://[^/]*/\(.*\)@\1@'` + pull_extra="${pull_extra_base}/${pull_default_tail}" + for i in ${subrepos_extra} ; do + if [ ! -f ${i}/.hg/hgrc ] ; then + repos_extra="${repos_extra} ${i}" + fi + done + fi at_a_time=2 + # Any repos to deal with? + if [ "${repos}" = "" -a "${repos_extra}" = "" ] ; then + echo "No repositories to clone." + exit + fi else hgdirs=`ls -d ./.hg ./*/.hg ./*/*/.hg ./*/*/*/.hg ./*/*/*/*/.hg 2>/dev/null` # Derive repository names from the .hg directory locations - repos="" for i in ${hgdirs} ; do repos="${repos} `echo ${i} | sed -e 's@/.hg$@@'`" done at_a_time=8 + # Any repos to deal with? + if [ "${repos}" = "" ] ; then + echo "No repositories to process." + exit + fi fi -# Any repos to deal with? -if [ "${repos}" = "" ] ; then - echo "No repositories to process." - exit -fi - -# Echo out what repositories we will process -echo "# Repos: ${repos}" +# Echo out what repositories we will clone +echo "# Repos: ${repos} ${repos_extra}" # Run the supplied command on all repos in parallel, save output until end n=0 @@ -77,8 +97,8 @@ for i in ${repos} ; do n=`expr ${n} '+' 1` ( ( - if [ "$1" = "clone" -o "$1" = "fclone" ] ; then - cline="hg $* ${pull_default}/${i} ${i}" + if [ "${command}" = "clone" -o "${command}" = "fclone" ] ; then + cline="hg clone ${pull_default}/${i} ${i}" echo "# ${cline}" ( eval "${cline}" ) else @@ -92,6 +112,22 @@ for i in ${repos} ; do sleep 5 fi done +if [ "${repos_extra}" != "" ] ; then + for i in ${repos_extra} ; do + echo "Starting on ${i}" + n=`expr ${n} '+' 1` + ( + ( + cline="hg clone ${pull_extra}/${i} ${i}" + echo "# ${cline}" + ( eval "${cline}" ) + echo "# exit code $?" + ) > ${tmp}/repo.${n} 2>&1 ; cat ${tmp}/repo.${n} ) & + if [ `expr ${n} '%' ${at_a_time}` -eq 0 ] ; then + sleep 5 + fi + done +fi # Wait for all hg commands to complete wait