diff --git a/make/Global.gmk b/make/Global.gmk index 16a5b05cccbe3..3e6721f994c60 100644 --- a/make/Global.gmk +++ b/make/Global.gmk @@ -102,7 +102,7 @@ help: $(info $(_) # method is 'auto', 'ignore' or 'fail' (default)) $(info $(_) TEST="test1 ..." # Use the given test descriptor(s) for testing, e.g.) $(info $(_) # make test TEST="jdk_lang gtest:all") - $(info $(_) TEST_DEPS="dependency1 ..." # Specify additional dependencies for running tests, e.g docs-jdk + $(info $(_) TEST_DEPS="dependency1 ..." # Specify additional dependencies for running tests, e.g docs-jdk) $(info $(_) JTREG="OPT1=x;OPT2=y" # Control the JTREG test harness, use 'make test-only JTREG=help' to list) $(info $(_) GTEST="OPT1=x;OPT2=y" # Control the GTEST test harness, use 'make test-only GTEST=help' to list) $(info $(_) MICRO="OPT1=x;OPT2=y" # Control the MICRO test harness, use 'make test-only MICRO=help' to list) diff --git a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java index 039c531301fe6..114c82c52295b 100644 --- a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java +++ b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java @@ -1896,6 +1896,11 @@ private void finishClassLoading(ClassList classes, Map usingModules = package2ModulesUsingIt.getOrDefault(ed.packageName(), Set.of()); ed.to.retainAll(usingModules); diff --git a/src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.hpp b/src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.hpp index 739126c653df9..22f1d694b92a8 100644 --- a/src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.hpp +++ b/src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.hpp @@ -70,12 +70,11 @@ friend class ArrayCopyStub; _call_stub_size = 11 * MacroAssembler::instruction_size + 1 * MacroAssembler::instruction_size + wordSize, // See emit_exception_handler for detail - // verify_not_null_oop + far_call + should_not_reach_here + invalidate_registers(DEBUG_ONLY) - _exception_handler_size = DEBUG_ONLY(584) NOT_DEBUG(548), // or smaller + _exception_handler_size = DEBUG_ONLY(256) NOT_DEBUG(32), // or smaller // See emit_deopt_handler for detail - // auipc (1) + far_jump (6 or 2) + // auipc (1) + far_jump (2) _deopt_handler_size = 1 * MacroAssembler::instruction_size + - 6 * MacroAssembler::instruction_size // or smaller + 2 * MacroAssembler::instruction_size }; void check_conflict(ciKlass* exact_klass, intptr_t current_klass, Register tmp, diff --git a/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp b/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp index 388ee5c6ea093..a6ac2822b251d 100644 --- a/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp +++ b/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp @@ -300,9 +300,9 @@ void CgroupV1MemoryController::print_version_specific_info(outputStream* st, jul jlong kmem_limit = kernel_memory_limit_in_bytes(phys_mem); jlong kmem_max_usage = kernel_memory_max_usage_in_bytes(); + OSContainer::print_container_helper(st, kmem_limit, "kernel_memory_limit_in_bytes"); OSContainer::print_container_helper(st, kmem_usage, "kernel_memory_usage_in_bytes"); - OSContainer::print_container_helper(st, kmem_limit, "kernel_memory_max_usage_in_bytes"); - OSContainer::print_container_helper(st, kmem_max_usage, "kernel_memory_limit_in_bytes"); + OSContainer::print_container_helper(st, kmem_max_usage, "kernel_memory_max_usage_in_bytes"); } char* CgroupV1Subsystem::cpu_cpuset_cpus() { diff --git a/src/hotspot/os/posix/os_posix.cpp b/src/hotspot/os/posix/os_posix.cpp index 72330190b5382..9aae3b5c1430a 100644 --- a/src/hotspot/os/posix/os_posix.cpp +++ b/src/hotspot/os/posix/os_posix.cpp @@ -931,10 +931,6 @@ void os::_exit(int num) { ALLOW_C_FUNCTION(::_exit, ::_exit(num);) } -bool os::dont_yield() { - return DontYieldALot; -} - void os::naked_yield() { sched_yield(); } diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 9d514e584a486..fd857c2cd95eb 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -4856,12 +4856,6 @@ int os::loadavg(double loadavg[], int nelem) { return -1; } - -// DontYieldALot=false by default: dutifully perform all yields as requested by JVM_Yield() -bool os::dont_yield() { - return DontYieldALot; -} - int os::open(const char *path, int oflag, int mode) { errno_t err; wchar_t* wide_path = wide_abs_unc_path(path, err); diff --git a/src/hotspot/os_cpu/aix_ppc/globals_aix_ppc.hpp b/src/hotspot/os_cpu/aix_ppc/globals_aix_ppc.hpp index b946ce15fa021..e8b04add19ddf 100644 --- a/src/hotspot/os_cpu/aix_ppc/globals_aix_ppc.hpp +++ b/src/hotspot/os_cpu/aix_ppc/globals_aix_ppc.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2015 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -29,7 +29,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, ThreadStackSize, 2048); // 0 => use system default define_pd_global(intx, VMThreadStackSize, 2048); diff --git a/src/hotspot/os_cpu/bsd_aarch64/globals_bsd_aarch64.hpp b/src/hotspot/os_cpu/bsd_aarch64/globals_bsd_aarch64.hpp index c18c4506ac9c0..4a10e7af091ba 100644 --- a/src/hotspot/os_cpu/bsd_aarch64/globals_bsd_aarch64.hpp +++ b/src/hotspot/os_cpu/bsd_aarch64/globals_bsd_aarch64.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, Red Hat Inc. All rights reserved. * Copyright (c) 2021, Azul Systems, Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -31,7 +31,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, ThreadStackSize, 2048); // 0 => use system default define_pd_global(intx, VMThreadStackSize, 2048); diff --git a/src/hotspot/os_cpu/bsd_x86/globals_bsd_x86.hpp b/src/hotspot/os_cpu/bsd_x86/globals_bsd_x86.hpp index a434e329a8bf6..f67bb15c69ef4 100644 --- a/src/hotspot/os_cpu/bsd_x86/globals_bsd_x86.hpp +++ b/src/hotspot/os_cpu/bsd_x86/globals_bsd_x86.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -29,7 +29,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) // -define_pd_global(bool, DontYieldALot, false); #ifdef AMD64 define_pd_global(intx, CompilerThreadStackSize, 1024); define_pd_global(intx, ThreadStackSize, 1024); // 0 => use system default diff --git a/src/hotspot/os_cpu/bsd_zero/globals_bsd_zero.hpp b/src/hotspot/os_cpu/bsd_zero/globals_bsd_zero.hpp index 71aa9043e9e2b..daf2fd8f2a67e 100644 --- a/src/hotspot/os_cpu/bsd_zero/globals_bsd_zero.hpp +++ b/src/hotspot/os_cpu/bsd_zero/globals_bsd_zero.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2010 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -31,7 +31,6 @@ // runtime system. See globals.hpp for details of what they do. // -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, ThreadStackSize, 1536); #ifdef _LP64 define_pd_global(intx, VMThreadStackSize, 1024); diff --git a/src/hotspot/os_cpu/linux_aarch64/globals_linux_aarch64.hpp b/src/hotspot/os_cpu/linux_aarch64/globals_linux_aarch64.hpp index c4219c2bac3d8..955a0ae9dcde9 100644 --- a/src/hotspot/os_cpu/linux_aarch64/globals_linux_aarch64.hpp +++ b/src/hotspot/os_cpu/linux_aarch64/globals_linux_aarch64.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -29,8 +29,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); - // Set default stack sizes < 2MB so as to prevent stacks from getting // large-page aligned and backed by THPs on systems where 2MB is the // default huge page size. For non-JavaThreads, glibc may add an additional diff --git a/src/hotspot/os_cpu/linux_arm/globals_linux_arm.hpp b/src/hotspot/os_cpu/linux_arm/globals_linux_arm.hpp index 4f2d3918a4dbd..c4ffdf2c02eef 100644 --- a/src/hotspot/os_cpu/linux_arm/globals_linux_arm.hpp +++ b/src/hotspot/os_cpu/linux_arm/globals_linux_arm.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -29,7 +29,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) // -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, CompilerThreadStackSize, 512); // System default ThreadStackSize appears to be 512 which is too big. define_pd_global(intx, ThreadStackSize, 320); diff --git a/src/hotspot/os_cpu/linux_ppc/globals_linux_ppc.hpp b/src/hotspot/os_cpu/linux_ppc/globals_linux_ppc.hpp index 182c55b9f96f2..96dcf0a8c0e9a 100644 --- a/src/hotspot/os_cpu/linux_ppc/globals_linux_ppc.hpp +++ b/src/hotspot/os_cpu/linux_ppc/globals_linux_ppc.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2015 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -29,7 +29,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, ThreadStackSize, 2048); // 0 => use system default define_pd_global(intx, VMThreadStackSize, 2048); diff --git a/src/hotspot/os_cpu/linux_riscv/globals_linux_riscv.hpp b/src/hotspot/os_cpu/linux_riscv/globals_linux_riscv.hpp index 297414bfcd510..16e4b205547bb 100644 --- a/src/hotspot/os_cpu/linux_riscv/globals_linux_riscv.hpp +++ b/src/hotspot/os_cpu/linux_riscv/globals_linux_riscv.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020, 2022, Huawei Technologies Co., Ltd. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -29,7 +29,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, ThreadStackSize, 2048); // 0 => use system default define_pd_global(intx, VMThreadStackSize, 2048); diff --git a/src/hotspot/os_cpu/linux_s390/globals_linux_s390.hpp b/src/hotspot/os_cpu/linux_s390/globals_linux_s390.hpp index 295dd665d2d83..49607e24d1520 100644 --- a/src/hotspot/os_cpu/linux_s390/globals_linux_s390.hpp +++ b/src/hotspot/os_cpu/linux_s390/globals_linux_s390.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -31,7 +31,6 @@ // Sets the default values for platform dependent flags used by the // runtime system (see globals.hpp). -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, ThreadStackSize, 1024); // 0 => Use system default. define_pd_global(intx, VMThreadStackSize, 1024); // Some jck tests in lang/fp/fpl038 run out of compile thread stack. diff --git a/src/hotspot/os_cpu/linux_x86/globals_linux_x86.hpp b/src/hotspot/os_cpu/linux_x86/globals_linux_x86.hpp index 8f1f64c2d9e99..97a5732d00a17 100644 --- a/src/hotspot/os_cpu/linux_x86/globals_linux_x86.hpp +++ b/src/hotspot/os_cpu/linux_x86/globals_linux_x86.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -28,7 +28,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); #ifdef AMD64 define_pd_global(intx, CompilerThreadStackSize, 1024); define_pd_global(intx, ThreadStackSize, 1024); // 0 => use system default diff --git a/src/hotspot/os_cpu/linux_zero/globals_linux_zero.hpp b/src/hotspot/os_cpu/linux_zero/globals_linux_zero.hpp index 957c5c4a12a73..ed09bf8372ede 100644 --- a/src/hotspot/os_cpu/linux_zero/globals_linux_zero.hpp +++ b/src/hotspot/os_cpu/linux_zero/globals_linux_zero.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2010 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -31,7 +31,6 @@ // runtime system. See globals.hpp for details of what they do. // -define_pd_global(bool, DontYieldALot, false); define_pd_global(intx, ThreadStackSize, 1536); #ifdef _LP64 define_pd_global(intx, VMThreadStackSize, 1024); diff --git a/src/hotspot/os_cpu/windows_aarch64/globals_windows_aarch64.hpp b/src/hotspot/os_cpu/windows_aarch64/globals_windows_aarch64.hpp index 836fb463206e4..a438e438cdb63 100644 --- a/src/hotspot/os_cpu/windows_aarch64/globals_windows_aarch64.hpp +++ b/src/hotspot/os_cpu/windows_aarch64/globals_windows_aarch64.hpp @@ -28,8 +28,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); - // Default stack size on Windows is determined by the executable (java.exe // has a default value of 320K/1MB [32bit/64bit]). Depending on Windows version, changing // ThreadStackSize to non-zero may have significant impact on memory usage. diff --git a/src/hotspot/os_cpu/windows_x86/globals_windows_x86.hpp b/src/hotspot/os_cpu/windows_x86/globals_windows_x86.hpp index c94796b097a99..811fa2e07e91e 100644 --- a/src/hotspot/os_cpu/windows_x86/globals_windows_x86.hpp +++ b/src/hotspot/os_cpu/windows_x86/globals_windows_x86.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -28,8 +28,6 @@ // Sets the default values for platform dependent flags used by the runtime system. // (see globals.hpp) -define_pd_global(bool, DontYieldALot, false); - // Default stack size on Windows is determined by the executable (java.exe // has a default value of 320K/1MB [32bit/64bit]). Depending on Windows version, changing // ThreadStackSize to non-zero may have significant impact on memory usage. diff --git a/src/hotspot/share/cds/lambdaFormInvokers.cpp b/src/hotspot/share/cds/lambdaFormInvokers.cpp index 88b1f9277ff6e..271c6c76d7ac8 100644 --- a/src/hotspot/share/cds/lambdaFormInvokers.cpp +++ b/src/hotspot/share/cds/lambdaFormInvokers.cpp @@ -166,7 +166,7 @@ void LambdaFormInvokers::regenerate_holder_classes(TRAPS) { // make a copy of class bytes so GC will not affect us. char *buf = NEW_RESOURCE_ARRAY(char, len); memcpy(buf, (char*)h_bytes->byte_at_addr(0), len); - ClassFileStream st((u1*)buf, len, nullptr, ClassFileStream::verify); + ClassFileStream st((u1*)buf, len, nullptr); regenerate_class(class_name, st, CHECK); } } diff --git a/src/hotspot/share/cds/unregisteredClasses.cpp b/src/hotspot/share/cds/unregisteredClasses.cpp index 91346a2008522..d23ca8903e9d6 100644 --- a/src/hotspot/share/cds/unregisteredClasses.cpp +++ b/src/hotspot/share/cds/unregisteredClasses.cpp @@ -51,6 +51,7 @@ InstanceKlass* UnregisteredClasses::load_class(Symbol* name, const char* path, T PerfClassTraceTime::CLASS_LOAD); Symbol* path_symbol = SymbolTable::new_symbol(path); + Symbol* findClass = SymbolTable::new_symbol("findClass"); Handle url_classloader = get_url_classloader(path_symbol, CHECK_NULL); Handle ext_class_name = java_lang_String::externalize_classname(name, CHECK_NULL); @@ -58,11 +59,10 @@ InstanceKlass* UnregisteredClasses::load_class(Symbol* name, const char* path, T JavaCallArguments args(2); args.set_receiver(url_classloader); args.push_oop(ext_class_name); - args.push_int(JNI_FALSE); JavaCalls::call_virtual(&result, vmClasses::URLClassLoader_klass(), - vmSymbols::loadClass_name(), - vmSymbols::string_boolean_class_signature(), + findClass, + vmSymbols::string_class_signature(), &args, CHECK_NULL); assert(result.get_type() == T_OBJECT, "just checking"); diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp index eb2d1b684d239..f108835c9c60e 100644 --- a/src/hotspot/share/classfile/classFileParser.cpp +++ b/src/hotspot/share/classfile/classFileParser.cpp @@ -4659,7 +4659,7 @@ const char* ClassFileParser::skip_over_field_signature(const char* signature, // Checks if name is a legal class name. void ClassFileParser::verify_legal_class_name(const Symbol* name, TRAPS) const { - if (!_need_verify || _relax_verify) { return; } + if (!_need_verify) { return; } assert(name->refcount() > 0, "symbol must be kept alive"); char* bytes = (char*)name->bytes(); @@ -4699,7 +4699,7 @@ void ClassFileParser::verify_legal_class_name(const Symbol* name, TRAPS) const { // Checks if name is a legal field name. void ClassFileParser::verify_legal_field_name(const Symbol* name, TRAPS) const { - if (!_need_verify || _relax_verify) { return; } + if (!_need_verify) { return; } char* bytes = (char*)name->bytes(); unsigned int length = name->utf8_length(); @@ -4732,7 +4732,7 @@ void ClassFileParser::verify_legal_field_name(const Symbol* name, TRAPS) const { // Checks if name is a legal method name. void ClassFileParser::verify_legal_method_name(const Symbol* name, TRAPS) const { - if (!_need_verify || _relax_verify) { return; } + if (!_need_verify) { return; } assert(name != nullptr, "method name is null"); char* bytes = (char*)name->bytes(); @@ -5236,17 +5236,6 @@ void ClassFileParser::update_class_name(Symbol* new_class_name) { _class_name->increment_refcount(); } -static bool relax_format_check_for(ClassLoaderData* loader_data) { - bool trusted = loader_data->is_boot_class_loader_data() || - loader_data->is_platform_class_loader_data(); - bool need_verify = - // verifyAll - (BytecodeVerificationLocal && BytecodeVerificationRemote) || - // verifyRemote - (!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); - return !need_verify; -} - ClassFileParser::ClassFileParser(ClassFileStream* stream, Symbol* name, ClassLoaderData* loader_data, @@ -5303,7 +5292,6 @@ ClassFileParser::ClassFileParser(ClassFileStream* stream, _itfs_len(0), _java_fields_count(0), _need_verify(false), - _relax_verify(false), _has_nonstatic_concrete_methods(false), _declares_nonstatic_concrete_methods(false), _has_localvariable_table(false), @@ -5324,24 +5312,10 @@ ClassFileParser::ClassFileParser(ClassFileStream* stream, assert(0 == _access_flags.as_int(), "invariant"); // Figure out whether we can skip format checking (matching classic VM behavior) - if (CDSConfig::is_dumping_static_archive()) { - // verify == true means it's a 'remote' class (i.e., non-boot class) - // Verification decision is based on BytecodeVerificationRemote flag - // for those classes. - _need_verify = (stream->need_verify()) ? BytecodeVerificationRemote : - BytecodeVerificationLocal; - } - else { - _need_verify = Verifier::should_verify_for(_loader_data->class_loader(), - stream->need_verify()); - } - - // synch back verification state to stream - stream->set_verify(_need_verify); + _need_verify = Verifier::should_verify_for(_loader_data->class_loader()); - // Check if verification needs to be relaxed for this class file - // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376) - _relax_verify = relax_format_check_for(_loader_data); + // synch back verification state to stream to check for truncation. + stream->set_need_verify(_need_verify); parse_stream(stream, CHECK); diff --git a/src/hotspot/share/classfile/classFileParser.hpp b/src/hotspot/share/classfile/classFileParser.hpp index 18cdeec7d8ead..e993120d14005 100644 --- a/src/hotspot/share/classfile/classFileParser.hpp +++ b/src/hotspot/share/classfile/classFileParser.hpp @@ -185,7 +185,6 @@ class ClassFileParser { u2 _java_fields_count; bool _need_verify; - bool _relax_verify; bool _has_nonstatic_concrete_methods; bool _declares_nonstatic_concrete_methods; diff --git a/src/hotspot/share/classfile/classFileStream.cpp b/src/hotspot/share/classfile/classFileStream.cpp index ed67481396d2d..a934cbafa45dd 100644 --- a/src/hotspot/share/classfile/classFileStream.cpp +++ b/src/hotspot/share/classfile/classFileStream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -28,8 +28,6 @@ #include "classfile/vmSymbols.hpp" #include "memory/resourceArea.hpp" -const bool ClassFileStream::verify = true; - void ClassFileStream::truncated_file_error(TRAPS) const { THROW_MSG(vmSymbols::java_lang_ClassFormatError(), "Truncated class file"); } @@ -37,13 +35,12 @@ void ClassFileStream::truncated_file_error(TRAPS) const { ClassFileStream::ClassFileStream(const u1* buffer, int length, const char* source, - bool verify_stream, bool from_boot_loader_modules_image) : _buffer_start(buffer), _buffer_end(buffer + length), _current(buffer), _source(source), - _need_verify(verify_stream), + _need_verify(true), // may be reset by ClassFileParser when this stream is parsed. _from_boot_loader_modules_image(from_boot_loader_modules_image) { assert(buffer != nullptr, "caller should throw NPE"); } @@ -72,6 +69,5 @@ const ClassFileStream* ClassFileStream::clone() const { return new ClassFileStream(new_buffer_start, length(), clone_source(), - need_verify(), from_boot_loader_modules_image()); } diff --git a/src/hotspot/share/classfile/classFileStream.hpp b/src/hotspot/share/classfile/classFileStream.hpp index 41a7df68bd586..67d66bb74a1ff 100644 --- a/src/hotspot/share/classfile/classFileStream.hpp +++ b/src/hotspot/share/classfile/classFileStream.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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,7 +43,7 @@ class ClassFileStream: public ResourceObj { const u1* const _buffer_end; // Buffer top (one past last element) mutable const u1* _current; // Current buffer position const char* const _source; // Source of stream (directory name, ZIP/JAR archive name) - bool _need_verify; // True if verification is on for the class file + bool _need_verify; // True if we need to verify and check truncation of stream bytes. bool _from_boot_loader_modules_image; // True if this was created by ClassPathImageEntry. void truncated_file_error(TRAPS) const ; @@ -52,12 +52,9 @@ class ClassFileStream: public ResourceObj { const char* clone_source() const; public: - static const bool verify; - ClassFileStream(const u1* buffer, int length, const char* source, - bool verify_stream = verify, // to be verified by default bool from_boot_loader_modules_image = false); virtual const ClassFileStream* clone() const; @@ -77,7 +74,7 @@ class ClassFileStream: public ResourceObj { } const char* source() const { return _source; } bool need_verify() const { return _need_verify; } - void set_verify(bool flag) { _need_verify = flag; } + void set_need_verify(bool flag) { _need_verify = flag; } bool from_boot_loader_modules_image() const { return _from_boot_loader_modules_image; } void check_truncated_file(bool b, TRAPS) const { diff --git a/src/hotspot/share/classfile/classLoader.cpp b/src/hotspot/share/classfile/classLoader.cpp index cb155bdeb1939..9cf88e7cf55c0 100644 --- a/src/hotspot/share/classfile/classLoader.cpp +++ b/src/hotspot/share/classfile/classLoader.cpp @@ -140,20 +140,16 @@ PerfCounter* ClassLoader::_perf_resolve_mh_count = nullptr; PerfCounter* ClassLoader::_perf_resolve_mt_count = nullptr; void ClassLoader::print_counters(outputStream *st) { - // The counters are only active if the logging is enabled, but - // we print to the passed in outputStream as requested. - if (log_is_enabled(Info, perf, class, link)) { - st->print_cr("ClassLoader:"); - st->print_cr(" clinit: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", ClassLoader::class_init_time_ms(), ClassLoader::class_init_count()); - st->print_cr(" link methods: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_ik_link_methods_time->get_value()) , _perf_ik_link_methods_count->get_value()); - st->print_cr(" method adapters: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_method_adapters_time->get_value()) , _perf_method_adapters_count->get_value()); - st->print_cr(" resolve..."); - st->print_cr(" invokedynamic: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_indy_time->get_value()) , _perf_resolve_indy_count->get_value()); - st->print_cr(" invokehandle: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_invokehandle_time->get_value()) , _perf_resolve_invokehandle_count->get_value()); - st->print_cr(" CP_MethodHandle: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mh_time->get_value()) , _perf_resolve_mh_count->get_value()); - st->print_cr(" CP_MethodType: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mt_time->get_value()) , _perf_resolve_mt_count->get_value()); - st->cr(); - } + st->print_cr("ClassLoader:"); + st->print_cr(" clinit: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", ClassLoader::class_init_time_ms(), ClassLoader::class_init_count()); + st->print_cr(" link methods: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_ik_link_methods_time->get_value()) , _perf_ik_link_methods_count->get_value()); + st->print_cr(" method adapters: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_method_adapters_time->get_value()) , _perf_method_adapters_count->get_value()); + st->print_cr(" resolve..."); + st->print_cr(" invokedynamic: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_indy_time->get_value()) , _perf_resolve_indy_count->get_value()); + st->print_cr(" invokehandle: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_invokehandle_time->get_value()) , _perf_resolve_invokehandle_count->get_value()); + st->print_cr(" CP_MethodHandle: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mh_time->get_value()) , _perf_resolve_mh_count->get_value()); + st->print_cr(" CP_MethodType: " JLONG_FORMAT "ms / " JLONG_FORMAT " events", Management::ticks_to_ms(_perf_resolve_mt_time->get_value()) , _perf_resolve_mt_count->get_value()); + st->cr(); } GrowableArray* ClassLoader::_patch_mod_entries = nullptr; @@ -297,8 +293,7 @@ ClassFileStream* ClassPathDirEntry::open_stream(JavaThread* current, const char* // Resource allocated return new ClassFileStream(buffer, checked_cast(st.st_size), - _dir, - ClassFileStream::verify); + _dir); } } } @@ -366,8 +361,7 @@ ClassFileStream* ClassPathZipEntry::open_stream(JavaThread* current, const char* // Resource allocated return new ClassFileStream(buffer, filesize, - _zip_name, - ClassFileStream::verify); + _zip_name); } DEBUG_ONLY(ClassPathImageEntry* ClassPathImageEntry::_singleton = nullptr;) @@ -449,7 +443,6 @@ ClassFileStream* ClassPathImageEntry::open_stream_for_loader(JavaThread* current return new ClassFileStream((u1*)data, checked_cast(size), _name, - ClassFileStream::verify, true); // from_boot_loader_modules_image } @@ -1198,8 +1191,6 @@ InstanceKlass* ClassLoader::load_class(Symbol* name, PackageEntry* pkg_entry, bo return nullptr; } - stream->set_verify(ClassLoaderExt::should_verify(classpath_index)); - ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data(); Handle protection_domain; ClassLoadInfo cl_info(protection_domain); diff --git a/src/hotspot/share/classfile/classLoaderExt.hpp b/src/hotspot/share/classfile/classLoaderExt.hpp index 1f1b38cd3121c..ce0013b9d4948 100644 --- a/src/hotspot/share/classfile/classLoaderExt.hpp +++ b/src/hotspot/share/classfile/classLoaderExt.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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 @@ -33,11 +33,6 @@ class ClassListParser; class ClassLoaderExt: public ClassLoader { // AllStatic public: - static bool should_verify(int classpath_index) { - CDS_ONLY(return (classpath_index >= _app_class_paths_start_index);) - NOT_CDS(return false;) - } - #if INCLUDE_CDS private: enum SomeConstants { diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index 0dd183e06d4de..e17de0f2264c6 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -347,7 +347,7 @@ Handle java_lang_String::create_from_str(const char* utf8_str, TRAPS) { #ifdef ASSERT // This check is too strict when the input string is not a valid UTF8. // For example, it may be created with arbitrary content via jni_NewStringUTF. - if (UTF8::is_legal_utf8((const unsigned char*)utf8_str, strlen(utf8_str), false)) { + if (UTF8::is_legal_utf8((const unsigned char*)utf8_str, strlen(utf8_str), /*version_leq_47*/false)) { ResourceMark rm; const char* expected = utf8_str; char* actual = as_utf8_string(h_obj()); @@ -365,7 +365,7 @@ oop java_lang_String::create_oop_from_str(const char* utf8_str, TRAPS) { return h_obj(); } -Handle java_lang_String::create_from_symbol(Symbol* symbol, TRAPS) { +Handle java_lang_String::create_from_symbol(const Symbol* symbol, TRAPS) { const char* utf8_str = (char*)symbol->bytes(); int utf8_len = symbol->utf8_length(); @@ -389,6 +389,8 @@ Handle java_lang_String::create_from_symbol(Symbol* symbol, TRAPS) { } #ifdef ASSERT + // This check is too strict on older classfile versions + if (UTF8::is_legal_utf8((const unsigned char*)utf8_str, utf8_len, /*version_leq_47*/false)) { ResourceMark rm; const char* expected = symbol->as_utf8(); @@ -755,6 +757,35 @@ bool java_lang_String::equals(oop java_string, const jchar* chars, int len) { return true; } +bool java_lang_String::equals(oop java_string, const char* utf8_string, size_t utf8_len) { + assert(java_string->klass() == vmClasses::String_klass(), + "must be java_string"); + typeArrayOop value = java_lang_String::value_no_keepalive(java_string); + int length = java_lang_String::length(java_string, value); + int unicode_length = UTF8::unicode_length(utf8_string, utf8_len); + if (length != unicode_length) { + return false; + } + bool is_latin1 = java_lang_String::is_latin1(java_string); + jchar c; + if (!is_latin1) { + for (int i = 0; i < unicode_length; i++) { + utf8_string = UTF8::next(utf8_string, &c); + if (value->char_at(i) != c) { + return false; + } + } + } else { + for (int i = 0; i < unicode_length; i++) { + utf8_string = UTF8::next(utf8_string, &c); + if ((((jchar) value->byte_at(i)) & 0xff) != c) { + return false; + } + } + } + return true; +} + bool java_lang_String::equals(oop str1, oop str2) { assert(str1->klass() == vmClasses::String_klass(), "must be java String"); diff --git a/src/hotspot/share/classfile/javaClasses.hpp b/src/hotspot/share/classfile/javaClasses.hpp index e01235958103a..a2e6ad7349c08 100644 --- a/src/hotspot/share/classfile/javaClasses.hpp +++ b/src/hotspot/share/classfile/javaClasses.hpp @@ -32,6 +32,7 @@ #include "runtime/handles.hpp" #include "runtime/os.hpp" #include "utilities/macros.hpp" +#include "utilities/utf8.hpp" #include "utilities/vmEnums.hpp" class JvmtiThreadState; @@ -99,7 +100,7 @@ class java_lang_String : AllStatic { static oop create_oop_from_unicode(const jchar* unicode, int len, TRAPS); static Handle create_from_str(const char* utf8_str, TRAPS); static oop create_oop_from_str(const char* utf8_str, TRAPS); - static Handle create_from_symbol(Symbol* symbol, TRAPS); + static Handle create_from_symbol(const Symbol* symbol, TRAPS); static Handle create_from_platform_dependent_str(const char* str, TRAPS); static void set_compact_strings(bool value); @@ -180,10 +181,24 @@ class java_lang_String : AllStatic { return h; } + static unsigned int hash_code(const char* utf8_str, size_t utf8_len) { + unsigned int h = 0; + int unicode_length = UTF8::unicode_length(utf8_str, utf8_len); + + jchar c; + while (unicode_length-- > 0) { + utf8_str = UTF8::next(utf8_str, &c); + h = 31 * h + ((unsigned int)c); + } + return h; + } + static unsigned int hash_code(oop java_string); static unsigned int hash_code_noupdate(oop java_string); + // Compare strings (of different types/encodings), length is the string (array) length static bool equals(oop java_string, const jchar* chars, int len); + static bool equals(oop java_string, const char* utf8_str, size_t utf8_len); static bool equals(oop str1, oop str2); static inline bool value_equals(typeArrayOop str_value1, typeArrayOop str_value2); diff --git a/src/hotspot/share/classfile/klassFactory.cpp b/src/hotspot/share/classfile/klassFactory.cpp index cfcf7d9ea32c2..493fc27dd4308 100644 --- a/src/hotspot/share/classfile/klassFactory.cpp +++ b/src/hotspot/share/classfile/klassFactory.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 2015, 2024, 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 @@ -77,8 +77,7 @@ InstanceKlass* KlassFactory::check_shared_class_file_load_hook( s2 path_index = ik->shared_classpath_index(); ClassFileStream* stream = new ClassFileStream(ptr, pointer_delta_as_int(end_ptr, ptr), - cfs->source(), - ClassFileStream::verify); + cfs->source()); ClassLoadInfo cl_info(protection_domain); ClassFileParser parser(stream, class_name, @@ -157,8 +156,7 @@ static ClassFileStream* check_class_file_load_hook(ClassFileStream* stream, // Set new class file stream using JVMTI agent modified class file data. stream = new ClassFileStream(ptr, pointer_delta_as_int(end_ptr, ptr), - stream->source(), - stream->need_verify()); + stream->source()); } } diff --git a/src/hotspot/share/classfile/stringTable.cpp b/src/hotspot/share/classfile/stringTable.cpp index 3a6cf166ff537..4de4b8e333c76 100644 --- a/src/hotspot/share/classfile/stringTable.cpp +++ b/src/hotspot/share/classfile/stringTable.cpp @@ -99,9 +99,9 @@ inline oop StringTable::read_string_from_compact_hashtable(address base_address, } typedef CompactHashtable< - const jchar*, oop, + const StringTable::StringWrapper&, oop, StringTable::read_string_from_compact_hashtable, - java_lang_String::equals> SharedStringTable; + StringTable::wrapped_string_equals> SharedStringTable; static SharedStringTable _shared_table; #endif @@ -123,12 +123,69 @@ volatile bool _alt_hash = false; static bool _rehashed = false; static uint64_t _alt_hash_seed = 0; +enum class StringType { + OopStr, UnicodeStr, SymbolStr, UTF8Str +}; + +struct StringWrapperInternal { + union { + const Handle oop_str; + const jchar* unicode_str; + const Symbol* symbol_str; + const char* utf8_str; + }; + const StringType type; + const size_t length; + + StringWrapperInternal(const Handle oop_str, const size_t length) : oop_str(oop_str), type(StringType::OopStr), length(length) {} + StringWrapperInternal(const jchar* unicode_str, const size_t length) : unicode_str(unicode_str), type(StringType::UnicodeStr), length(length) {} + StringWrapperInternal(const Symbol* symbol_str, const size_t length) : symbol_str(symbol_str), type(StringType::SymbolStr), length(length) {} + StringWrapperInternal(const char* utf8_str, const size_t length) : utf8_str(utf8_str), type(StringType::UTF8Str), length(length) {} +}; + static unsigned int hash_string(const jchar* s, int len, bool useAlt) { return useAlt ? AltHashing::halfsiphash_32(_alt_hash_seed, s, len) : java_lang_String::hash_code(s, len); } +const char* StringTable::get_symbol_utf8(const StringWrapper& symbol) { + return reinterpret_cast(symbol.symbol_str->bytes()); +} + +unsigned int StringTable::hash_wrapped_string(const StringWrapper& wrapped_str) { + switch (wrapped_str.type) { + case StringType::OopStr: + return java_lang_String::hash_code(wrapped_str.oop_str()); + case StringType::UnicodeStr: + return java_lang_String::hash_code(wrapped_str.unicode_str, static_cast(wrapped_str.length)); + case StringType::SymbolStr: + return java_lang_String::hash_code(get_symbol_utf8(wrapped_str), wrapped_str.length); + case StringType::UTF8Str: + return java_lang_String::hash_code(wrapped_str.utf8_str, wrapped_str.length); + default: + ShouldNotReachHere(); + } + return 0; +} + +// Unnamed int needed to fit CompactHashtable's equals type signature +bool StringTable::wrapped_string_equals(oop java_string, const StringWrapper& wrapped_str, int) { + switch (wrapped_str.type) { + case StringType::OopStr: + return java_lang_String::equals(java_string, wrapped_str.oop_str()); + case StringType::UnicodeStr: + return java_lang_String::equals(java_string, wrapped_str.unicode_str, static_cast(wrapped_str.length)); + case StringType::SymbolStr: + return java_lang_String::equals(java_string, get_symbol_utf8(wrapped_str), wrapped_str.length); + case StringType::UTF8Str: + return java_lang_String::equals(java_string, wrapped_str.utf8_str, wrapped_str.length); + default: + ShouldNotReachHere(); + } + return false; +} + class StringTableConfig : public StackObj { private: public: @@ -163,22 +220,33 @@ class StringTableConfig : public StackObj { } }; -class StringTableLookupJchar : StackObj { - private: - Thread* _thread; +class StringTableLookup : StackObj { uintx _hash; - int _len; - const jchar* _str; + +protected: + Thread* _thread; Handle _found; - public: - StringTableLookupJchar(Thread* thread, uintx hash, const jchar* key, int len) - : _thread(thread), _hash(hash), _len(len), _str(key) { - } - uintx get_hash() const { - return _hash; +public: + StringTableLookup(Thread* thread, uintx hash) + : _hash(hash), _thread(thread) {} + uintx get_hash() const { return _hash; } + bool is_dead(WeakHandle* value) { + oop val_oop = value->peek(); + return val_oop == nullptr; } - bool equals(WeakHandle* value) { +}; + +class StringTableLookupUnicode : public StringTableLookup { +private: + const jchar* _str; + int _len; + +public: + StringTableLookupUnicode(Thread* thread, uintx hash, const jchar* key, int len) + : StringTableLookup(thread, hash), _str(key), _len(len) {} + + bool equals(const WeakHandle* value) { oop val_oop = value->peek(); if (val_oop == nullptr) { return false; @@ -188,29 +256,42 @@ class StringTableLookupJchar : StackObj { return false; } // Need to resolve weak handle and Handleize through possible safepoint. - _found = Handle(_thread, value->resolve()); + _found = Handle(_thread, value->resolve()); return true; } - bool is_dead(WeakHandle* value) { +}; + +class StringTableLookupUTF8 : public StringTableLookup { +private: + const char* _str; + size_t _utf8_len; + +public: + StringTableLookupUTF8(Thread* thread, uintx hash, const char* key, size_t utf8_len) + : StringTableLookup(thread, hash), _str(key), _utf8_len(utf8_len) {} + + bool equals(const WeakHandle* value) { oop val_oop = value->peek(); - return val_oop == nullptr; + if (val_oop == nullptr) { + return false; + } + bool equals = java_lang_String::equals(val_oop, _str, _utf8_len); + if (!equals) { + return false; + } + // Need to resolve weak handle and Handleize through possible safepoint. + _found = Handle(_thread, value->resolve()); + return true; } }; -class StringTableLookupOop : public StackObj { - private: - Thread* _thread; - uintx _hash; +class StringTableLookupOop : public StringTableLookup { +private: Handle _find; - Handle _found; // Might be a different oop with the same value that's already - // in the table, which is the point. - public: - StringTableLookupOop(Thread* thread, uintx hash, Handle handle) - : _thread(thread), _hash(hash), _find(handle) { } - uintx get_hash() const { - return _hash; - } +public: + StringTableLookupOop(Thread* thread, uintx hash, Handle handle) + : StringTableLookup(thread, hash), _find(handle) {} bool equals(WeakHandle* value) { oop val_oop = value->peek(); @@ -225,11 +306,6 @@ class StringTableLookupOop : public StackObj { _found = Handle(_thread, value->resolve()); return true; } - - bool is_dead(WeakHandle* value) { - oop val_oop = value->peek(); - return val_oop == nullptr; - } }; void StringTable::create_table() { @@ -291,14 +367,15 @@ oop StringTable::lookup(Symbol* symbol) { oop StringTable::lookup(const jchar* name, int len) { unsigned int hash = java_lang_String::hash_code(name, len); - oop string = lookup_shared(name, len, hash); + StringWrapper wrapped_name(name, len); + oop string = lookup_shared(wrapped_name, hash); if (string != nullptr) { return string; } if (_alt_hash) { hash = hash_string(name, len, true); } - return do_lookup(name, len, hash); + return do_lookup(wrapped_name, hash); } class StringTableGet : public StackObj { @@ -323,80 +400,140 @@ void StringTable::update_needs_rehash(bool rehash) { } } -oop StringTable::do_lookup(const jchar* name, int len, uintx hash) { +oop StringTable::do_lookup(const StringWrapper& name, uintx hash) { Thread* thread = Thread::current(); - StringTableLookupJchar lookup(thread, hash, name, len); StringTableGet stg(thread); bool rehash_warning; - _local_table->get(thread, lookup, stg, &rehash_warning); + + switch (name.type) { + case StringType::OopStr: { + StringTableLookupOop lookup(thread, hash, name.oop_str); + _local_table->get(thread, lookup, stg, &rehash_warning); + break; + } + case StringType::UnicodeStr: { + StringTableLookupUnicode lookup(thread, hash, name.unicode_str, static_cast(name.length)); + _local_table->get(thread, lookup, stg, &rehash_warning); + break; + } + case StringType::SymbolStr: { + StringTableLookupUTF8 lookup(thread, hash, get_symbol_utf8(name), name.length); + _local_table->get(thread, lookup, stg, &rehash_warning); + break; + } + case StringType::UTF8Str: { + StringTableLookupUTF8 lookup(thread, hash, name.utf8_str, name.length); + _local_table->get(thread, lookup, stg, &rehash_warning); + break; + } + default: + ShouldNotReachHere(); + } + update_needs_rehash(rehash_warning); return stg.get_res_oop(); } +// Converts and allocates to a unicode string and stores the unicode length in len +const jchar* StringTable::to_unicode(const StringWrapper& wrapped_str, int &len, TRAPS) { + switch (wrapped_str.type) { + case StringType::UnicodeStr: + len = static_cast(wrapped_str.length); + return wrapped_str.unicode_str; + case StringType::OopStr: + return java_lang_String::as_unicode_string(wrapped_str.oop_str(), len, CHECK_NULL); + case StringType::SymbolStr: { + const char* utf8_str = get_symbol_utf8(wrapped_str); + int unicode_length = UTF8::unicode_length(utf8_str, wrapped_str.symbol_str->utf8_length()); + jchar* chars = NEW_RESOURCE_ARRAY(jchar, unicode_length); + UTF8::convert_to_unicode(utf8_str, chars, unicode_length); + len = unicode_length; + return chars; + } + case StringType::UTF8Str: { + int unicode_length = UTF8::unicode_length(wrapped_str.utf8_str); + jchar* chars = NEW_RESOURCE_ARRAY(jchar, unicode_length); + UTF8::convert_to_unicode(wrapped_str.utf8_str, chars, unicode_length); + len = unicode_length; + return chars; + } + default: + ShouldNotReachHere(); + } + return nullptr; +} + +Handle StringTable::handle_from_wrapped_string(const StringWrapper& wrapped_str, TRAPS) { + switch (wrapped_str.type) { + case StringType::OopStr: + return wrapped_str.oop_str; + case StringType::UnicodeStr: + return java_lang_String::create_from_unicode(wrapped_str.unicode_str, static_cast(wrapped_str.length), THREAD); + case StringType::SymbolStr: + return java_lang_String::create_from_symbol(wrapped_str.symbol_str, THREAD); + case StringType::UTF8Str: + return java_lang_String::create_from_str(wrapped_str.utf8_str, THREAD); + default: + ShouldNotReachHere(); + } + return Handle(); +} + // Interning oop StringTable::intern(Symbol* symbol, TRAPS) { if (symbol == nullptr) return nullptr; - ResourceMark rm(THREAD); - int length; - jchar* chars = symbol->as_unicode(length); - Handle string; - oop result = intern(string, chars, length, CHECK_NULL); + int length = symbol->utf8_length(); + StringWrapper name(symbol, length); + oop result = intern(name, CHECK_NULL); return result; } oop StringTable::intern(oop string, TRAPS) { if (string == nullptr) return nullptr; - ResourceMark rm(THREAD); - int length; + int length = java_lang_String::length(string); Handle h_string (THREAD, string); - jchar* chars = java_lang_String::as_unicode_string(string, length, - CHECK_NULL); - oop result = intern(h_string, chars, length, CHECK_NULL); + StringWrapper name(h_string, length); + oop result = intern(name, CHECK_NULL); return result; } oop StringTable::intern(const char* utf8_string, TRAPS) { if (utf8_string == nullptr) return nullptr; - ResourceMark rm(THREAD); - int length = UTF8::unicode_length(utf8_string); - jchar* chars = NEW_RESOURCE_ARRAY(jchar, length); - UTF8::convert_to_unicode(utf8_string, chars, length); - Handle string; - oop result = intern(string, chars, length, CHECK_NULL); + size_t length = strlen(utf8_string); + StringWrapper name(utf8_string, length); + oop result = intern(name, CHECK_NULL); return result; } -oop StringTable::intern(Handle string_or_null_h, const jchar* name, int len, TRAPS) { +oop StringTable::intern(const StringWrapper& name, TRAPS) { // shared table always uses java_lang_String::hash_code - unsigned int hash = java_lang_String::hash_code(name, len); - oop found_string = lookup_shared(name, len, hash); + unsigned int hash = hash_wrapped_string(name); + oop found_string = lookup_shared(name, hash); if (found_string != nullptr) { return found_string; } + if (_alt_hash) { - hash = hash_string(name, len, true); + ResourceMark rm(THREAD); + // Convert to unicode for alt hashing + int unicode_length; + const jchar* chars = to_unicode(name, unicode_length, CHECK_NULL); + hash = hash_string(chars, unicode_length, true); } - found_string = do_lookup(name, len, hash); + + found_string = do_lookup(name, hash); if (found_string != nullptr) { return found_string; } - return do_intern(string_or_null_h, name, len, hash, THREAD); + return do_intern(name, hash, THREAD); } -oop StringTable::do_intern(Handle string_or_null_h, const jchar* name, - int len, uintx hash, TRAPS) { +oop StringTable::do_intern(const StringWrapper& name, uintx hash, TRAPS) { HandleMark hm(THREAD); // cleanup strings created - Handle string_h; - - if (!string_or_null_h.is_null()) { - string_h = string_or_null_h; - } else { - string_h = java_lang_String::create_from_unicode(name, len, CHECK_NULL); - } + Handle string_h = handle_from_wrapped_string(name, CHECK_NULL); - assert(java_lang_String::equals(string_h(), name, len), + assert(StringTable::wrapped_string_equals(string_h(), name), "string must be properly initialized"); - assert(len == java_lang_String::length(string_h()), "Must be same length"); // Notify deduplication support that the string is being interned. A string // must never be deduplicated after it has been interned. Doing so interferes @@ -410,7 +547,7 @@ oop StringTable::do_intern(Handle string_or_null_h, const jchar* name, bool rehash_warning; do { - // Callers have already looked up the String using the jchar* name, so just go to add. + // Callers have already looked up the String, so just go to add. WeakHandle wh(_oop_storage, string_h); // The hash table takes ownership of the WeakHandle, even if it's not inserted. if (_local_table->insert(THREAD, lookup, wh, &rehash_warning)) { @@ -775,14 +912,17 @@ size_t StringTable::shared_entry_count() { return _shared_table.entry_count(); } -oop StringTable::lookup_shared(const jchar* name, int len, unsigned int hash) { - assert(hash == java_lang_String::hash_code(name, len), +oop StringTable::lookup_shared(const StringWrapper& name, unsigned int hash) { + assert(hash == hash_wrapped_string(name), "hash must be computed using java_lang_String::hash_code"); - return _shared_table.lookup(name, hash, len); + // len is required but is already part of StringWrapper, so 0 is used + return _shared_table.lookup(name, hash, 0); } oop StringTable::lookup_shared(const jchar* name, int len) { - return _shared_table.lookup(name, java_lang_String::hash_code(name, len), len); + StringWrapper wrapped_name(name, len); + // len is required but is already part of StringWrapper, so 0 is used + return _shared_table.lookup(wrapped_name, java_lang_String::hash_code(name, len), 0); } // This is called BEFORE we enter the CDS safepoint. We can allocate heap objects. diff --git a/src/hotspot/share/classfile/stringTable.hpp b/src/hotspot/share/classfile/stringTable.hpp index 9f49e79718231..38abb9c875c8d 100644 --- a/src/hotspot/share/classfile/stringTable.hpp +++ b/src/hotspot/share/classfile/stringTable.hpp @@ -56,6 +56,18 @@ class StringTable : AllStatic { static double get_load_factor(); static double get_dead_factor(size_t num_dead); +public: + typedef struct StringWrapperInternal StringWrapper; + + // Unnamed int needed to fit CompactHashtable's equals type signature + static bool wrapped_string_equals(oop java_string, const StringWrapper& wrapped_str, int = 0); + +private: + static const char* get_symbol_utf8(const StringWrapper& symbol_str); + static unsigned int hash_wrapped_string(const StringWrapper& wrapped_str); + static const jchar* to_unicode(const StringWrapper& wrapped_str, int &len, TRAPS); + static Handle handle_from_wrapped_string(const StringWrapper& wrapped_str, TRAPS); + // GC support // Callback for GC to notify of changes that might require cleaning or resize. @@ -65,9 +77,9 @@ class StringTable : AllStatic { static void item_added(); static void item_removed(); - static oop intern(Handle string_or_null_h, const jchar* name, int len, TRAPS); - static oop do_intern(Handle string_or_null, const jchar* name, int len, uintx hash, TRAPS); - static oop do_lookup(const jchar* name, int len, uintx hash); + static oop intern(const StringWrapper& name, TRAPS); + static oop do_intern(const StringWrapper& name, uintx hash, TRAPS); + static oop do_lookup(const StringWrapper& name, uintx hash); static void print_table_statistics(outputStream* st); @@ -87,7 +99,7 @@ class StringTable : AllStatic { // Interning static oop intern(Symbol* symbol, TRAPS); static oop intern(oop string, TRAPS); - static oop intern(const char *utf8_string, TRAPS); + static oop intern(const char* utf8_string, TRAPS); // Rehash the string table if it gets out of balance private: @@ -131,7 +143,7 @@ class StringTable : AllStatic { #endif // INCLUDE_CDS_JAVA_HEAP private: - static oop lookup_shared(const jchar* name, int len, unsigned int hash) NOT_CDS_JAVA_HEAP_RETURN_(nullptr); + static oop lookup_shared(const StringWrapper& name, unsigned int hash) NOT_CDS_JAVA_HEAP_RETURN_(nullptr); public: static oop lookup_shared(const jchar* name, int len) NOT_CDS_JAVA_HEAP_RETURN_(nullptr); static size_t shared_entry_count() NOT_CDS_JAVA_HEAP_RETURN_(0); diff --git a/src/hotspot/share/classfile/systemDictionary.cpp b/src/hotspot/share/classfile/systemDictionary.cpp index 2338a179324b6..2d0ebfb7266a5 100644 --- a/src/hotspot/share/classfile/systemDictionary.cpp +++ b/src/hotspot/share/classfile/systemDictionary.cpp @@ -825,7 +825,6 @@ InstanceKlass* SystemDictionary::resolve_hidden_class_from_stream( loader_data = register_loader(class_loader, create_mirror_cld); assert(st != nullptr, "invariant"); - assert(st->need_verify(), "invariant"); // Parse stream and create a klass. InstanceKlass* k = KlassFactory::create_from_stream(st, diff --git a/src/hotspot/share/classfile/verifier.cpp b/src/hotspot/share/classfile/verifier.cpp index b34cde4c63ab6..e8dc8bcfdc9d7 100644 --- a/src/hotspot/share/classfile/verifier.cpp +++ b/src/hotspot/share/classfile/verifier.cpp @@ -105,8 +105,8 @@ static verify_byte_codes_fn_t verify_byte_codes_fn() { // Methods in Verifier -bool Verifier::should_verify_for(oop class_loader, bool should_verify_class) { - return (class_loader == nullptr || !should_verify_class) ? +bool Verifier::should_verify_for(oop class_loader) { + return class_loader == nullptr ? BytecodeVerificationLocal : BytecodeVerificationRemote; } @@ -276,7 +276,7 @@ bool Verifier::verify(InstanceKlass* klass, bool should_verify_class, TRAPS) { bool Verifier::is_eligible_for_verification(InstanceKlass* klass, bool should_verify_class) { Symbol* name = klass->name(); - return (should_verify_for(klass->class_loader(), should_verify_class) && + return (should_verify_class && // return if the class is a bootstrapping class // or defineClass specified not to verify by default (flags override passed arg) // We need to skip the following four for bootstraping diff --git a/src/hotspot/share/classfile/verifier.hpp b/src/hotspot/share/classfile/verifier.hpp index 8065620c8fdb1..731d5eb8d3b9f 100644 --- a/src/hotspot/share/classfile/verifier.hpp +++ b/src/hotspot/share/classfile/verifier.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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,7 +52,7 @@ class Verifier : AllStatic { // Return false if the class is loaded by the bootstrap loader, // or if defineClass was called requesting skipping verification // -Xverify:all overrides this value - static bool should_verify_for(oop class_loader, bool should_verify_class); + static bool should_verify_for(oop class_loader); // Relax certain access checks to enable some broken 1.1 apps to run on 1.2. static bool relax_access_for(oop class_loader); diff --git a/src/hotspot/share/gc/g1/g1RemSet.cpp b/src/hotspot/share/gc/g1/g1RemSet.cpp index bb5ac5036fe47..7ae81de1d074f 100644 --- a/src/hotspot/share/gc/g1/g1RemSet.cpp +++ b/src/hotspot/share/gc/g1/g1RemSet.cpp @@ -755,27 +755,71 @@ class G1ScanAndCountNMethodClosure : public NMethodClosure { // Heap region closure to be applied to all regions in the current collection set // increment to fix up non-card related roots. -class G1ScanCollectionSetRegionClosure : public G1HeapRegionClosure { +class G1ScanCodeRootsClosure : public G1HeapRegionClosure { G1ParScanThreadState* _pss; G1RemSetScanState* _scan_state; - G1GCPhaseTimes::GCParPhases _scan_phase; - G1GCPhaseTimes::GCParPhases _code_roots_phase; - uint _worker_id; size_t _code_roots_scanned; +public: + G1ScanCodeRootsClosure(G1RemSetScanState* scan_state, + G1ParScanThreadState* pss, + uint worker_id) : + _pss(pss), + _scan_state(scan_state), + _worker_id(worker_id), + _code_roots_scanned(0) { } + + bool do_heap_region(G1HeapRegion* r) { + // Scan the code root list attached to the current region + G1ScanAndCountNMethodClosure cl(_pss->closures()->weak_nmethods()); + r->code_roots_do(&cl); + _code_roots_scanned += cl.count(); + return false; + } + + size_t code_roots_scanned() const { return _code_roots_scanned; } +}; + +void G1RemSet::scan_collection_set_code_roots(G1ParScanThreadState* pss, + uint worker_id, + G1GCPhaseTimes::GCParPhases coderoots_phase, + G1GCPhaseTimes::GCParPhases objcopy_phase) { + EventGCPhaseParallel event; + + Tickspan code_root_scan_time; + Tickspan code_root_trim_partially_time; + G1EvacPhaseWithTrimTimeTracker timer(pss, code_root_scan_time, code_root_trim_partially_time); + + G1GCPhaseTimes* p = _g1h->phase_times(); + + G1ScanCodeRootsClosure cl(_scan_state, pss, worker_id); + // Code roots work distribution occurs inside the iteration method. So scan all collection + // set regions for all threads. + _g1h->collection_set_iterate_increment_from(&cl, worker_id); + + p->record_or_add_time_secs(coderoots_phase, worker_id, code_root_scan_time.seconds()); + p->add_time_secs(objcopy_phase, worker_id, code_root_trim_partially_time.seconds()); + + p->record_or_add_thread_work_item(coderoots_phase, worker_id, cl.code_roots_scanned(), G1GCPhaseTimes::CodeRootsScannedNMethods); + + event.commit(GCId::current(), worker_id, G1GCPhaseTimes::phase_name(coderoots_phase)); +} + +class G1ScanOptionalRemSetRootsClosure : public G1HeapRegionClosure { + G1ParScanThreadState* _pss; + + uint _worker_id; + + G1GCPhaseTimes::GCParPhases _scan_phase; + size_t _opt_roots_scanned; + size_t _opt_refs_scanned; size_t _opt_refs_memory_used; - Tickspan _code_root_scan_time; - Tickspan _code_trim_partially_time; - - Tickspan _rem_set_opt_root_scan_time; - Tickspan _rem_set_opt_trim_partially_time; - void scan_opt_rem_set_roots(G1HeapRegion* r) { G1OopStarChunkedList* opt_rem_set_list = _pss->oops_into_optional_region(r); @@ -786,92 +830,58 @@ class G1ScanCollectionSetRegionClosure : public G1HeapRegionClosure { } public: - G1ScanCollectionSetRegionClosure(G1RemSetScanState* scan_state, - G1ParScanThreadState* pss, + G1ScanOptionalRemSetRootsClosure(G1ParScanThreadState* pss, uint worker_id, - G1GCPhaseTimes::GCParPhases scan_phase, - G1GCPhaseTimes::GCParPhases code_roots_phase) : + G1GCPhaseTimes::GCParPhases scan_phase) : _pss(pss), - _scan_state(scan_state), - _scan_phase(scan_phase), - _code_roots_phase(code_roots_phase), _worker_id(worker_id), - _code_roots_scanned(0), + _scan_phase(scan_phase), _opt_roots_scanned(0), _opt_refs_scanned(0), - _opt_refs_memory_used(0), - _code_root_scan_time(), - _code_trim_partially_time(), - _rem_set_opt_root_scan_time(), - _rem_set_opt_trim_partially_time() { } + _opt_refs_memory_used(0) { } - bool do_heap_region(G1HeapRegion* r) { - // The individual references for the optional remembered set are per-worker, so we - // always need to scan them. + bool do_heap_region(G1HeapRegion* r) override { if (r->has_index_in_opt_cset()) { - EventGCPhaseParallel event; - G1EvacPhaseWithTrimTimeTracker timer(_pss, _rem_set_opt_root_scan_time, _rem_set_opt_trim_partially_time); scan_opt_rem_set_roots(r); - - event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(_scan_phase)); - } - - // Scan code root remembered sets. - { - EventGCPhaseParallel event; - G1EvacPhaseWithTrimTimeTracker timer(_pss, _code_root_scan_time, _code_trim_partially_time); - G1ScanAndCountNMethodClosure cl(_pss->closures()->weak_nmethods()); - - // Scan the code root list attached to the current region - r->code_roots_do(&cl); - - _code_roots_scanned += cl.count(); - - event.commit(GCId::current(), _worker_id, G1GCPhaseTimes::phase_name(_code_roots_phase)); } - return false; } - Tickspan code_root_scan_time() const { return _code_root_scan_time; } - Tickspan code_root_trim_partially_time() const { return _code_trim_partially_time; } - - size_t code_roots_scanned() const { return _code_roots_scanned; } - - Tickspan rem_set_opt_root_scan_time() const { return _rem_set_opt_root_scan_time; } - Tickspan rem_set_opt_trim_partially_time() const { return _rem_set_opt_trim_partially_time; } - size_t opt_roots_scanned() const { return _opt_roots_scanned; } size_t opt_refs_scanned() const { return _opt_refs_scanned; } size_t opt_refs_memory_used() const { return _opt_refs_memory_used; } }; -void G1RemSet::scan_collection_set_regions(G1ParScanThreadState* pss, - uint worker_id, - G1GCPhaseTimes::GCParPhases scan_phase, - G1GCPhaseTimes::GCParPhases coderoots_phase, - G1GCPhaseTimes::GCParPhases objcopy_phase) { - G1ScanCollectionSetRegionClosure cl(_scan_state, pss, worker_id, scan_phase, coderoots_phase); - _g1h->collection_set_iterate_increment_from(&cl, worker_id); +void G1RemSet::scan_collection_set_optional_roots(G1ParScanThreadState* pss, + uint worker_id, + G1GCPhaseTimes::GCParPhases scan_phase, + G1GCPhaseTimes::GCParPhases objcopy_phase) { + assert(scan_phase == G1GCPhaseTimes::OptScanHR, "must be"); + + EventGCPhaseParallel event; + + Tickspan rem_set_opt_root_scan_time; + Tickspan rem_set_opt_trim_partially_time; + G1EvacPhaseWithTrimTimeTracker timer(pss, rem_set_opt_root_scan_time, rem_set_opt_trim_partially_time); G1GCPhaseTimes* p = _g1h->phase_times(); - p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_opt_root_scan_time().seconds()); - p->record_or_add_time_secs(scan_phase, worker_id, cl.rem_set_opt_trim_partially_time().seconds()); + G1ScanOptionalRemSetRootsClosure cl(pss, worker_id, scan_phase); + // The individual references for the optional remembered set are per-worker, so every worker + // always need to scan all regions (no claimer). + _g1h->collection_set_iterate_increment_from(&cl, worker_id); - p->record_or_add_time_secs(coderoots_phase, worker_id, cl.code_root_scan_time().seconds()); - p->record_or_add_thread_work_item(coderoots_phase, worker_id, cl.code_roots_scanned(), G1GCPhaseTimes::CodeRootsScannedNMethods); + p->record_or_add_time_secs(scan_phase, worker_id, rem_set_opt_root_scan_time.seconds()); + p->record_or_add_time_secs(objcopy_phase, worker_id, rem_set_opt_trim_partially_time.seconds()); - p->add_time_secs(objcopy_phase, worker_id, cl.code_root_trim_partially_time().seconds()); + p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_roots_scanned(), G1GCPhaseTimes::ScanHRFoundRoots); + p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_scanned(), G1GCPhaseTimes::ScanHRScannedOptRefs); + p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_memory_used(), G1GCPhaseTimes::ScanHRUsedMemory); - // At this time we record some metrics only for the evacuations after the initial one. - if (scan_phase == G1GCPhaseTimes::OptScanHR) { - p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_roots_scanned(), G1GCPhaseTimes::ScanHRFoundRoots); - p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_scanned(), G1GCPhaseTimes::ScanHRScannedOptRefs); - p->record_or_add_thread_work_item(scan_phase, worker_id, cl.opt_refs_memory_used(), G1GCPhaseTimes::ScanHRUsedMemory); - } + event.commit(GCId::current(), worker_id, G1GCPhaseTimes::phase_name(scan_phase)); } + #ifdef ASSERT void G1RemSet::assert_scan_top_is_null(uint hrm_index) { assert(_scan_state->scan_top(hrm_index) == nullptr, diff --git a/src/hotspot/share/gc/g1/g1RemSet.hpp b/src/hotspot/share/gc/g1/g1RemSet.hpp index 0445ad185d3e9..ae4d4a35c45d4 100644 --- a/src/hotspot/share/gc/g1/g1RemSet.hpp +++ b/src/hotspot/share/gc/g1/g1RemSet.hpp @@ -112,11 +112,15 @@ class G1RemSet: public CHeapObj { // Do work for regions in the current increment of the collection set, scanning // non-card based (heap) roots. - void scan_collection_set_regions(G1ParScanThreadState* pss, - uint worker_id, - G1GCPhaseTimes::GCParPhases scan_phase, - G1GCPhaseTimes::GCParPhases coderoots_phase, - G1GCPhaseTimes::GCParPhases objcopy_phase); + void scan_collection_set_code_roots(G1ParScanThreadState* pss, + uint worker_id, + G1GCPhaseTimes::GCParPhases coderoots_phase, + G1GCPhaseTimes::GCParPhases objcopy_phase); + + void scan_collection_set_optional_roots(G1ParScanThreadState* pss, + uint worker_id, + G1GCPhaseTimes::GCParPhases scan_phase, + G1GCPhaseTimes::GCParPhases objcopy_phase); // Two methods for concurrent refinement support, executed concurrently to // the mutator: diff --git a/src/hotspot/share/gc/g1/g1YoungCollector.cpp b/src/hotspot/share/gc/g1/g1YoungCollector.cpp index f3590aa2ff696..13c4e9949ed82 100644 --- a/src/hotspot/share/gc/g1/g1YoungCollector.cpp +++ b/src/hotspot/share/gc/g1/g1YoungCollector.cpp @@ -591,8 +591,10 @@ class G1EvacuateRegionsBaseTask : public WorkerTask { protected: G1CollectedHeap* _g1h; G1ParScanThreadStateSet* _per_thread_states; + G1ScannerTasksQueueSet* _task_queues; TaskTerminator _terminator; + uint _num_workers; void evacuate_live_objects(G1ParScanThreadState* pss, @@ -667,7 +669,22 @@ class G1EvacuateRegionsTask : public G1EvacuateRegionsBaseTask { void scan_roots(G1ParScanThreadState* pss, uint worker_id) { _root_processor->evacuate_roots(pss, worker_id); _g1h->rem_set()->scan_heap_roots(pss, worker_id, G1GCPhaseTimes::ScanHR, G1GCPhaseTimes::ObjCopy, _has_optional_evacuation_work); - _g1h->rem_set()->scan_collection_set_regions(pss, worker_id, G1GCPhaseTimes::ScanHR, G1GCPhaseTimes::CodeRoots, G1GCPhaseTimes::ObjCopy); + _g1h->rem_set()->scan_collection_set_code_roots(pss, worker_id, G1GCPhaseTimes::CodeRoots, G1GCPhaseTimes::ObjCopy); + // There are no optional roots to scan right now. +#ifdef ASSERT + class VerifyOptionalCollectionSetRootsEmptyClosure : public G1HeapRegionClosure { + G1ParScanThreadState* _pss; + + public: + VerifyOptionalCollectionSetRootsEmptyClosure(G1ParScanThreadState* pss) : _pss(pss) { } + + bool do_heap_region(G1HeapRegion* r) override { + assert(!r->has_index_in_opt_cset(), "must be"); + return false; + } + } cl(pss); + _g1h->collection_set_iterate_increment_from(&cl, worker_id); +#endif } void evacuate_live_objects(G1ParScanThreadState* pss, uint worker_id) { @@ -736,7 +753,8 @@ class G1EvacuateOptionalRegionsTask : public G1EvacuateRegionsBaseTask { void scan_roots(G1ParScanThreadState* pss, uint worker_id) { _g1h->rem_set()->scan_heap_roots(pss, worker_id, G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::OptObjCopy, true /* remember_already_scanned_cards */); - _g1h->rem_set()->scan_collection_set_regions(pss, worker_id, G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::OptCodeRoots, G1GCPhaseTimes::OptObjCopy); + _g1h->rem_set()->scan_collection_set_code_roots(pss, worker_id, G1GCPhaseTimes::OptCodeRoots, G1GCPhaseTimes::OptObjCopy); + _g1h->rem_set()->scan_collection_set_optional_roots(pss, worker_id, G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::ObjCopy); } void evacuate_live_objects(G1ParScanThreadState* pss, uint worker_id) { diff --git a/src/hotspot/share/gc/z/zHeap.cpp b/src/hotspot/share/gc/z/zHeap.cpp index 1e917bb5ee39d..d29a5d15795f4 100644 --- a/src/hotspot/share/gc/z/zHeap.cpp +++ b/src/hotspot/share/gc/z/zHeap.cpp @@ -248,10 +248,6 @@ void ZHeap::free_page(ZPage* page, bool allow_defragment) { // Remove page table entry _page_table.remove(page); - if (page->is_old()) { - page->remset_delete(); - } - // Free page _page_allocator.free_page(page, allow_defragment); } @@ -262,9 +258,6 @@ size_t ZHeap::free_empty_pages(const ZArray* pages) { ZArrayIterator iter(pages); for (ZPage* page; iter.next(&page);) { _page_table.remove(page); - if (page->is_old()) { - page->remset_delete(); - } freed += page->size(); } diff --git a/src/hotspot/share/gc/z/zPageAllocator.cpp b/src/hotspot/share/gc/z/zPageAllocator.cpp index 12c17468bfb7e..ecd9f3e34b9b9 100644 --- a/src/hotspot/share/gc/z/zPageAllocator.cpp +++ b/src/hotspot/share/gc/z/zPageAllocator.cpp @@ -809,6 +809,11 @@ ZPage* ZPageAllocator::prepare_to_recycle(ZPage* page, bool allow_defragment) { return defragment_page(to_recycle); } + // Remove the remset before recycling + if (to_recycle->is_old() && to_recycle == page) { + to_recycle->remset_delete(); + } + return to_recycle; } @@ -880,18 +885,9 @@ void ZPageAllocator::free_pages(const ZArray* pages) { } void ZPageAllocator::free_pages_alloc_failed(ZPageAllocation* allocation) { - ZArray to_recycle_pages; - - // Prepare pages for recycling before taking the lock - ZListRemoveIterator allocation_pages_iter(allocation->pages()); - for (ZPage* page; allocation_pages_iter.next(&page);) { - // Prepare to recycle - ZPage* const to_recycle = prepare_to_recycle(page, false /* allow_defragment */); - - // Register for recycling - to_recycle_pages.push(to_recycle); - } - + // The page(s) in the allocation are either taken from the cache or a newly + // created, mapped and commited ZPage. These page(s) have not been inserted in + // the page table, nor allocated a remset, so prepare_to_recycle is not required. ZLocker locker(&_lock); // Only decrease the overall used and not the generation used, @@ -901,7 +897,7 @@ void ZPageAllocator::free_pages_alloc_failed(ZPageAllocation* allocation) { size_t freed = 0; // Free any allocated/flushed pages - ZArrayIterator iter(&to_recycle_pages); + ZListRemoveIterator iter(allocation->pages()); for (ZPage* page; iter.next(&page);) { freed += page->size(); recycle_page(page); diff --git a/src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp b/src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp index bb91016e52223..c2a4016478735 100644 --- a/src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp +++ b/src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, 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 @@ -1202,7 +1202,7 @@ static ClassFileStream* schema_extend_event_klass_bytes(const InstanceKlass* ik, orig_stream->skip_u1_fast(attrib_len); } } - return new ClassFileStream(new_buffer, orig_stream_length, nullptr, ClassFileStream::verify); + return new ClassFileStream(new_buffer, orig_stream_length, nullptr); } // Attempt to locate an existing UTF8_INFO mapping the utf8_constant. @@ -1510,7 +1510,7 @@ static ClassFileStream* schema_extend_event_subklass_bytes(const InstanceKlass* size_of_new_bytes = size_of_instrumented_bytes; is_instrumented = true; } - return new ClassFileStream(new_bytes, size_of_new_bytes, nullptr, ClassFileStream::verify); + return new ClassFileStream(new_bytes, size_of_new_bytes, nullptr); } static bool _force_instrumentation = false; @@ -1547,7 +1547,7 @@ static ClassFileStream* retransform_bytes(const Klass* existing_klass, const Cla assert(new_bytes != nullptr, "invariant"); assert(size_of_new_bytes > 0, "invariant"); is_instrumented = true; - return new ClassFileStream(new_bytes, size_of_new_bytes, nullptr, ClassFileStream::verify); + return new ClassFileStream(new_bytes, size_of_new_bytes, nullptr); } // On initial class load. diff --git a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp index d60baa3c1cc9a..143248ef714ec 100644 --- a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp +++ b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp @@ -169,7 +169,7 @@ NO_TRANSITION(jboolean, jfr_set_throttle(JNIEnv* env, jclass jvm, jlong event_ty return JNI_TRUE; NO_TRANSITION_END -NO_TRANSITION(void, jfr_set_miscellaneous(JNIEnv* env, jobject jvm, jlong event_type_id, jlong value)) +NO_TRANSITION(void, jfr_set_miscellaneous(JNIEnv* env, jclass jvm, jlong event_type_id, jlong value)) JfrEventSetting::set_miscellaneous(event_type_id, value); const JfrEventId typed_event_id = (JfrEventId)event_type_id; if (EventDeprecatedInvocation::eventId == typed_event_id) { diff --git a/src/hotspot/share/jfr/jni/jfrJniMethod.hpp b/src/hotspot/share/jfr/jni/jfrJniMethod.hpp index ece4425782dae..5020920945ea7 100644 --- a/src/hotspot/share/jfr/jni/jfrJniMethod.hpp +++ b/src/hotspot/share/jfr/jni/jfrJniMethod.hpp @@ -101,7 +101,7 @@ jboolean JNICALL jfr_is_available(JNIEnv* env, jclass jvm); jdouble JNICALL jfr_time_conv_factor(JNIEnv* env, jclass jvm); -jlong JNICALL jfr_type_id(JNIEnv* env, jobject jvm, jclass jc); +jlong JNICALL jfr_type_id(JNIEnv* env, jclass jvm, jclass jc); void JNICALL jfr_set_repository_location(JNIEnv* env, jclass jvm, jstring location); @@ -129,7 +129,7 @@ jlong JNICALL jfr_get_unloaded_event_classes_count(JNIEnv* env, jclass jvm); jboolean JNICALL jfr_set_throttle(JNIEnv* env, jclass jvm, jlong event_type_id, jlong event_sample_size, jlong period_ms); -void JNICALL jfr_set_miscellaneous(JNIEnv* env, jobject jvm, jlong id, jlong value); +void JNICALL jfr_set_miscellaneous(JNIEnv* env, jclass jvm, jlong id, jlong value); void JNICALL jfr_emit_old_object_samples(JNIEnv* env, jclass jvm, jlong cutoff_ticks, jboolean, jboolean); diff --git a/src/hotspot/share/oops/methodData.cpp b/src/hotspot/share/oops/methodData.cpp index bc2649ba0ed3e..3c0c0b5468971 100644 --- a/src/hotspot/share/oops/methodData.cpp +++ b/src/hotspot/share/oops/methodData.cpp @@ -1558,6 +1558,8 @@ void MethodData::print_value_on(outputStream* st) const { } void MethodData::print_data_on(outputStream* st) const { + ConditionalMutexLocker ml(extra_data_lock(), !extra_data_lock()->owned_by_self(), + Mutex::_no_safepoint_check_flag); ResourceMark rm; ProfileData* data = first_data(); if (_parameters_type_data_di != no_parameters) { @@ -1568,6 +1570,7 @@ void MethodData::print_data_on(outputStream* st) const { st->fill_to(6); data->print_data_on(st, this); } + st->print_cr("--- Extra data:"); DataLayout* dp = extra_data_base(); DataLayout* end = args_data_limit(); diff --git a/src/hotspot/share/oops/methodData.hpp b/src/hotspot/share/oops/methodData.hpp index 36fcf8ce5fd60..8375552a911b2 100644 --- a/src/hotspot/share/oops/methodData.hpp +++ b/src/hotspot/share/oops/methodData.hpp @@ -2511,7 +2511,7 @@ class MethodData : public Metadata { void clean_method_data(bool always_clean); void clean_weak_method_links(); - Mutex* extra_data_lock() { return &_extra_data_lock; } + Mutex* extra_data_lock() const { return const_cast(&_extra_data_lock); } void check_extra_data_locked() const NOT_DEBUG_RETURN; }; diff --git a/src/hotspot/share/opto/chaitin.cpp b/src/hotspot/share/opto/chaitin.cpp index bef4cfce4d5a1..6252e31d8984f 100644 --- a/src/hotspot/share/opto/chaitin.cpp +++ b/src/hotspot/share/opto/chaitin.cpp @@ -424,6 +424,9 @@ void PhaseChaitin::Register_Allocate() { live.compute(_lrg_map.max_lrg_id()); _live = &live; } + + C->print_method(PHASE_INITIAL_LIVENESS, 4); + // Create the interference graph using virtual copies build_ifg_virtual(); // Include stack slots this time @@ -464,6 +467,8 @@ void PhaseChaitin::Register_Allocate() { _live = &live; } + C->print_method(PHASE_AGGRESSIVE_COALESCING, 4); + // Build physical interference graph uint must_spill = 0; must_spill = build_ifg_physical(&live_arena); @@ -504,6 +509,9 @@ void PhaseChaitin::Register_Allocate() { live.compute(_lrg_map.max_lrg_id()); // Compute LIVE _live = &live; } + + C->print_method(PHASE_INITIAL_SPILLING, 4); + build_ifg_physical(&live_arena); _ifg->SquareUp(); _ifg->Compute_Effective_Degree(); @@ -518,6 +526,10 @@ void PhaseChaitin::Register_Allocate() { } _lrg_map.compress_uf_map_for_nodes(); + if (OptoCoalesce) { + C->print_method(PHASE_CONSERVATIVE_COALESCING, 4); + } + #ifdef ASSERT verify(&live_arena, true); #endif @@ -580,6 +592,9 @@ void PhaseChaitin::Register_Allocate() { live.compute(_lrg_map.max_lrg_id()); _live = &live; } + + C->print_method(PHASE_ITERATIVE_SPILLING, 4); + must_spill = build_ifg_physical(&live_arena); _ifg->SquareUp(); _ifg->Compute_Effective_Degree(); @@ -593,6 +608,11 @@ void PhaseChaitin::Register_Allocate() { coalesce.coalesce_driver(); } _lrg_map.compress_uf_map_for_nodes(); + + if (OptoCoalesce) { + C->print_method(PHASE_CONSERVATIVE_COALESCING, 4); + } + #ifdef ASSERT verify(&live_arena, true); #endif @@ -607,6 +627,8 @@ void PhaseChaitin::Register_Allocate() { spills = Select(); } + C->print_method(PHASE_AFTER_ITERATIVE_SPILLING, 4); + // Count number of Simplify-Select trips per coloring success. _allocator_attempts += _trip_cnt + 1; _allocator_successes += 1; @@ -614,9 +636,13 @@ void PhaseChaitin::Register_Allocate() { // Peephole remove copies post_allocate_copy_removal(); + C->print_method(PHASE_POST_ALLOCATION_COPY_REMOVAL, 4); + // Merge multidefs if multiple defs representing the same value are used in a single block. merge_multidefs(); + C->print_method(PHASE_MERGE_MULTI_DEFS, 4); + #ifdef ASSERT // Verify the graph after RA. verify(&live_arena); @@ -645,6 +671,8 @@ void PhaseChaitin::Register_Allocate() { // Convert CISC spills fixup_spills(); + C->print_method(PHASE_FIX_UP_SPILLS, 4); + // Log regalloc results CompileLog* log = Compile::current()->log(); if (log != nullptr) { diff --git a/src/hotspot/share/opto/loopPredicate.cpp b/src/hotspot/share/opto/loopPredicate.cpp index a4bec870b18ce..ed2cee63122b3 100644 --- a/src/hotspot/share/opto/loopPredicate.cpp +++ b/src/hotspot/share/opto/loopPredicate.cpp @@ -283,62 +283,57 @@ IfProjNode* PhaseIdealLoop::clone_parse_predicate_to_unswitched_loop(ParsePredic return new_predicate_proj; } -// Clones Assertion Predicates to both unswitched loops starting at 'old_predicate_proj' by following its control inputs. -// It also rewires the control edges of data nodes with dependencies in the loop from the old predicates to the new -// cloned predicates. +// Clones Template Assertion Predicates to both unswitched loops starting at 'old_predicate_proj' by following its +// control inputs. It also rewires the control edges of data nodes with dependencies in the loop from the old predicates +// to the new cloned predicates. void PhaseIdealLoop::clone_assertion_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, - Deoptimization::DeoptReason reason, ParsePredicateSuccessProj* old_parse_predicate_proj, - ParsePredicateSuccessProj* fast_loop_parse_predicate_proj, - ParsePredicateSuccessProj* slow_loop_parse_predicate_proj) { - assert(fast_loop_parse_predicate_proj->in(0)->is_ParsePredicate() && - slow_loop_parse_predicate_proj->in(0)->is_ParsePredicate(), "sanity check"); - // Only need to clone range check predicates as those can be changed and duplicated by inserting pre/main/post loops - // and doing loop unrolling. Push the original predicates on a list to later process them in reverse order to keep the + ParsePredicateNode* true_path_loop_parse_predicate, + ParsePredicateNode* false_path_loop_parse_predicate) { + // Push the original Template Assertion Predicates on a list to later process them in reverse order to keep the // original predicate order. Unique_Node_List list; - get_assertion_predicates(old_parse_predicate_proj, list); + get_template_assertion_predicates(old_parse_predicate_proj, list); Node_List to_process; - // Process in reverse order such that 'create_new_if_for_predicate' can be used in - // 'clone_assertion_predicate_for_unswitched_loops' and the original order is maintained. for (int i = list.size() - 1; i >= 0; i--) { - Node* predicate = list.at(i); - assert(predicate->in(0)->is_If(), "must be If node"); - IfNode* iff = predicate->in(0)->as_If(); - assert(predicate->is_Proj() && predicate->as_Proj()->is_IfProj(), "predicate must be a projection of an if node"); - IfProjNode* predicate_proj = predicate->as_IfProj(); + IfTrueNode* template_assertion_predicate_success_proj = list.at(i)->as_IfTrue(); + assert(template_assertion_predicate_success_proj->in(0)->is_If(), "must be If node"); - IfProjNode* fast_proj = clone_assertion_predicate_for_unswitched_loops(iff, predicate_proj, reason, fast_loop_parse_predicate_proj); - assert(assertion_predicate_has_loop_opaque_node(fast_proj->in(0)->as_If()), "must find Assertion Predicate for fast loop"); - IfProjNode* slow_proj = clone_assertion_predicate_for_unswitched_loops(iff, predicate_proj, reason, slow_loop_parse_predicate_proj); - assert(assertion_predicate_has_loop_opaque_node(slow_proj->in(0)->as_If()), "must find Assertion Predicate for slow loop"); + IfTrueNode* true_path_loop_proj = + clone_assertion_predicate_for_unswitched_loops(template_assertion_predicate_success_proj, + true_path_loop_parse_predicate); + IfTrueNode* false_path_loop_proj = + clone_assertion_predicate_for_unswitched_loops(template_assertion_predicate_success_proj, + false_path_loop_parse_predicate); // Update control dependent data nodes. - for (DUIterator j = predicate->outs(); predicate->has_out(j); j++) { - Node* fast_node = predicate->out(j); - if (loop->is_member(get_loop(ctrl_or_self(fast_node)))) { - assert(fast_node->in(0) == predicate, "only control edge"); - Node* slow_node = old_new[fast_node->_idx]; - assert(slow_node->in(0) == predicate, "only control edge"); - _igvn.replace_input_of(fast_node, 0, fast_proj); - to_process.push(slow_node); + for (DUIterator j = template_assertion_predicate_success_proj->outs(); + template_assertion_predicate_success_proj->has_out(j); + j++) { + Node* true_path_loop_node = template_assertion_predicate_success_proj->out(j); + if (loop->is_member(get_loop(ctrl_or_self(true_path_loop_node)))) { + assert(true_path_loop_node->in(0) == template_assertion_predicate_success_proj, "only control edge"); + Node* false_path_loop_node = old_new[true_path_loop_node->_idx]; + assert(false_path_loop_node->in(0) == template_assertion_predicate_success_proj, "only control edge"); + _igvn.replace_input_of(true_path_loop_node, 0, true_path_loop_proj); + to_process.push(false_path_loop_node); --j; } } - // Have to delay updates to the slow loop so uses of predicate are not modified while we iterate on them. + // Have to delay updates to the false path loop so uses of predicate are not modified while we iterate on them. while (to_process.size() > 0) { Node* slow_node = to_process.pop(); - _igvn.replace_input_of(slow_node, 0, slow_proj); + _igvn.replace_input_of(slow_node, 0, false_path_loop_proj); } } } -// Put all Assertion Predicate projections on a list, starting at 'predicate' and going up in the tree. If 'get_opaque' +// Put all Template Assertion Predicate projections on a list, starting at 'predicate' and going up in the tree. If 'get_opaque' // is set, then the OpaqueTemplateAssertionPredicateNode nodes of the Assertion Predicates are put on the list instead // of the projections. -void PhaseIdealLoop::get_assertion_predicates(ParsePredicateSuccessProj* parse_predicate_proj, Unique_Node_List& list, - const bool get_opaque) { +void PhaseIdealLoop::get_template_assertion_predicates(ParsePredicateSuccessProj* parse_predicate_proj, Unique_Node_List& list, + const bool get_opaque) { Deoptimization::DeoptReason deopt_reason = parse_predicate_proj->in(0)->as_ParsePredicate()->deopt_reason(); PredicateBlockIterator predicate_iterator(parse_predicate_proj, deopt_reason); TemplateAssertionPredicateCollector template_assertion_predicate_collector(list, get_opaque); @@ -348,39 +343,38 @@ void PhaseIdealLoop::get_assertion_predicates(ParsePredicateSuccessProj* parse_p // Clone an Assertion Predicate for an unswitched loop. OpaqueLoopInit and OpaqueLoopStride nodes are cloned and uncommon // traps are kept for the predicate (a Halt node is used later when creating pre/main/post loops and copying this cloned // predicate again). -IfProjNode* PhaseIdealLoop::clone_assertion_predicate_for_unswitched_loops(IfNode* template_assertion_predicate, - IfProjNode* predicate, - Deoptimization::DeoptReason reason, - ParsePredicateSuccessProj* parse_predicate_proj) { - TemplateAssertionExpression template_assertion_expression(template_assertion_predicate->in(1)->as_OpaqueTemplateAssertionPredicate()); - OpaqueTemplateAssertionPredicateNode* cloned_opaque_node = template_assertion_expression.clone(parse_predicate_proj->in(0)->in(0), this); - IfProjNode* if_proj = create_new_if_for_predicate(parse_predicate_proj, nullptr, reason, - template_assertion_predicate->Opcode(), false); - _igvn.replace_input_of(if_proj->in(0), 1, cloned_opaque_node); - _igvn.replace_input_of(parse_predicate_proj->in(0), 0, if_proj); - set_idom(parse_predicate_proj->in(0), if_proj, dom_depth(if_proj)); - return if_proj; +IfTrueNode* +PhaseIdealLoop::clone_assertion_predicate_for_unswitched_loops(IfTrueNode* template_assertion_predicate_success_proj, + ParsePredicateNode* unswitched_loop_parse_predicate) { + TemplateAssertionPredicate template_assertion_predicate(template_assertion_predicate_success_proj); + IfTrueNode* template_success_proj = template_assertion_predicate.clone(unswitched_loop_parse_predicate->in(0), this); + assert(assertion_predicate_has_loop_opaque_node(template_success_proj->in(0)->as_If()), + "must find Assertion Predicate for fast loop"); + _igvn.replace_input_of(unswitched_loop_parse_predicate, 0, template_success_proj); + set_idom(unswitched_loop_parse_predicate, template_success_proj, dom_depth(template_success_proj)); + return template_success_proj; } // Clone the old Parse Predicates and Assertion Predicates before the unswitch If to the unswitched loops after the // unswitch If. void PhaseIdealLoop::clone_parse_and_assertion_predicates_to_unswitched_loop(IdealLoopTree* loop, Node_List& old_new, - IfProjNode*& iffast_pred, IfProjNode*& ifslow_pred) { + IfProjNode*& true_path_loop_entry, + IfProjNode*& false_path_loop_entry) { LoopNode* head = loop->_head->as_Loop(); Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl); const Predicates predicates(entry); clone_loop_predication_predicates_to_unswitched_loop(loop, old_new, predicates.loop_predicate_block(), - Deoptimization::Reason_predicate, iffast_pred, ifslow_pred); + Deoptimization::Reason_predicate, true_path_loop_entry, false_path_loop_entry); clone_loop_predication_predicates_to_unswitched_loop(loop, old_new, predicates.profiled_loop_predicate_block(), - Deoptimization::Reason_profile_predicate, iffast_pred, ifslow_pred); + Deoptimization::Reason_profile_predicate, true_path_loop_entry, false_path_loop_entry); const PredicateBlock* loop_limit_check_predicate_block = predicates.loop_limit_check_predicate_block(); if (loop_limit_check_predicate_block->has_parse_predicate() && !head->is_CountedLoop()) { // Don't clone the Loop Limit Check Parse Predicate if we already have a counted loop (a Loop Limit Check Predicate // is only created when converting a LoopNode to a CountedLoopNode). clone_parse_predicate_to_unswitched_loops(loop_limit_check_predicate_block, Deoptimization::Reason_loop_limit_check, - iffast_pred, ifslow_pred); + true_path_loop_entry, false_path_loop_entry); } } @@ -388,16 +382,17 @@ void PhaseIdealLoop::clone_parse_and_assertion_predicates_to_unswitched_loop(Ide void PhaseIdealLoop::clone_loop_predication_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, const PredicateBlock* predicate_block, Deoptimization::DeoptReason reason, - IfProjNode*& iffast_pred, - IfProjNode*& ifslow_pred) { + IfProjNode*& true_path_loop_entry, + IfProjNode*& false_path_loop_entry) { if (predicate_block->has_parse_predicate()) { // We currently only clone Assertion Predicates if there are Parse Predicates. This is not entirely correct and will // be changed with the complete fix for Assertion Predicates. - clone_parse_predicate_to_unswitched_loops(predicate_block, reason, iffast_pred, ifslow_pred); - assert(iffast_pred->in(0)->is_ParsePredicate() && ifslow_pred->in(0)->is_ParsePredicate(), + clone_parse_predicate_to_unswitched_loops(predicate_block, reason, true_path_loop_entry, false_path_loop_entry); + assert(true_path_loop_entry->in(0)->is_ParsePredicate() && false_path_loop_entry->in(0)->is_ParsePredicate(), "must be success projections of the cloned Parse Predicates"); - clone_assertion_predicates_to_unswitched_loop(loop, old_new, reason, predicate_block->parse_predicate_success_proj(), - iffast_pred->as_IfTrue(), ifslow_pred->as_IfTrue()); + clone_assertion_predicates_to_unswitched_loop(loop, old_new, predicate_block->parse_predicate_success_proj(), + true_path_loop_entry->in(0)->as_ParsePredicate(), + false_path_loop_entry->in(0)->as_ParsePredicate()); } } @@ -1250,9 +1245,9 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod // Fall through into rest of the cleanup code which will move any dependent nodes to the skeleton predicates of the // upper bound test. We always need to create skeleton predicates in order to properly remove dead loops when later // splitting the predicated loop into (unreachable) sub-loops (i.e. done by unrolling, peeling, pre/main/post etc.). - IfTrueNode* template_assertion_predicate_proj = - create_template_assertion_predicate(if_opcode, cl, parse_predicate_proj, upper_bound_proj, scale, offset, range, - deopt_reason); + IfTrueNode* template_assertion_predicate_proj = create_template_assertion_predicate(cl, parse_predicate, + upper_bound_proj, scale, offset, + range); // Eliminate the old range check in the loop body. // When a range check is eliminated, data dependent nodes (Load and range check CastII nodes) are now dependent on 2 @@ -1288,15 +1283,16 @@ void PhaseIdealLoop::eliminate_hoisted_range_check(IfTrueNode* hoisted_check_pro // Each newly created Hoisted Check Predicate is accompanied by two Template Assertion Predicates. Later, we initialize // them by making a copy of them when splitting a loop into sub loops. The Assertion Predicates ensure that dead sub // loops are removed properly. -IfTrueNode* PhaseIdealLoop::create_template_assertion_predicate(const int if_opcode, CountedLoopNode* loop_head, - ParsePredicateSuccessProj* parse_predicate_proj, +IfTrueNode* PhaseIdealLoop::create_template_assertion_predicate(CountedLoopNode* loop_head, + ParsePredicateNode* parse_predicate, IfProjNode* new_control, const int scale, Node* offset, - Node* range, Deoptimization::DeoptReason deopt_reason) { + Node* range) { TemplateAssertionPredicateCreator template_assertion_predicate_creator(loop_head, scale, offset, range, this); - return template_assertion_predicate_creator.create_with_uncommon_trap(new_control, parse_predicate_proj, deopt_reason, - if_opcode); - + IfTrueNode* template_success_proj = template_assertion_predicate_creator.create(new_control); + _igvn.replace_input_of(parse_predicate, 0, template_success_proj); + set_idom(parse_predicate, template_success_proj, dom_depth(template_success_proj)); + return template_success_proj; } // Insert Hoisted Check Predicates for null checks and range checks and additional Template Assertion Predicates for diff --git a/src/hotspot/share/opto/loopTransform.cpp b/src/hotspot/share/opto/loopTransform.cpp index 9175d79e6dd4d..e6a56410bd777 100644 --- a/src/hotspot/share/opto/loopTransform.cpp +++ b/src/hotspot/share/opto/loopTransform.cpp @@ -2768,7 +2768,7 @@ void PhaseIdealLoop::do_range_check(IdealLoopTree *loop, Node_List &old_new) { // unrolling or splitting this main-loop further. TemplateAssertionPredicateCreator template_assertion_predicate_creator(cl, scale_con , int_offset, int_limit, this); - loop_entry = template_assertion_predicate_creator.create_with_halt(loop_entry); + loop_entry = template_assertion_predicate_creator.create(loop_entry); assert(assertion_predicate_has_loop_opaque_node(loop_entry->in(0)->as_If()), "unexpected"); // Initialized Assertion Predicate for the value of the initial main-loop. diff --git a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp index 44a72fda644f6..e52f31b1e118d 100644 --- a/src/hotspot/share/opto/loopnode.cpp +++ b/src/hotspot/share/opto/loopnode.cpp @@ -2834,7 +2834,7 @@ Node* CountedLoopNode::skip_assertion_predicates_with_halt() { ctrl = skip_strip_mined()->in(LoopNode::EntryControl); } if (is_main_loop() || is_post_loop()) { - AssertionPredicatesWithHalt assertion_predicates(ctrl); + AssertionPredicates assertion_predicates(ctrl); return assertion_predicates.entry(); } return ctrl; @@ -4470,7 +4470,7 @@ void PhaseIdealLoop::collect_useful_template_assertion_predicates_for_loop(Ideal const PredicateBlock* profiled_loop_predicate_block = predicates.profiled_loop_predicate_block(); if (profiled_loop_predicate_block->has_parse_predicate()) { ParsePredicateSuccessProj* parse_predicate_proj = profiled_loop_predicate_block->parse_predicate_success_proj(); - get_assertion_predicates(parse_predicate_proj, useful_predicates, true); + get_template_assertion_predicates(parse_predicate_proj, useful_predicates, true); } } @@ -4478,7 +4478,7 @@ void PhaseIdealLoop::collect_useful_template_assertion_predicates_for_loop(Ideal const PredicateBlock* loop_predicate_block = predicates.loop_predicate_block(); if (loop_predicate_block->has_parse_predicate()) { ParsePredicateSuccessProj* parse_predicate_proj = loop_predicate_block->parse_predicate_success_proj(); - get_assertion_predicates(parse_predicate_proj, useful_predicates, true); + get_template_assertion_predicates(parse_predicate_proj, useful_predicates, true); } } } diff --git a/src/hotspot/share/opto/loopnode.hpp b/src/hotspot/share/opto/loopnode.hpp index cc67240975d76..07ae390bd2ec6 100644 --- a/src/hotspot/share/opto/loopnode.hpp +++ b/src/hotspot/share/opto/loopnode.hpp @@ -947,7 +947,7 @@ class PhaseIdealLoop : public PhaseTransform { DEBUG_ONLY(static bool assertion_predicate_has_loop_opaque_node(IfNode* iff);) private: DEBUG_ONLY(static void count_opaque_loop_nodes(Node* n, uint& init, uint& stride);) - static void get_assertion_predicates(ParsePredicateSuccessProj* parse_predicate_proj, Unique_Node_List& list, bool get_opaque = false); + static void get_template_assertion_predicates(ParsePredicateSuccessProj* parse_predicate_proj, Unique_Node_List& list, bool get_opaque = false); void update_main_loop_assertion_predicates(CountedLoopNode* main_loop_head); void initialize_assertion_predicates_for_peeled_loop(CountedLoopNode* peeled_loop_head, CountedLoopNode* remaining_loop_head, @@ -1389,10 +1389,8 @@ class PhaseIdealLoop : public PhaseTransform { void loop_predication_follow_branches(Node *c, IdealLoopTree *loop, float loop_trip_cnt, PathFrequency& pf, Node_Stack& stack, VectorSet& seen, Node_List& if_proj_list); - IfTrueNode* create_template_assertion_predicate(int if_opcode, CountedLoopNode* loop_head, - ParsePredicateSuccessProj* parse_predicate_proj, - IfProjNode* new_control, int scale, Node* offset, - Node* range, Deoptimization::DeoptReason deopt_reason); + IfTrueNode* create_template_assertion_predicate(CountedLoopNode* loop_head, ParsePredicateNode* parse_predicate, + IfProjNode* new_control, int scale, Node* offset, Node* range); void eliminate_hoisted_range_check(IfTrueNode* hoisted_check_proj, IfTrueNode* template_assertion_predicate_proj); // Helper function to collect predicate for eliminating the useless ones @@ -1661,23 +1659,24 @@ class PhaseIdealLoop : public PhaseTransform { public: // Clone Parse Predicates to slow and fast loop when unswitching a loop void clone_parse_and_assertion_predicates_to_unswitched_loop(IdealLoopTree* loop, Node_List& old_new, - IfProjNode*& iffast_pred, IfProjNode*& ifslow_pred); + IfProjNode*& true_path_loop_entry, + IfProjNode*& false_path_loop_entry); private: void clone_loop_predication_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, const PredicateBlock* predicate_block, - Deoptimization::DeoptReason reason, IfProjNode*& iffast_pred, - IfProjNode*& ifslow_pred); + Deoptimization::DeoptReason reason, + IfProjNode*& true_path_loop_entry, + IfProjNode*& false_path_loop_entry); void clone_parse_predicate_to_unswitched_loops(const PredicateBlock* predicate_block, Deoptimization::DeoptReason reason, IfProjNode*& iffast_pred, IfProjNode*& ifslow_pred); IfProjNode* clone_parse_predicate_to_unswitched_loop(ParsePredicateSuccessProj* parse_predicate_proj, Node* new_entry, Deoptimization::DeoptReason reason, bool slow_loop); void clone_assertion_predicates_to_unswitched_loop(IdealLoopTree* loop, const Node_List& old_new, - Deoptimization::DeoptReason reason, ParsePredicateSuccessProj* old_parse_predicate_proj, - ParsePredicateSuccessProj* fast_loop_parse_predicate_proj, - ParsePredicateSuccessProj* slow_loop_parse_predicate_proj); - IfProjNode* clone_assertion_predicate_for_unswitched_loops(IfNode* template_assertion_predicate, IfProjNode* predicate, - Deoptimization::DeoptReason reason, - ParsePredicateSuccessProj* parse_predicate_proj); + ParsePredicateSuccessProj* old_parse_predicate_proj, + ParsePredicateNode* true_path_loop_parse_predicate, + ParsePredicateNode* false_path_loop_parse_predicate); + IfTrueNode* clone_assertion_predicate_for_unswitched_loops(IfTrueNode* template_assertion_predicate_success_proj, + ParsePredicateNode* unswitched_loop_parse_predicate); static void check_cloned_parse_predicate_for_unswitching(const Node* new_entry, bool is_fast_loop) PRODUCT_RETURN; bool _created_loop_node; diff --git a/src/hotspot/share/opto/phasetype.hpp b/src/hotspot/share/opto/phasetype.hpp index 7a83f8c7f27d9..dcdf3aa3f8612 100644 --- a/src/hotspot/share/opto/phasetype.hpp +++ b/src/hotspot/share/opto/phasetype.hpp @@ -93,6 +93,15 @@ flags(BEFORE_MATCHING, "Before matching") \ flags(MATCHING, "After matching") \ flags(GLOBAL_CODE_MOTION, "Global code motion") \ + flags(INITIAL_LIVENESS, "Initial liveness") \ + flags(AGGRESSIVE_COALESCING, "Aggressive coalescing") \ + flags(INITIAL_SPILLING, "Initial spilling") \ + flags(CONSERVATIVE_COALESCING, "Conservative coalescing") \ + flags(ITERATIVE_SPILLING, "Iterative spilling") \ + flags(AFTER_ITERATIVE_SPILLING, "After iterative spilling") \ + flags(POST_ALLOCATION_COPY_REMOVAL, "Post-allocation copy removal") \ + flags(MERGE_MULTI_DEFS, "Merge multiple definitions") \ + flags(FIX_UP_SPILLS, "Fix up spills") \ flags(REGISTER_ALLOCATION, "Register Allocation") \ flags(BLOCK_ORDERING, "Block Ordering") \ flags(PEEPHOLE, "Peephole") \ diff --git a/src/hotspot/share/opto/predicates.cpp b/src/hotspot/share/opto/predicates.cpp index 5e600eab2f0de..b57a4d6fdf138 100644 --- a/src/hotspot/share/opto/predicates.cpp +++ b/src/hotspot/share/opto/predicates.cpp @@ -33,10 +33,10 @@ // Walk over all Initialized Assertion Predicates and return the entry into the first Initialized Assertion Predicate // (i.e. not belonging to an Initialized Assertion Predicate anymore) -Node* AssertionPredicatesWithHalt::find_entry(Node* start_proj) { +Node* AssertionPredicates::find_entry(Node* start_proj) { assert(start_proj != nullptr, "should not be null"); Node* entry = start_proj; - while (AssertionPredicateWithHalt::is_predicate(entry)) { + while (AssertionPredicate::is_predicate(entry)) { entry = entry->in(0)->in(0); } return entry; @@ -48,7 +48,7 @@ bool may_be_assertion_predicate_if(const Node* node) { return node->is_IfTrue() && RegularPredicate::may_be_predicate_if(node->as_IfProj()); } -bool AssertionPredicateWithHalt::is_predicate(const Node* maybe_success_proj) { +bool AssertionPredicate::is_predicate(const Node* maybe_success_proj) { if (!may_be_assertion_predicate_if(maybe_success_proj)) { return false; } @@ -57,14 +57,14 @@ bool AssertionPredicateWithHalt::is_predicate(const Node* maybe_success_proj) { // Check if the If node of `predicate_proj` has an OpaqueTemplateAssertionPredicate (Template Assertion Predicate) or // an OpaqueInitializedAssertionPredicate (Initialized Assertion Predicate) node as input. -bool AssertionPredicateWithHalt::has_assertion_predicate_opaque(const Node* predicate_proj) { +bool AssertionPredicate::has_assertion_predicate_opaque(const Node* predicate_proj) { IfNode* iff = predicate_proj->in(0)->as_If(); Node* bol = iff->in(1); return bol->is_OpaqueTemplateAssertionPredicate() || bol->is_OpaqueInitializedAssertionPredicate(); } // Check if the other projection (UCT projection) of `success_proj` has a Halt node as output. -bool AssertionPredicateWithHalt::has_halt(const Node* success_proj) { +bool AssertionPredicate::has_halt(const Node* success_proj) { ProjNode* other_proj = success_proj->as_IfProj()->other_if_proj(); return other_proj->outcnt() == 1 && other_proj->unique_out()->Opcode() == Op_Halt; } @@ -82,7 +82,7 @@ ParsePredicateNode* ParsePredicate::init_parse_predicate(Node* parse_predicate_p return nullptr; } -Deoptimization::DeoptReason RegularPredicateWithUCT::uncommon_trap_reason(IfProjNode* if_proj) { +Deoptimization::DeoptReason RuntimePredicate::uncommon_trap_reason(IfProjNode* if_proj) { CallStaticJavaNode* uct_call = if_proj->is_uncommon_trap_if_pattern(); if (uct_call == nullptr) { return Deoptimization::Reason_none; @@ -90,7 +90,7 @@ Deoptimization::DeoptReason RegularPredicateWithUCT::uncommon_trap_reason(IfProj return Deoptimization::trap_request_reason(uct_call->uncommon_trap_request()); } -bool RegularPredicateWithUCT::is_predicate(Node* maybe_success_proj) { +bool RuntimePredicate::is_predicate(Node* maybe_success_proj) { if (RegularPredicate::may_be_predicate_if(maybe_success_proj)) { return has_valid_uncommon_trap(maybe_success_proj); } else { @@ -98,7 +98,7 @@ bool RegularPredicateWithUCT::is_predicate(Node* maybe_success_proj) { } } -bool RegularPredicateWithUCT::has_valid_uncommon_trap(const Node* success_proj) { +bool RuntimePredicate::has_valid_uncommon_trap(const Node* success_proj) { assert(RegularPredicate::may_be_predicate_if(success_proj), "must have been checked before"); const Deoptimization::DeoptReason deopt_reason = uncommon_trap_reason(success_proj->as_IfProj()); return (deopt_reason == Deoptimization::Reason_loop_limit_check || @@ -106,7 +106,7 @@ bool RegularPredicateWithUCT::has_valid_uncommon_trap(const Node* success_proj) deopt_reason == Deoptimization::Reason_profile_predicate); } -bool RegularPredicateWithUCT::is_predicate(const Node* node, Deoptimization::DeoptReason deopt_reason) { +bool RuntimePredicate::is_predicate(const Node* node, const Deoptimization::DeoptReason deopt_reason) { if (RegularPredicate::may_be_predicate_if(node)) { return deopt_reason == uncommon_trap_reason(node->as_IfProj()); } else { @@ -128,16 +128,6 @@ bool RegularPredicate::may_be_predicate_if(const Node* node) { return false; } -// Runtime Predicates always have an UCT since they could normally fail at runtime. In this case we execute the trap -// on the failing path. -bool RuntimePredicate::is_predicate(Node* node) { - return RegularPredicateWithUCT::is_predicate(node); -} - -bool RuntimePredicate::is_predicate(Node* node, Deoptimization::DeoptReason deopt_reason) { - return RegularPredicateWithUCT::is_predicate(node, deopt_reason); -} - // Rewire any non-CFG nodes dependent on this Template Assertion Predicate (i.e. with a control input to this // Template Assertion Predicate) to the 'target_predicate' based on the 'data_in_loop_body' check. void TemplateAssertionPredicate::rewire_loop_data_dependencies(IfTrueNode* target_predicate, @@ -161,6 +151,21 @@ bool TemplateAssertionPredicate::is_predicate(Node* node) { return if_node->in(1)->is_OpaqueTemplateAssertionPredicate(); } +// Clone this Template Assertion Predicate and replace the OpaqueLoopInitNode with the provided 'new_opaque_init' node. +IfTrueNode* TemplateAssertionPredicate::clone(Node* new_control, PhaseIdealLoop* phase) const { + assert(PhaseIdealLoop::assertion_predicate_has_loop_opaque_node(_if_node), + "must find OpaqueLoop* nodes for Template Assertion Predicate"); + TemplateAssertionExpression template_assertion_expression(opaque_node()); + OpaqueTemplateAssertionPredicateNode* new_opaque_node = template_assertion_expression.clone(new_control, phase); + AssertionPredicateIfCreator assertion_predicate_if_creator(phase); + IfTrueNode* success_proj = assertion_predicate_if_creator.create_for_template(new_control, _if_node->Opcode(), + new_opaque_node, + _if_node->assertion_predicate_type()); + assert(PhaseIdealLoop::assertion_predicate_has_loop_opaque_node(success_proj->in(0)->as_If()), + "Template Assertion Predicates must have OpaqueLoop* nodes in the bool expression"); + return success_proj; +} + // Clone this Template Assertion Predicate and replace the OpaqueLoopInitNode with the provided 'new_opaque_init' node. IfTrueNode* TemplateAssertionPredicate::clone_and_replace_init(Node* new_control, OpaqueLoopInitNode* new_opaque_init, PhaseIdealLoop* phase) const { @@ -168,7 +173,7 @@ IfTrueNode* TemplateAssertionPredicate::clone_and_replace_init(Node* new_control "must find OpaqueLoop* nodes for Template Assertion Predicate"); TemplateAssertionExpression template_assertion_expression(opaque_node()); OpaqueTemplateAssertionPredicateNode* new_opaque_node = - template_assertion_expression.clone_and_replace_init(new_opaque_init, new_control, phase); + template_assertion_expression.clone_and_replace_init(new_control, new_opaque_init, phase); AssertionPredicateIfCreator assertion_predicate_if_creator(phase); IfTrueNode* success_proj = assertion_predicate_if_creator.create_for_template(new_control, _if_node->Opcode(), new_opaque_node, @@ -295,16 +300,16 @@ class ReplaceInitAndStrideStrategy : public TransformStrategyForOpaqueLoopNodes // OpaqueTemplateAssertionPredicate to and including the OpaqueLoop* nodes). The cloned nodes are rewired to reflect the // same graph structure as found for this Template Assertion Expression. The cloned nodes get 'new_ctrl' as ctrl. There // is no other update done for the cloned nodes. Return the newly cloned OpaqueTemplateAssertionPredicate. -OpaqueTemplateAssertionPredicateNode* TemplateAssertionExpression::clone(Node* new_ctrl, PhaseIdealLoop* phase) { - CloneStrategy clone_init_and_stride_strategy(phase, new_ctrl); - return clone(clone_init_and_stride_strategy, new_ctrl, phase); +OpaqueTemplateAssertionPredicateNode* TemplateAssertionExpression::clone(Node* new_control, PhaseIdealLoop* phase) { + CloneStrategy clone_init_and_stride_strategy(phase, new_control); + return clone(clone_init_and_stride_strategy, new_control, phase); } // Same as clone() but instead of cloning the OpaqueLoopInitNode, we replace it with the provided 'new_init' node. OpaqueTemplateAssertionPredicateNode* -TemplateAssertionExpression::clone_and_replace_init(Node* new_init, Node* new_ctrl, PhaseIdealLoop* phase) { - ReplaceInitAndCloneStrideStrategy replace_init_and_clone_stride_strategy(new_init, new_ctrl, phase); - return clone(replace_init_and_clone_stride_strategy, new_ctrl, phase); +TemplateAssertionExpression::clone_and_replace_init(Node* new_control, Node* new_init, PhaseIdealLoop* phase) { + ReplaceInitAndCloneStrideStrategy replace_init_and_clone_stride_strategy(new_init, new_control, phase); + return clone(replace_init_and_clone_stride_strategy, new_control, phase); } // Same as clone() but instead of cloning the OpaqueLoopInit and OpaqueLoopStride node, we replace them with the provided @@ -617,26 +622,6 @@ void AssertionPredicateIfCreator::create_halt_node(IfFalseNode* fail_proj, Ideal _phase->register_control(halt, loop, fail_proj); } -// Creates an init and last value Template Assertion Predicate connected together from a Parse Predicate with an UCT on -// the failing path. Returns the success projection of the last value Template Assertion Predicate. -IfTrueNode* TemplateAssertionPredicateCreator::create_with_uncommon_trap( - Node* new_control, ParsePredicateSuccessProj* parse_predicate_success_proj, - const Deoptimization::DeoptReason deopt_reason, const int if_opcode) { - OpaqueLoopInitNode* opaque_init = create_opaque_init(new_control); - bool does_overflow; - OpaqueTemplateAssertionPredicateNode* template_assertion_predicate_expression = - create_for_init_value(new_control, opaque_init, does_overflow); - IfTrueNode* template_predicate_success_proj = - create_if_node_with_uncommon_trap(template_assertion_predicate_expression, parse_predicate_success_proj, - deopt_reason, if_opcode, does_overflow, - AssertionPredicateType::InitValue); - template_assertion_predicate_expression = create_for_last_value(template_predicate_success_proj, opaque_init, - does_overflow); - return create_if_node_with_uncommon_trap(template_assertion_predicate_expression, parse_predicate_success_proj, - deopt_reason, if_opcode, does_overflow, - AssertionPredicateType::LastValue); -} - OpaqueLoopInitNode* TemplateAssertionPredicateCreator::create_opaque_init(Node* new_control) { OpaqueLoopInitNode* opaque_init = new OpaqueLoopInitNode(_phase->C, _loop_head->init_trip()); _phase->register_new_node(opaque_init, new_control); @@ -650,17 +635,6 @@ TemplateAssertionPredicateCreator::create_for_init_value(Node* new_control, Opaq return expression_creator.create_for_template(new_control, opaque_init, does_overflow); } -IfTrueNode* TemplateAssertionPredicateCreator::create_if_node_with_uncommon_trap( - OpaqueTemplateAssertionPredicateNode* template_assertion_predicate_expression, - ParsePredicateSuccessProj* parse_predicate_success_proj, const Deoptimization::DeoptReason deopt_reason, - const int if_opcode, const bool does_overflow, const AssertionPredicateType assertion_predicate_type) { - IfTrueNode* success_proj = _phase->create_new_if_for_predicate(parse_predicate_success_proj, nullptr, deopt_reason, - does_overflow ? Op_If : if_opcode, false, - assertion_predicate_type); - _phase->igvn().replace_input_of(success_proj->in(0), 1, template_assertion_predicate_expression); - return success_proj; -} - OpaqueTemplateAssertionPredicateNode* TemplateAssertionPredicateCreator::create_for_last_value(Node* new_control, OpaqueLoopInitNode* opaque_init, bool& does_overflow) const { @@ -683,7 +657,7 @@ Node* TemplateAssertionPredicateCreator::create_last_value(Node* new_control, Op return last_value; } -IfTrueNode* TemplateAssertionPredicateCreator::create_if_node_with_halt( +IfTrueNode* TemplateAssertionPredicateCreator::create_if_node( Node* new_control, OpaqueTemplateAssertionPredicateNode* template_assertion_predicate_expression, const bool does_overflow, const AssertionPredicateType assertion_predicate_type) { AssertionPredicateIfCreator assertion_predicate_if_creator(_phase); @@ -694,18 +668,18 @@ IfTrueNode* TemplateAssertionPredicateCreator::create_if_node_with_halt( // Creates an init and last value Template Assertion Predicate connected together with a Halt node on the failing path. // Returns the success projection of the last value Template Assertion Predicate latter. -IfTrueNode* TemplateAssertionPredicateCreator::create_with_halt(Node* new_control) { +IfTrueNode* TemplateAssertionPredicateCreator::create(Node* new_control) { OpaqueLoopInitNode* opaque_init = create_opaque_init(new_control); bool does_overflow; OpaqueTemplateAssertionPredicateNode* template_assertion_predicate_expression = create_for_init_value(new_control, opaque_init, does_overflow); IfTrueNode* template_predicate_success_proj = - create_if_node_with_halt(new_control, template_assertion_predicate_expression, does_overflow, - AssertionPredicateType::InitValue); + create_if_node(new_control, template_assertion_predicate_expression, does_overflow, + AssertionPredicateType::InitValue); template_assertion_predicate_expression = create_for_last_value(template_predicate_success_proj, opaque_init, does_overflow); - return create_if_node_with_halt(template_predicate_success_proj, template_assertion_predicate_expression, - does_overflow, AssertionPredicateType::LastValue); + return create_if_node(template_predicate_success_proj, template_assertion_predicate_expression, + does_overflow, AssertionPredicateType::LastValue); } InitializedAssertionPredicateCreator::InitializedAssertionPredicateCreator(PhaseIdealLoop* phase) diff --git a/src/hotspot/share/opto/predicates.hpp b/src/hotspot/share/opto/predicates.hpp index 342650cd9664b..4b8440f5aaeb6 100644 --- a/src/hotspot/share/opto/predicates.hpp +++ b/src/hotspot/share/opto/predicates.hpp @@ -252,15 +252,15 @@ class NodeInLoopBody : public StackObj { virtual bool check(Node* node) const = 0; }; -// Class to represent Assertion Predicates with a HaltNode instead of an UCT (i.e. either an Initialized Assertion -// Predicate or a Template Assertion Predicate created after the initial one at Loop Predication). -class AssertionPredicatesWithHalt : public StackObj { - Node* _entry; +// Class to represent Assertion Predicates (i.e. either Initialized and/or Template Assertion Predicates). +class AssertionPredicates : public StackObj { + Node* const _entry; static Node* find_entry(Node* start_proj); public: - AssertionPredicatesWithHalt(Node* assertion_predicate_proj) : _entry(find_entry(assertion_predicate_proj)) {} + explicit AssertionPredicates(Node* assertion_predicate_proj) : _entry(find_entry(assertion_predicate_proj)) {} + NONCOPYABLE(AssertionPredicates); // Returns the control input node into the first assertion predicate If. If there are no assertion predicates, it // returns the same node initially passed to the constructor. @@ -269,15 +269,14 @@ class AssertionPredicatesWithHalt : public StackObj { } }; -// Class to represent a single Assertion Predicate with a HaltNode. This could either be: +// Class to represent a single Assertion Predicate. This could either be: // - A Template Assertion Predicate. // - An Initialized Assertion Predicate. -// Note that all other Regular Predicates have an UCT node. -class AssertionPredicateWithHalt : public StackObj { +class AssertionPredicate : public StackObj { static bool has_assertion_predicate_opaque(const Node* predicate_proj); + static bool has_halt(const Node* success_proj); public: static bool is_predicate(const Node* maybe_success_proj); - static bool has_halt(const Node* success_proj); }; // Utility class representing a Regular Predicate which is either a Runtime Predicate or an Assertion Predicate. @@ -286,19 +285,6 @@ class RegularPredicate : public StackObj { static bool may_be_predicate_if(const Node* node); }; -// Class to represent a single Regular Predicate with an UCT. This could either be: -// - A Runtime Predicate -// - A Template Assertion Predicate -// Note that all other Regular Predicates have a Halt node. -class RegularPredicateWithUCT : public StackObj { - static Deoptimization::DeoptReason uncommon_trap_reason(IfProjNode* if_proj); - - public: - static bool is_predicate(Node* maybe_success_proj); - static bool is_predicate(const Node* node, Deoptimization::DeoptReason deopt_reason); - static bool has_valid_uncommon_trap(const Node* success_proj); -}; - // Class to represent a Parse Predicate. class ParsePredicate : public Predicate { ParsePredicateSuccessProj* _success_proj; @@ -356,6 +342,8 @@ class RuntimePredicate : public Predicate { private: static bool is_predicate(Node* maybe_success_proj); + static bool has_valid_uncommon_trap(const Node* success_proj); + static Deoptimization::DeoptReason uncommon_trap_reason(IfProjNode* if_proj); public: Node* entry() const override { @@ -370,7 +358,7 @@ class RuntimePredicate : public Predicate { return _success_proj; } - static bool is_predicate(Node* node, Deoptimization::DeoptReason deopt_reason); + static bool is_predicate(const Node* node, Deoptimization::DeoptReason deopt_reason); }; // Class to represent a Template Assertion Predicate. @@ -405,6 +393,7 @@ class TemplateAssertionPredicate : public Predicate { return _if_node->assertion_predicate_type() == AssertionPredicateType::LastValue; } + IfTrueNode* clone(Node* new_control, PhaseIdealLoop* phase) const; IfTrueNode* clone_and_replace_init(Node* new_control, OpaqueLoopInitNode* new_opaque_init, PhaseIdealLoop* phase) const; void replace_opaque_stride_input(Node* new_stride, PhaseIterGVN& igvn) const; IfTrueNode* initialize(PhaseIdealLoop* phase, Node* new_control) const; @@ -466,8 +455,9 @@ class TemplateAssertionExpression : public StackObj { Node* new_ctrl, PhaseIdealLoop* phase); public: - OpaqueTemplateAssertionPredicateNode* clone(Node* new_ctrl, PhaseIdealLoop* phase); - OpaqueTemplateAssertionPredicateNode* clone_and_replace_init(Node* new_init, Node* new_ctrl, PhaseIdealLoop* phase); + OpaqueTemplateAssertionPredicateNode* clone(Node* new_control, PhaseIdealLoop* phase); + OpaqueTemplateAssertionPredicateNode* clone_and_replace_init(Node* new_control, Node* new_init, + PhaseIdealLoop* phase); OpaqueTemplateAssertionPredicateNode* clone_and_replace_init_and_stride(Node* new_control, Node* new_init, Node* new_stride, PhaseIdealLoop* phase); void replace_opaque_stride_input(Node* new_stride, PhaseIterGVN& igvn); @@ -570,7 +560,7 @@ class AssertionPredicateIfCreator : public StackObj { void create_halt_node(IfFalseNode* fail_proj, IdealLoopTree* loop, const char* halt_message); }; -// This class is used to create a Template Assertion Predicate either with an UCT or a Halt Node from scratch. +// This class is used to create a Template Assertion Predicate either with a Halt Node from scratch. class TemplateAssertionPredicateCreator : public StackObj { CountedLoopNode* const _loop_head; const int _scale; @@ -584,13 +574,9 @@ class TemplateAssertionPredicateCreator : public StackObj { OpaqueTemplateAssertionPredicateNode* create_for_last_value(Node* new_control, OpaqueLoopInitNode* opaque_init, bool& does_overflow) const; Node* create_last_value(Node* new_control, OpaqueLoopInitNode* opaque_init) const; - IfTrueNode* create_if_node_with_uncommon_trap(OpaqueTemplateAssertionPredicateNode* template_assertion_predicate_expression, - ParsePredicateSuccessProj* parse_predicate_success_proj, - Deoptimization::DeoptReason deopt_reason, int if_opcode, - bool does_overflow, AssertionPredicateType assertion_predicate_type); - IfTrueNode* create_if_node_with_halt(Node* new_control, - OpaqueTemplateAssertionPredicateNode* template_assertion_predicate_expression, - bool does_overflow, AssertionPredicateType assertion_predicate_type); + IfTrueNode* create_if_node(Node* new_control, + OpaqueTemplateAssertionPredicateNode* template_assertion_predicate_expression, + bool does_overflow, AssertionPredicateType assertion_predicate_type); public: TemplateAssertionPredicateCreator(CountedLoopNode* loop_head, int scale, Node* offset, Node* range, @@ -602,9 +588,7 @@ class TemplateAssertionPredicateCreator : public StackObj { _phase(phase) {} NONCOPYABLE(TemplateAssertionPredicateCreator); - IfTrueNode* create_with_uncommon_trap(Node* new_control, ParsePredicateSuccessProj* parse_predicate_success_proj, - Deoptimization::DeoptReason deopt_reason, int if_opcode); - IfTrueNode* create_with_halt(Node* new_control); + IfTrueNode* create(Node* new_control); }; // This class creates a new Initialized Assertion Predicate either from a template or from scratch. diff --git a/src/hotspot/share/prims/jni.cpp b/src/hotspot/share/prims/jni.cpp index 6efe45caf1415..b27448dd39ac9 100644 --- a/src/hotspot/share/prims/jni.cpp +++ b/src/hotspot/share/prims/jni.cpp @@ -288,7 +288,7 @@ JNI_ENTRY(jclass, jni_DefineClass(JNIEnv *env, const char *name, jobject loaderR CHECK_NULL); ResourceMark rm(THREAD); - ClassFileStream st((u1*)buf, bufLen, nullptr, ClassFileStream::verify); + ClassFileStream st((u1*)buf, bufLen, nullptr); Handle class_loader (THREAD, JNIHandles::resolve(loaderRef)); Handle protection_domain; ClassLoadInfo cl_info(protection_domain); diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index a027351ff7b43..12ed10630fcea 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -917,7 +917,7 @@ static jclass jvm_define_class_common(const char *name, CHECK_NULL); ResourceMark rm(THREAD); - ClassFileStream st((u1*)buf, len, source, ClassFileStream::verify); + ClassFileStream st((u1*)buf, len, source); Handle class_loader (THREAD, JNIHandles::resolve(loader)); Handle protection_domain (THREAD, JNIHandles::resolve(pd)); ClassLoadInfo cl_info(protection_domain); @@ -1003,7 +1003,7 @@ static jclass jvm_lookup_define_class(jclass lookup, const char *name, Handle protection_domain (THREAD, JNIHandles::resolve(pd)); const char* source = is_nestmate ? host_class->external_name() : "__JVM_LookupDefineClass__"; - ClassFileStream st((u1*)buf, len, source, ClassFileStream::verify); + ClassFileStream st((u1*)buf, len, source); InstanceKlass* ik = nullptr; if (!is_hidden) { @@ -2951,7 +2951,6 @@ JVM_END JVM_LEAF(void, JVM_Yield(JNIEnv *env, jclass threadClass)) - if (os::dont_yield()) return; HOTSPOT_THREAD_YIELD(); os::naked_yield(); JVM_END diff --git a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp index 344ef7802a2a6..a982ac97c4786 100644 --- a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp +++ b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp @@ -1362,8 +1362,7 @@ jvmtiError VM_RedefineClasses::load_new_class_versions() { ClassFileStream st((u1*)_class_defs[i].class_bytes, _class_defs[i].class_byte_count, - "__VM_RedefineClasses__", - ClassFileStream::verify); + "__VM_RedefineClasses__"); // Set redefined class handle in JvmtiThreadState class. // This redefined class is sent to agent event handler for class file diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 70b537bf2d731..11c13fe3c9e19 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -697,9 +697,6 @@ const int ObjectAlignmentInBytes = 8; "Allow parallel defineClass requests for class loaders " \ "registering as parallel capable") \ \ - product_pd(bool, DontYieldALot, \ - "(Deprecated) Throw away obvious excess yield calls") \ - \ product(bool, DisablePrimordialThreadGuardPages, false, EXPERIMENTAL, \ "Disable the use of stack guard pages if the JVM is loaded " \ "on the primordial process thread") \ diff --git a/src/hotspot/share/runtime/java.cpp b/src/hotspot/share/runtime/java.cpp index 23df464aba8bb..c9c7ae8e4c36f 100644 --- a/src/hotspot/share/runtime/java.cpp +++ b/src/hotspot/share/runtime/java.cpp @@ -359,7 +359,11 @@ void print_statistics() { ThreadsSMRSupport::log_statistics(); - ClassLoader::print_counters(tty); + if (log_is_enabled(Info, perf, class, link)) { + LogStreamHandle(Info, perf, class, link) log; + log.print_cr("At VM exit:"); + ClassLoader::print_counters(&log); + } } // Note: before_exit() can be executed only once, if more than one threads diff --git a/src/hotspot/share/runtime/os.hpp b/src/hotspot/share/runtime/os.hpp index 2f665df5bba98..54771f622e991 100644 --- a/src/hotspot/share/runtime/os.hpp +++ b/src/hotspot/share/runtime/os.hpp @@ -1042,8 +1042,6 @@ class os: AllStatic { // debugging support (mostly used by debug.cpp but also fatal error handler) static bool find(address pc, outputStream* st = tty); // OS specific function to make sense out of an address - static bool dont_yield(); // when true, JVM_Yield() is nop - // Thread priority helpers (implemented in OS-specific part) static OSReturn set_native_priority(Thread* thread, int native_prio); static OSReturn get_native_priority(const Thread* const thread, int* priority_ptr); diff --git a/src/java.base/macosx/classes/sun/nio/fs/BsdFileAttributeViews.java b/src/java.base/macosx/classes/sun/nio/fs/BsdFileAttributeViews.java index e071f25f22c50..cac81af84dc5c 100644 --- a/src/java.base/macosx/classes/sun/nio/fs/BsdFileAttributeViews.java +++ b/src/java.base/macosx/classes/sun/nio/fs/BsdFileAttributeViews.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -29,12 +29,15 @@ import java.nio.file.attribute.FileTime; import java.util.concurrent.TimeUnit; import static sun.nio.fs.BsdNativeDispatcher.*; -import static sun.nio.fs.UnixNativeDispatcher.lutimes; +import static sun.nio.fs.UnixConstants.ELOOP; +import static sun.nio.fs.UnixConstants.ENXIO; +import static sun.nio.fs.UnixNativeDispatcher.futimens; +import static sun.nio.fs.UnixNativeDispatcher.utimensat; class BsdFileAttributeViews { // - // Use setattrlist(2) system call which can set creation, modification, - // and access times. + // Use the futimens(2)/utimensat(2) system calls to set the access and + // modification times, and setattrlist(2) to set the creation time. // private static void setTimes(UnixPath path, FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime, @@ -50,31 +53,29 @@ private static void setTimes(UnixPath path, FileTime lastModifiedTime, // permission check path.checkWrite(); - boolean useLutimes = false; + // use a file descriptor if possible to avoid a race due to accessing + // a path more than once as the file at that path could change. + // if path is a symlink, then the open should fail with ELOOP and + // the path will be used instead of the file descriptor. + int fd = -1; try { - useLutimes = !followLinks && - UnixFileAttributes.get(path, false).isSymbolicLink(); + fd = path.openForAttributeAccess(followLinks); } catch (UnixException x) { - x.rethrowAsIOException(path); - } - - int fd = -1; - if (!useLutimes) { - try { - fd = path.openForAttributeAccess(followLinks); - } catch (UnixException x) { + if (!(x.errno() == ENXIO || (x.errno() == ELOOP))) { x.rethrowAsIOException(path); } } try { // not all volumes support setattrlist(2), so set the last - // modified and last access times using futimens(2)/lutimes(3) + // modified and last access times use futimens(2)/utimensat(2) if (lastModifiedTime != null || lastAccessTime != null) { // if not changing both attributes then need existing attributes if (lastModifiedTime == null || lastAccessTime == null) { try { - UnixFileAttributes attrs = UnixFileAttributes.get(fd); + UnixFileAttributes attrs = fd >= 0 ? + UnixFileAttributes.get(fd) : + UnixFileAttributes.get(path, followLinks); if (lastModifiedTime == null) lastModifiedTime = attrs.lastModifiedTime(); if (lastAccessTime == null) @@ -85,20 +86,21 @@ private static void setTimes(UnixPath path, FileTime lastModifiedTime, } // update times - TimeUnit timeUnit = useLutimes ? - TimeUnit.MICROSECONDS : TimeUnit.NANOSECONDS; - long modValue = lastModifiedTime.to(timeUnit); - long accessValue= lastAccessTime.to(timeUnit); + long modValue = lastModifiedTime.to(TimeUnit.NANOSECONDS); + long accessValue= lastAccessTime.to(TimeUnit.NANOSECONDS); boolean retry = false; + int flags = followLinks ? 0 : UnixConstants.AT_SYMLINK_NOFOLLOW; try { - if (useLutimes) - lutimes(path, accessValue, modValue); - else + if (fd >= 0) futimens(fd, accessValue, modValue); + else + utimensat(UnixConstants.AT_FDCWD, path, accessValue, + modValue, flags); } catch (UnixException x) { - // if futimens fails with EINVAL and one/both of the times is - // negative then we adjust the value to the epoch and retry. + // if futimens/utimensat fails with EINVAL and one/both of + // the times is negative, then we adjust the value to the + // epoch and retry. if (x.errno() == UnixConstants.EINVAL && (modValue < 0L || accessValue < 0L)) { retry = true; @@ -110,34 +112,34 @@ private static void setTimes(UnixPath path, FileTime lastModifiedTime, if (modValue < 0L) modValue = 0L; if (accessValue < 0L) accessValue= 0L; try { - if (useLutimes) - lutimes(path, accessValue, modValue); - else + if (fd >= 0) futimens(fd, accessValue, modValue); + else + utimensat(UnixConstants.AT_FDCWD, path, accessValue, + modValue, flags); } catch (UnixException x) { x.rethrowAsIOException(path); } } } - // set the creation time using setattrlist + // set the creation time using setattrlist(2) if (createTime != null) { long createValue = createTime.to(TimeUnit.NANOSECONDS); int commonattr = UnixConstants.ATTR_CMN_CRTIME; try { - if (useLutimes) - setattrlist(path, commonattr, 0L, 0L, createValue, - followLinks ? 0 : UnixConstants.FSOPT_NOFOLLOW); - else + if (fd >= 0) fsetattrlist(fd, commonattr, 0L, 0L, createValue, - followLinks ? 0 : UnixConstants.FSOPT_NOFOLLOW); + followLinks ? 0 : UnixConstants.FSOPT_NOFOLLOW); + else + setattrlist(path, commonattr, 0L, 0L, createValue, + followLinks ? 0 : UnixConstants.FSOPT_NOFOLLOW); } catch (UnixException x) { x.rethrowAsIOException(path); } } } finally { - if (!useLutimes) - close(fd, e -> null); + close(fd, e -> null); } } diff --git a/src/java.base/share/classes/java/io/BufferedInputStream.java b/src/java.base/share/classes/java/io/BufferedInputStream.java index c401873ce12e4..5ca55d838ae34 100644 --- a/src/java.base/share/classes/java/io/BufferedInputStream.java +++ b/src/java.base/share/classes/java/io/BufferedInputStream.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.Objects; -import jdk.internal.misc.InternalLock; import jdk.internal.misc.Unsafe; import jdk.internal.util.ArraysSupport; @@ -74,9 +73,6 @@ public class BufferedInputStream extends FilterInputStream { private static final long BUF_OFFSET = U.objectFieldOffset(BufferedInputStream.class, "buf"); - // initialized to null when BufferedInputStream is sub-classed - private final InternalLock lock; - // initial buffer size (DEFAULT_BUFFER_SIZE or size specified to constructor) private final int initialSize; @@ -243,12 +239,9 @@ public BufferedInputStream(InputStream in, int size) { } initialSize = size; if (getClass() == BufferedInputStream.class) { - // use internal lock and lazily create buffer when not subclassed - lock = InternalLock.newLockOrNull(); + // lazily create buffer when not subclassed buf = EMPTY; } else { - // use monitors and eagerly create buffer when subclassed - lock = null; buf = new byte[size]; } } @@ -256,7 +249,7 @@ public BufferedInputStream(InputStream in, int size) { /** * Fills the buffer with more data, taking into account * shuffling and other tricks for dealing with marks. - * Assumes that it is being called by a locked method. + * Assumes that it is being called by a synchronized method. * This method also assumes that all data has already been read in, * hence pos > count. */ @@ -310,22 +303,7 @@ else if (pos >= buffer.length) { /* no room left in buffer */ * or an I/O error occurs. * @see java.io.FilterInputStream#in */ - public int read() throws IOException { - if (lock != null) { - lock.lock(); - try { - return implRead(); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - return implRead(); - } - } - } - - private int implRead() throws IOException { + public synchronized int read() throws IOException { if (pos >= count) { fill(); if (pos >= count) @@ -397,22 +375,7 @@ private int read1(byte[] b, int off, int len) throws IOException { * or an I/O error occurs. * @throws IndexOutOfBoundsException {@inheritDoc} */ - public int read(byte[] b, int off, int len) throws IOException { - if (lock != null) { - lock.lock(); - try { - return implRead(b, off, len); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - return implRead(b, off, len); - } - } - } - - private int implRead(byte[] b, int off, int len) throws IOException { + public synchronized int read(byte[] b, int off, int len) throws IOException { ensureOpen(); if ((off | len | (off + len) | (b.length - (off + len))) < 0) { throw new IndexOutOfBoundsException(); @@ -444,22 +407,7 @@ private int implRead(byte[] b, int off, int len) throws IOException { * {@code in.skip(n)} throws an IOException, * or an I/O error occurs. */ - public long skip(long n) throws IOException { - if (lock != null) { - lock.lock(); - try { - return implSkip(n); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - return implSkip(n); - } - } - } - - private long implSkip(long n) throws IOException { + public synchronized long skip(long n) throws IOException { ensureOpen(); if (n <= 0) { return 0; @@ -500,22 +448,7 @@ private long implSkip(long n) throws IOException { * invoking its {@link #close()} method, * or an I/O error occurs. */ - public int available() throws IOException { - if (lock != null) { - lock.lock(); - try { - return implAvailable(); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - return implAvailable(); - } - } - } - - private int implAvailable() throws IOException { + public synchronized int available() throws IOException { int n = count - pos; int avail = getInIfOpen().available(); return n > (Integer.MAX_VALUE - avail) @@ -531,22 +464,7 @@ private int implAvailable() throws IOException { * the mark position becomes invalid. * @see java.io.BufferedInputStream#reset() */ - public void mark(int readlimit) { - if (lock != null) { - lock.lock(); - try { - implMark(readlimit); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implMark(readlimit); - } - } - } - - private void implMark(int readlimit) { + public synchronized void mark(int readlimit) { marklimit = readlimit; markpos = pos; } @@ -567,22 +485,7 @@ private void implMark(int readlimit) { * method, or an I/O error occurs. * @see java.io.BufferedInputStream#mark(int) */ - public void reset() throws IOException { - if (lock != null) { - lock.lock(); - try { - implReset(); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implReset(); - } - } - } - - private void implReset() throws IOException { + public synchronized void reset() throws IOException { ensureOpen(); if (markpos < 0) throw new IOException("Resetting to invalid mark"); @@ -628,23 +531,8 @@ public void close() throws IOException { } @Override - public long transferTo(OutputStream out) throws IOException { + public synchronized long transferTo(OutputStream out) throws IOException { Objects.requireNonNull(out, "out"); - if (lock != null) { - lock.lock(); - try { - return implTransferTo(out); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - return implTransferTo(out); - } - } - } - - private long implTransferTo(OutputStream out) throws IOException { if (getClass() == BufferedInputStream.class && markpos == -1) { int avail = count - pos; if (avail > 0) { diff --git a/src/java.base/share/classes/java/io/BufferedOutputStream.java b/src/java.base/share/classes/java/io/BufferedOutputStream.java index 687f0c91bc4f7..2ad9adad5ad25 100644 --- a/src/java.base/share/classes/java/io/BufferedOutputStream.java +++ b/src/java.base/share/classes/java/io/BufferedOutputStream.java @@ -26,7 +26,6 @@ package java.io; import java.util.Arrays; -import jdk.internal.misc.InternalLock; import jdk.internal.misc.VM; /** @@ -47,9 +46,6 @@ public class BufferedOutputStream extends FilterOutputStream { private static final int DEFAULT_INITIAL_BUFFER_SIZE = 512; private static final int DEFAULT_MAX_BUFFER_SIZE = 8192; - // initialized to null when BufferedOutputStream is sub-classed - private final InternalLock lock; - /** * The internal buffer where data is stored. */ @@ -90,12 +86,9 @@ private BufferedOutputStream(OutputStream out, int initialSize, int maxSize) { } if (getClass() == BufferedOutputStream.class) { - // use InternalLock and resizable buffer when not sub-classed - this.lock = InternalLock.newLockOrNull(); - this.buf = new byte[initialSize]; // resizable + // resizable when not sub-classed + this.buf = new byte[initialSize]; } else { - // use monitors and no resizing when sub-classed - this.lock = null; this.buf = new byte[maxSize]; } this.maxBufSize = maxSize; @@ -136,8 +129,6 @@ private void flushBuffer() throws IOException { * Grow buf to fit an additional len bytes if needed. * If possible, it grows by len+1 to avoid flushing when len bytes * are added. A no-op if the buffer is not resizable. - * - * This method should only be called while holding the lock. */ private void growIfNeeded(int len) { int neededSize = count + len + 1; @@ -157,22 +148,7 @@ private void growIfNeeded(int len) { * @throws IOException if an I/O error occurs. */ @Override - public void write(int b) throws IOException { - if (lock != null) { - lock.lock(); - try { - implWrite(b); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWrite(b); - } - } - } - - private void implWrite(int b) throws IOException { + public synchronized void write(int b) throws IOException { growIfNeeded(1); if (count >= buf.length) { flushBuffer(); @@ -198,22 +174,7 @@ private void implWrite(int b) throws IOException { * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override - public void write(byte[] b, int off, int len) throws IOException { - if (lock != null) { - lock.lock(); - try { - implWrite(b, off, len); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWrite(b, off, len); - } - } - } - - private void implWrite(byte[] b, int off, int len) throws IOException { + public synchronized void write(byte[] b, int off, int len) throws IOException { if (len >= maxBufSize) { /* If the request length exceeds the max size of the output buffer, flush the output buffer and then write the data directly. @@ -238,22 +199,7 @@ private void implWrite(byte[] b, int off, int len) throws IOException { * @see java.io.FilterOutputStream#out */ @Override - public void flush() throws IOException { - if (lock != null) { - lock.lock(); - try { - implFlush(); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implFlush(); - } - } - } - - private void implFlush() throws IOException { + public synchronized void flush() throws IOException { flushBuffer(); out.flush(); } diff --git a/src/java.base/share/classes/java/io/BufferedReader.java b/src/java.base/share/classes/java/io/BufferedReader.java index c2f6b89e08622..a51f0acaf007d 100644 --- a/src/java.base/share/classes/java/io/BufferedReader.java +++ b/src/java.base/share/classes/java/io/BufferedReader.java @@ -32,7 +32,6 @@ import java.util.Spliterators; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import jdk.internal.misc.InternalLock; /** * Reads text from a character-input stream, buffering characters so as to @@ -181,37 +180,23 @@ private void fill() throws IOException { * @throws IOException If an I/O error occurs */ public int read() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return implRead(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - return implRead(); - } - } - } - - private int implRead() throws IOException { - ensureOpen(); - for (;;) { - if (nextChar >= nChars) { - fill(); - if (nextChar >= nChars) - return -1; - } - if (skipLF) { - skipLF = false; - if (cb[nextChar] == '\n') { - nextChar++; - continue; + synchronized (lock) { + ensureOpen(); + for (;;) { + if (nextChar >= nChars) { + fill(); + if (nextChar >= nChars) + return -1; + } + if (skipLF) { + skipLF = false; + if (cb[nextChar] == '\n') { + nextChar++; + continue; + } } + return cb[nextChar++]; } - return cb[nextChar++]; } } @@ -296,36 +281,22 @@ private int read1(char[] cbuf, int off, int len) throws IOException { * @throws IOException {@inheritDoc} */ public int read(char[] cbuf, int off, int len) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return implRead(cbuf, off, len); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - return implRead(cbuf, off, len); + synchronized (lock) { + ensureOpen(); + Objects.checkFromIndexSize(off, len, cbuf.length); + if (len == 0) { + return 0; } - } - } - - private int implRead(char[] cbuf, int off, int len) throws IOException { - ensureOpen(); - Objects.checkFromIndexSize(off, len, cbuf.length); - if (len == 0) { - return 0; - } - int n = read1(cbuf, off, len); - if (n <= 0) return n; - while ((n < len) && in.ready()) { - int n1 = read1(cbuf, off + n, len - n); - if (n1 <= 0) break; - n += n1; + int n = read1(cbuf, off, len); + if (n <= 0) return n; + while ((n < len) && in.ready()) { + int n1 = read1(cbuf, off + n, len - n); + if (n1 <= 0) break; + n += n1; + } + return n; } - return n; } /** @@ -347,81 +318,67 @@ private int implRead(char[] cbuf, int off, int len) throws IOException { * @throws IOException If an I/O error occurs */ String readLine(boolean ignoreLF, boolean[] term) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return implReadLine(ignoreLF, term); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - return implReadLine(ignoreLF, term); - } - } - } + synchronized (lock) { + StringBuilder s = null; + int startChar; - private String implReadLine(boolean ignoreLF, boolean[] term) throws IOException { - StringBuilder s = null; - int startChar; + ensureOpen(); + boolean omitLF = ignoreLF || skipLF; + if (term != null) term[0] = false; - ensureOpen(); - boolean omitLF = ignoreLF || skipLF; - if (term != null) term[0] = false; + bufferLoop: + for (;;) { - bufferLoop: - for (;;) { - - if (nextChar >= nChars) - fill(); - if (nextChar >= nChars) { /* EOF */ - if (s != null && s.length() > 0) - return s.toString(); - else - return null; - } - boolean eol = false; - char c = 0; - int i; + if (nextChar >= nChars) + fill(); + if (nextChar >= nChars) { /* EOF */ + if (s != null && s.length() > 0) + return s.toString(); + else + return null; + } + boolean eol = false; + char c = 0; + int i; - /* Skip a leftover '\n', if necessary */ - if (omitLF && (cb[nextChar] == '\n')) - nextChar++; - skipLF = false; - omitLF = false; - - charLoop: - for (i = nextChar; i < nChars; i++) { - c = cb[i]; - if ((c == '\n') || (c == '\r')) { - if (term != null) term[0] = true; - eol = true; - break charLoop; + /* Skip a leftover '\n', if necessary */ + if (omitLF && (cb[nextChar] == '\n')) + nextChar++; + skipLF = false; + omitLF = false; + + charLoop: + for (i = nextChar; i < nChars; i++) { + c = cb[i]; + if ((c == '\n') || (c == '\r')) { + if (term != null) term[0] = true; + eol = true; + break charLoop; + } } - } - startChar = nextChar; - nextChar = i; + startChar = nextChar; + nextChar = i; - if (eol) { - String str; - if (s == null) { - str = new String(cb, startChar, i - startChar); - } else { - s.append(cb, startChar, i - startChar); - str = s.toString(); - } - nextChar++; - if (c == '\r') { - skipLF = true; + if (eol) { + String str; + if (s == null) { + str = new String(cb, startChar, i - startChar); + } else { + s.append(cb, startChar, i - startChar); + str = s.toString(); + } + nextChar++; + if (c == '\r') { + skipLF = true; + } + return str; } - return str; - } - if (s == null) - s = new StringBuilder(DEFAULT_EXPECTED_LINE_LENGTH); - s.append(cb, startChar, i - startChar); + if (s == null) + s = new StringBuilder(DEFAULT_EXPECTED_LINE_LENGTH); + s.append(cb, startChar, i - startChar); + } } } @@ -450,47 +407,33 @@ public long skip(long n) throws IOException { if (n < 0L) { throw new IllegalArgumentException("skip value is negative"); } - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return implSkip(n); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - return implSkip(n); - } - } - } - - private long implSkip(long n) throws IOException { - ensureOpen(); - long r = n; - while (r > 0) { - if (nextChar >= nChars) - fill(); - if (nextChar >= nChars) /* EOF */ - break; - if (skipLF) { - skipLF = false; - if (cb[nextChar] == '\n') { - nextChar++; + synchronized (lock) { + ensureOpen(); + long r = n; + while (r > 0) { + if (nextChar >= nChars) + fill(); + if (nextChar >= nChars) /* EOF */ + break; + if (skipLF) { + skipLF = false; + if (cb[nextChar] == '\n') { + nextChar++; + } + } + long d = nChars - nextChar; + if (r <= d) { + nextChar += (int)r; + r = 0; + break; + } + else { + r -= d; + nextChar = nChars; } } - long d = nChars - nextChar; - if (r <= d) { - nextChar += (int)r; - r = 0; - break; - } - else { - r -= d; - nextChar = nChars; - } + return n - r; } - return n - r; } /** @@ -501,42 +444,28 @@ private long implSkip(long n) throws IOException { * @throws IOException If an I/O error occurs */ public boolean ready() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return implReady(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - return implReady(); - } - } - } + synchronized (lock) { + ensureOpen(); - private boolean implReady() throws IOException { - ensureOpen(); - - /* - * If newline needs to be skipped and the next char to be read - * is a newline character, then just skip it right away. - */ - if (skipLF) { - /* Note that in.ready() will return true if and only if the next - * read on the stream will not block. + /* + * If newline needs to be skipped and the next char to be read + * is a newline character, then just skip it right away. */ - if (nextChar >= nChars && in.ready()) { - fill(); - } - if (nextChar < nChars) { - if (cb[nextChar] == '\n') - nextChar++; - skipLF = false; + if (skipLF) { + /* Note that in.ready() will return true if and only if the next + * read on the stream will not block. + */ + if (nextChar >= nChars && in.ready()) { + fill(); + } + if (nextChar < nChars) { + if (cb[nextChar] == '\n') + nextChar++; + skipLF = false; + } } + return (nextChar < nChars) || in.ready(); } - return (nextChar < nChars) || in.ready(); } /** @@ -566,28 +495,14 @@ public void mark(int readAheadLimit) throws IOException { if (readAheadLimit < 0) { throw new IllegalArgumentException("Read-ahead limit < 0"); } - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implMark(readAheadLimit); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implMark(readAheadLimit); - } + synchronized (lock) { + ensureOpen(); + this.readAheadLimit = readAheadLimit; + markedChar = nextChar; + markedSkipLF = skipLF; } } - private void implMark(int readAheadLimit) throws IOException { - ensureOpen(); - this.readAheadLimit = readAheadLimit; - markedChar = nextChar; - markedSkipLF = skipLF; - } - /** * Resets the stream to the most recent mark. * @@ -595,55 +510,27 @@ private void implMark(int readAheadLimit) throws IOException { * or if the mark has been invalidated */ public void reset() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implReset(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implReset(); - } + synchronized (lock) { + ensureOpen(); + if (markedChar < 0) + throw new IOException((markedChar == INVALIDATED) + ? "Mark invalid" + : "Stream not marked"); + nextChar = markedChar; + skipLF = markedSkipLF; } } - private void implReset() throws IOException { - ensureOpen(); - if (markedChar < 0) - throw new IOException((markedChar == INVALIDATED) - ? "Mark invalid" - : "Stream not marked"); - nextChar = markedChar; - skipLF = markedSkipLF; - } - public void close() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { + if (in == null) + return; try { - implClose(); + in.close(); } finally { - locker.unlock(); + in = null; + cb = null; } - } else { - synchronized (lock) { - implClose(); - } - } - } - - private void implClose() throws IOException { - if (in == null) - return; - try { - in.close(); - } finally { - in = null; - cb = null; } } diff --git a/src/java.base/share/classes/java/io/BufferedWriter.java b/src/java.base/share/classes/java/io/BufferedWriter.java index 17862a265ae82..e3f8a21fe60bb 100644 --- a/src/java.base/share/classes/java/io/BufferedWriter.java +++ b/src/java.base/share/classes/java/io/BufferedWriter.java @@ -27,7 +27,6 @@ import java.util.Arrays; import java.util.Objects; -import jdk.internal.misc.InternalLock; import jdk.internal.misc.VM; /** @@ -162,58 +161,30 @@ private void growIfNeeded(int len) { * may be invoked by PrintStream. */ void flushBuffer() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implFlushBuffer(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implFlushBuffer(); - } + synchronized (lock) { + ensureOpen(); + if (nextChar == 0) + return; + out.write(cb, 0, nextChar); + nextChar = 0; } } - private void implFlushBuffer() throws IOException { - ensureOpen(); - if (nextChar == 0) - return; - out.write(cb, 0, nextChar); - nextChar = 0; - } - /** * Writes a single character. * * @throws IOException If an I/O error occurs */ public void write(int c) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implWrite(c); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implWrite(c); - } + synchronized (lock) { + ensureOpen(); + growIfNeeded(1); + if (nextChar >= nChars) + flushBuffer(); + cb[nextChar++] = (char) c; } } - private void implWrite(int c) throws IOException { - ensureOpen(); - growIfNeeded(1); - if (nextChar >= nChars) - flushBuffer(); - cb[nextChar++] = (char) c; - } - /** * Our own little min method, to avoid loading java.lang.Math if we've run * out of file descriptors and we're trying to print a stack trace. @@ -245,46 +216,32 @@ private int min(int a, int b) { * @throws IOException If an I/O error occurs */ public void write(char[] cbuf, int off, int len) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implWrite(cbuf, off, len); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implWrite(cbuf, off, len); + synchronized (lock) { + ensureOpen(); + Objects.checkFromIndexSize(off, len, cbuf.length); + if (len == 0) { + return; } - } - } - private void implWrite(char[] cbuf, int off, int len) throws IOException { - ensureOpen(); - Objects.checkFromIndexSize(off, len, cbuf.length); - if (len == 0) { - return; - } - - if (len >= maxChars) { - /* If the request length exceeds the max size of the output buffer, - flush the buffer and then write the data directly. In this - way buffered streams will cascade harmlessly. */ - flushBuffer(); - out.write(cbuf, off, len); - return; - } - - growIfNeeded(len); - int b = off, t = off + len; - while (b < t) { - int d = min(nChars - nextChar, t - b); - System.arraycopy(cbuf, b, cb, nextChar, d); - b += d; - nextChar += d; - if (nextChar >= nChars) { + if (len >= maxChars) { + /* If the request length exceeds the max size of the output buffer, + flush the buffer and then write the data directly. In this + way buffered streams will cascade harmlessly. */ flushBuffer(); + out.write(cbuf, off, len); + return; + } + + growIfNeeded(len); + int b = off, t = off + len; + while (b < t) { + int d = min(nChars - nextChar, t - b); + System.arraycopy(cbuf, b, cb, nextChar, d); + b += d; + nextChar += d; + if (nextChar >= nChars) { + flushBuffer(); + } } } } @@ -312,35 +269,21 @@ private void implWrite(char[] cbuf, int off, int len) throws IOException { * @throws IOException If an I/O error occurs */ public void write(String s, int off, int len) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implWrite(s, off, len); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implWrite(s, off, len); + synchronized (lock) { + ensureOpen(); + growIfNeeded(len); + int b = off, t = off + len; + while (b < t) { + int d = min(nChars - nextChar, t - b); + s.getChars(b, b + d, cb, nextChar); + b += d; + nextChar += d; + if (nextChar >= nChars) + flushBuffer(); } } } - private void implWrite(String s, int off, int len) throws IOException { - ensureOpen(); - growIfNeeded(len); - int b = off, t = off + len; - while (b < t) { - int d = min(nChars - nextChar, t - b); - s.getChars(b, b + d, cb, nextChar); - b += d; - nextChar += d; - if (nextChar >= nChars) - flushBuffer(); - } - } - /** * Writes a line separator. The line separator string is defined by the * system property {@code line.separator}, and is not necessarily a single @@ -358,52 +301,24 @@ public void newLine() throws IOException { * @throws IOException If an I/O error occurs */ public void flush() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implFlush(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implFlush(); - } + synchronized (lock) { + flushBuffer(); + out.flush(); } } - private void implFlush() throws IOException { - flushBuffer(); - out.flush(); - } - + @SuppressWarnings("try") public void close() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implClose(); - } finally { - locker.unlock(); + synchronized (lock) { + if (out == null) { + return; } - } else { - synchronized (lock) { - implClose(); + try (Writer w = out) { + flushBuffer(); + } finally { + out = null; + cb = null; } } } - - @SuppressWarnings("try") - private void implClose() throws IOException { - if (out == null) { - return; - } - try (Writer w = out) { - flushBuffer(); - } finally { - out = null; - cb = null; - } - } } diff --git a/src/java.base/share/classes/java/io/Console.java b/src/java.base/share/classes/java/io/Console.java index 8ae4fc00773da..d8ba0439d4726 100644 --- a/src/java.base/share/classes/java/io/Console.java +++ b/src/java.base/share/classes/java/io/Console.java @@ -172,6 +172,19 @@ public Console println(Object obj) { throw newUnsupportedOperationException(); } + /** + * Terminates the current line in this console's output stream using + * {@link System#lineSeparator()} and then flushes the console. + * + * @return This console + * + * @since 24 + */ + @PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES) + public Console println() { + return println(""); + } + /** * Writes a string representation of the specified object to this console's * output stream and then flushes the console. @@ -214,6 +227,24 @@ public String readln(String prompt) { throw newUnsupportedOperationException(); } + /** + * Reads a single line of text from this console. + * + * @throws IOError + * If an I/O error occurs. + * + * @return A string containing the line read from the console, not + * including any line-termination characters, or {@code null} + * if an end of stream has been reached without having read + * any characters. + * + * @since 24 + */ + @PreviewFeature(feature = PreviewFeature.Feature.IMPLICIT_CLASSES) + public String readln() { + throw newUnsupportedOperationException(); + } + /** * Writes a formatted string to this console's output stream using * the specified format string and arguments with the diff --git a/src/java.base/share/classes/java/io/IO.java b/src/java.base/share/classes/java/io/IO.java index 7485f87f03fda..a49a51041fc04 100644 --- a/src/java.base/share/classes/java/io/IO.java +++ b/src/java.base/share/classes/java/io/IO.java @@ -63,6 +63,21 @@ public static void println(Object obj) { con().println(obj); } + /** + * Terminates the current line on the system console and then flushes + * that console. + * + *

The effect is as if {@link Console#println() println()} + * had been called on {@code System.console()}. + * + * @throws IOError if {@code System.console()} returns {@code null}, + * or if an I/O error occurs + * @since 24 + */ + public static void println() { + con().println(); + } + /** * Writes a string representation of the specified object to the system * console and then flushes that console. @@ -99,6 +114,24 @@ public static String readln(String prompt) { return con().readln(prompt); } + /** + * Reads a single line of text from the system console. + * + *

The effect is as if {@link Console#readln() readln()} + * had been called on {@code System.console()}. + * + * @return a string containing the line read from the system console, not + * including any line-termination characters. Returns {@code null} if an + * end of stream has been reached without having read any characters. + * + * @throws IOError if {@code System.console()} returns {@code null}, + * or if an I/O error occurs + * @since 24 + */ + public static String readln() { + return con().readln(); + } + private static Console con() { var con = System.console(); if (con != null) { diff --git a/src/java.base/share/classes/java/io/InputStreamReader.java b/src/java.base/share/classes/java/io/InputStreamReader.java index d3033b15b9f72..6d43c4ae0cdc6 100644 --- a/src/java.base/share/classes/java/io/InputStreamReader.java +++ b/src/java.base/share/classes/java/io/InputStreamReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, 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 @@ -28,7 +28,6 @@ import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; -import jdk.internal.misc.InternalLock; import sun.nio.cs.StreamDecoder; /** @@ -62,20 +61,6 @@ public class InputStreamReader extends Reader { private final StreamDecoder sd; - /** - * Return the lock object for the given reader's stream decoder. - * If the reader type is trusted then an internal lock can be used. If the - * reader type is not trusted then the reader object is the lock. - */ - private static Object lockFor(InputStreamReader reader) { - Class clazz = reader.getClass(); - if (clazz == InputStreamReader.class || clazz == FileReader.class) { - return InternalLock.newLockOr(reader); - } else { - return reader; - } - } - /** * Creates an InputStreamReader that uses the * {@link Charset#defaultCharset() default charset}. @@ -88,7 +73,7 @@ private static Object lockFor(InputStreamReader reader) { public InputStreamReader(InputStream in) { super(in); Charset cs = Charset.defaultCharset(); - sd = StreamDecoder.forInputStreamReader(in, lockFor(this), cs); + sd = StreamDecoder.forInputStreamReader(in, this, cs); } /** @@ -110,7 +95,7 @@ public InputStreamReader(InputStream in, String charsetName) super(in); if (charsetName == null) throw new NullPointerException("charsetName"); - sd = StreamDecoder.forInputStreamReader(in, lockFor(this), charsetName); + sd = StreamDecoder.forInputStreamReader(in, this, charsetName); } /** @@ -126,7 +111,7 @@ public InputStreamReader(InputStream in, Charset cs) { super(in); if (cs == null) throw new NullPointerException("charset"); - sd = StreamDecoder.forInputStreamReader(in, lockFor(this), cs); + sd = StreamDecoder.forInputStreamReader(in, this, cs); } /** @@ -142,7 +127,7 @@ public InputStreamReader(InputStream in, CharsetDecoder dec) { super(in); if (dec == null) throw new NullPointerException("charset decoder"); - sd = StreamDecoder.forInputStreamReader(in, lockFor(this), dec); + sd = StreamDecoder.forInputStreamReader(in, this, dec); } /** diff --git a/src/java.base/share/classes/java/io/OutputStreamWriter.java b/src/java.base/share/classes/java/io/OutputStreamWriter.java index cda9fead18e64..9a16aa140bc47 100644 --- a/src/java.base/share/classes/java/io/OutputStreamWriter.java +++ b/src/java.base/share/classes/java/io/OutputStreamWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, 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 @@ -28,7 +28,6 @@ import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; -import jdk.internal.misc.InternalLock; import sun.nio.cs.StreamEncoder; /** @@ -75,20 +74,6 @@ public class OutputStreamWriter extends Writer { private final StreamEncoder se; - /** - * Return the lock object for the given writer's stream encoder. - * If the writer type is trusted then an internal lock can be used. If the - * writer type is not trusted then the writer object is the lock. - */ - private static Object lockFor(OutputStreamWriter writer) { - Class clazz = writer.getClass(); - if (clazz == OutputStreamWriter.class || clazz == FileWriter.class) { - return InternalLock.newLockOr(writer); - } else { - return writer; - } - } - /** * Creates an OutputStreamWriter that uses the named charset. * @@ -108,7 +93,7 @@ public OutputStreamWriter(OutputStream out, String charsetName) super(out); if (charsetName == null) throw new NullPointerException("charsetName"); - se = StreamEncoder.forOutputStreamWriter(out, lockFor(this), charsetName); + se = StreamEncoder.forOutputStreamWriter(out, this, charsetName); } /** @@ -122,7 +107,7 @@ public OutputStreamWriter(OutputStream out, String charsetName) @SuppressWarnings("this-escape") public OutputStreamWriter(OutputStream out) { super(out); - se = StreamEncoder.forOutputStreamWriter(out, lockFor(this), + se = StreamEncoder.forOutputStreamWriter(out, this, out instanceof PrintStream ps ? ps.charset() : Charset.defaultCharset()); } @@ -142,7 +127,7 @@ public OutputStreamWriter(OutputStream out, Charset cs) { super(out); if (cs == null) throw new NullPointerException("charset"); - se = StreamEncoder.forOutputStreamWriter(out, lockFor(this), cs); + se = StreamEncoder.forOutputStreamWriter(out, this, cs); } /** @@ -161,7 +146,7 @@ public OutputStreamWriter(OutputStream out, CharsetEncoder enc) { super(out); if (enc == null) throw new NullPointerException("charset encoder"); - se = StreamEncoder.forOutputStreamWriter(out, lockFor(this), enc); + se = StreamEncoder.forOutputStreamWriter(out, this, enc); } /** diff --git a/src/java.base/share/classes/java/io/PrintStream.java b/src/java.base/share/classes/java/io/PrintStream.java index 3096f2356f52f..0c1dd20e6685f 100644 --- a/src/java.base/share/classes/java/io/PrintStream.java +++ b/src/java.base/share/classes/java/io/PrintStream.java @@ -30,9 +30,6 @@ import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; -import jdk.internal.access.JavaIOPrintStreamAccess; -import jdk.internal.access.SharedSecrets; -import jdk.internal.misc.InternalLock; /** * A {@code PrintStream} adds functionality to another output stream, @@ -67,9 +64,6 @@ public class PrintStream extends FilterOutputStream implements Appendable, Closeable { - // initialized to null when PrintStream is sub-classed - private final InternalLock lock; - private final boolean autoFlush; private boolean trouble = false; private Formatter formatter; @@ -117,13 +111,6 @@ private PrintStream(boolean autoFlush, OutputStream out) { this.charset = out instanceof PrintStream ps ? ps.charset() : Charset.defaultCharset(); this.charOut = new OutputStreamWriter(this, charset); this.textOut = new BufferedWriter(charOut); - - // use monitors when PrintStream is sub-classed - if (getClass() == PrintStream.class) { - lock = InternalLock.newLockOrNull(); - } else { - lock = null; - } } /* Variant of the private constructor so that the given charset name @@ -220,13 +207,6 @@ public PrintStream(OutputStream out, boolean autoFlush, Charset charset) { this.charOut = new OutputStreamWriter(this, charset); this.textOut = new BufferedWriter(charOut); this.charset = charset; - - // use monitors when PrintStream is sub-classed - if (getClass() == PrintStream.class) { - lock = InternalLock.newLockOrNull(); - } else { - lock = null; - } } /** @@ -420,30 +400,17 @@ private void ensureOpen() throws IOException { */ @Override public void flush() { - if (lock != null) { - lock.lock(); + synchronized (this) { try { - implFlush(); - } finally { - lock.unlock(); + ensureOpen(); + out.flush(); } - } else { - synchronized (this) { - implFlush(); + catch (IOException x) { + trouble = true; } } } - private void implFlush() { - try { - ensureOpen(); - out.flush(); - } - catch (IOException x) { - trouble = true; - } - } - private boolean closing = false; /* To avoid recursive closing */ /** @@ -454,33 +421,20 @@ private void implFlush() { */ @Override public void close() { - if (lock != null) { - lock.lock(); - try { - implClose(); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implClose(); - } - } - } - - private void implClose() { - if (!closing) { - closing = true; - try { - textOut.close(); - out.close(); - } - catch (IOException x) { - trouble = true; + synchronized (this) { + if (!closing) { + closing = true; + try { + textOut.close(); + out.close(); + } + catch (IOException x) { + trouble = true; + } + textOut = null; + charOut = null; + out = null; } - textOut = null; - charOut = null; - out = null; } } @@ -547,17 +501,11 @@ protected void clearError() { @Override public void write(int b) { try { - if (lock != null) { - lock.lock(); - try { - implWrite(b); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWrite(b); - } + synchronized (this) { + ensureOpen(); + out.write(b); + if ((b == '\n') && autoFlush) + out.flush(); } } catch (InterruptedIOException x) { @@ -568,13 +516,6 @@ public void write(int b) { } } - private void implWrite(int b) throws IOException { - ensureOpen(); - out.write(b); - if ((b == '\n') && autoFlush) - out.flush(); - } - /** * Writes {@code len} bytes from the specified byte array starting at * offset {@code off} to this stream. If automatic flushing is @@ -593,17 +534,11 @@ private void implWrite(int b) throws IOException { @Override public void write(byte[] buf, int off, int len) { try { - if (lock != null) { - lock.lock(); - try { - implWrite(buf, off, len); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWrite(buf, off, len); - } + synchronized (this) { + ensureOpen(); + out.write(buf, off, len); + if (autoFlush) + out.flush(); } } catch (InterruptedIOException x) { @@ -614,14 +549,6 @@ public void write(byte[] buf, int off, int len) { } } - private void implWrite(byte[] buf, int off, int len) throws IOException { - ensureOpen(); - out.write(buf, off, len); - if (autoFlush) - out.flush(); - } - - /** * Writes all bytes from the specified byte array to this stream. If * automatic flushing is enabled then the {@code flush} method will be @@ -686,16 +613,17 @@ public void writeBytes(byte[] buf) { private void write(char[] buf) { try { - if (lock != null) { - lock.lock(); - try { - implWrite(buf); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWrite(buf); + synchronized (this) { + ensureOpen(); + textOut.write(buf); + textOut.flushBuffer(); + charOut.flushBuffer(); + if (autoFlush) { + for (int i = 0; i < buf.length; i++) + if (buf[i] == '\n') { + out.flush(); + break; + } } } } catch (InterruptedIOException x) { @@ -705,37 +633,20 @@ private void write(char[] buf) { } } - private void implWrite(char[] buf) throws IOException { - ensureOpen(); - textOut.write(buf); - textOut.flushBuffer(); - charOut.flushBuffer(); - if (autoFlush) { - for (int i = 0; i < buf.length; i++) - if (buf[i] == '\n') { - out.flush(); - break; - } - } - } - // Used to optimize away back-to-back flushing and synchronization when // using println, but since subclasses could exist which depend on // observing a call to print followed by newLine() we only use this if // getClass() == PrintStream.class to avoid compatibility issues. private void writeln(char[] buf) { try { - if (lock != null) { - lock.lock(); - try { - implWriteln(buf); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWriteln(buf); - } + synchronized (this) { + ensureOpen(); + textOut.write(buf); + textOut.newLine(); + textOut.flushBuffer(); + charOut.flushBuffer(); + if (autoFlush) + out.flush(); } } catch (InterruptedIOException x) { @@ -746,29 +657,15 @@ private void writeln(char[] buf) { } } - private void implWriteln(char[] buf) throws IOException { - ensureOpen(); - textOut.write(buf); - textOut.newLine(); - textOut.flushBuffer(); - charOut.flushBuffer(); - if (autoFlush) - out.flush(); - } - private void write(String s) { try { - if (lock != null) { - lock.lock(); - try { - implWrite(s); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWrite(s); - } + synchronized (this) { + ensureOpen(); + textOut.write(s); + textOut.flushBuffer(); + charOut.flushBuffer(); + if (autoFlush && (s.indexOf('\n') >= 0)) + out.flush(); } } catch (InterruptedIOException x) { @@ -779,32 +676,20 @@ private void write(String s) { } } - private void implWrite(String s) throws IOException { - ensureOpen(); - textOut.write(s); - textOut.flushBuffer(); - charOut.flushBuffer(); - if (autoFlush && (s.indexOf('\n') >= 0)) - out.flush(); - } - // Used to optimize away back-to-back flushing and synchronization when // using println, but since subclasses could exist which depend on // observing a call to print followed by newLine we only use this if // getClass() == PrintStream.class to avoid compatibility issues. private void writeln(String s) { try { - if (lock != null) { - lock.lock(); - try { - implWriteln(s); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implWriteln(s); - } + synchronized (this) { + ensureOpen(); + textOut.write(s); + textOut.newLine(); + textOut.flushBuffer(); + charOut.flushBuffer(); + if (autoFlush) + out.flush(); } } catch (InterruptedIOException x) { @@ -815,29 +700,15 @@ private void writeln(String s) { } } - private void implWriteln(String s) throws IOException { - ensureOpen(); - textOut.write(s); - textOut.newLine(); - textOut.flushBuffer(); - charOut.flushBuffer(); - if (autoFlush) - out.flush(); - } - private void newLine() { try { - if (lock != null) { - lock.lock(); - try { - implNewLine(); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implNewLine(); - } + synchronized (this) { + ensureOpen(); + textOut.newLine(); + textOut.flushBuffer(); + charOut.flushBuffer(); + if (autoFlush) + out.flush(); } } catch (InterruptedIOException x) { @@ -848,15 +719,6 @@ private void newLine() { } } - private void implNewLine() throws IOException { - ensureOpen(); - textOut.newLine(); - textOut.flushBuffer(); - charOut.flushBuffer(); - if (autoFlush) - out.flush(); - } - /* Methods that do not terminate lines */ /** @@ -1314,17 +1176,11 @@ public PrintStream printf(Locale l, String format, Object ... args) { */ public PrintStream format(String format, Object ... args) { try { - if (lock != null) { - lock.lock(); - try { - implFormat(format, args); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implFormat(format, args); - } + synchronized (this) { + ensureOpen(); + if ((formatter == null) || (formatter.locale() != Locale.getDefault(Locale.Category.FORMAT))) + formatter = new Formatter((Appendable) this); + formatter.format(Locale.getDefault(Locale.Category.FORMAT), format, args); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); @@ -1334,13 +1190,6 @@ public PrintStream format(String format, Object ... args) { return this; } - private void implFormat(String format, Object ... args) throws IOException { - ensureOpen(); - if ((formatter == null) || (formatter.locale() != Locale.getDefault(Locale.Category.FORMAT))) - formatter = new Formatter((Appendable) this); - formatter.format(Locale.getDefault(Locale.Category.FORMAT), format, args); - } - /** * Writes a formatted string to this output stream using the specified * format string and arguments. @@ -1383,17 +1232,11 @@ private void implFormat(String format, Object ... args) throws IOException { */ public PrintStream format(Locale l, String format, Object ... args) { try { - if (lock != null) { - lock.lock(); - try { - implFormat(l, format, args); - } finally { - lock.unlock(); - } - } else { - synchronized (this) { - implFormat(l, format, args); - } + synchronized (this) { + ensureOpen(); + if ((formatter == null) || (formatter.locale() != l)) + formatter = new Formatter(this, l); + formatter.format(l, format, args); } } catch (InterruptedIOException x) { Thread.currentThread().interrupt(); @@ -1403,13 +1246,6 @@ public PrintStream format(Locale l, String format, Object ... args) { return this; } - private void implFormat(Locale l, String format, Object ... args) throws IOException { - ensureOpen(); - if ((formatter == null) || (formatter.locale() != l)) - formatter = new Formatter(this, l); - formatter.format(l, format, args); - } - /** * Appends the specified character sequence to this output stream. * @@ -1511,13 +1347,4 @@ public PrintStream append(char c) { public Charset charset() { return charset; } - - static { - SharedSecrets.setJavaIOCPrintStreamAccess(new JavaIOPrintStreamAccess() { - public Object lock(PrintStream ps) { - Object lock = ps.lock; - return (lock != null) ? lock : ps; - } - }); - } } diff --git a/src/java.base/share/classes/java/io/PrintWriter.java b/src/java.base/share/classes/java/io/PrintWriter.java index 55baa2e0a5701..dd6deb75ab70a 100644 --- a/src/java.base/share/classes/java/io/PrintWriter.java +++ b/src/java.base/share/classes/java/io/PrintWriter.java @@ -31,9 +31,6 @@ import java.nio.charset.Charset; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; -import jdk.internal.access.JavaIOPrintWriterAccess; -import jdk.internal.access.SharedSecrets; -import jdk.internal.misc.InternalLock; /** * Prints formatted representations of objects to a text-output stream. This @@ -377,30 +374,16 @@ private void ensureOpen() throws IOException { * @see #checkError() */ public void flush() { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implFlush(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implFlush(); + ensureOpen(); + out.flush(); + } catch (IOException x) { + trouble = true; } } } - private void implFlush() { - try { - ensureOpen(); - out.flush(); - } catch (IOException x) { - trouble = true; - } - } - /** * Closes the stream and releases any system resources associated * with it. Closing a previously closed stream has no effect. @@ -408,32 +391,18 @@ private void implFlush() { * @see #checkError() */ public void close() { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implClose(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implClose(); + if (out != null) { + out.close(); + out = null; + } + } catch (IOException x) { + trouble = true; } } } - private void implClose() { - try { - if (out != null) { - out.close(); - out = null; - } - } catch (IOException x) { - trouble = true; - } - } - /** * Flushes the stream if it's not closed and checks its error state. * @@ -487,32 +456,18 @@ protected void clearError() { * @param c int specifying a character to be written. */ public void write(int c) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implWrite(c); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implWrite(c); + ensureOpen(); + out.write(c); + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + trouble = true; } } } - private void implWrite(int c) { - try { - ensureOpen(); - out.write(c); - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - trouble = true; - } - } - /** * Writes A Portion of an array of characters. * @param buf Array of characters @@ -525,29 +480,15 @@ private void implWrite(int c) { * to throw an {@code IndexOutOfBoundsException} */ public void write(char[] buf, int off, int len) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implWrite(buf, off, len); - } finally { - locker.unlock(); + ensureOpen(); + out.write(buf, off, len); + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + trouble = true; } - } else { - synchronized (lock) { - implWrite(buf, off, len); - } - } - } - - private void implWrite(char[] buf, int off, int len) { - try { - ensureOpen(); - out.write(buf, off, len); - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - trouble = true; } } @@ -572,29 +513,15 @@ public void write(char[] buf) { * to throw an {@code IndexOutOfBoundsException} */ public void write(String s, int off, int len) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implWrite(s, off, len); - } finally { - locker.unlock(); + ensureOpen(); + out.write(s, off, len); + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + trouble = true; } - } else { - synchronized (lock) { - implWrite(s, off, len); - } - } - } - - private void implWrite(String s, int off, int len) { - try { - ensureOpen(); - out.write(s, off, len); - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - trouble = true; } } @@ -608,34 +535,20 @@ public void write(String s) { } private void newLine() { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implNewLine(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implNewLine(); + ensureOpen(); + out.write(System.lineSeparator()); + if (autoFlush) + out.flush(); + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + trouble = true; } } } - private void implNewLine() { - try { - ensureOpen(); - out.write(System.lineSeparator()); - if (autoFlush) - out.flush(); - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - trouble = true; - } - } - /* Methods that do not terminate lines */ /** @@ -788,20 +701,9 @@ public void println() { * @param x the {@code boolean} value to be printed */ public void println(boolean x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -813,20 +715,9 @@ public void println(boolean x) { * @param x the {@code char} value to be printed */ public void println(char x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -838,20 +729,9 @@ public void println(char x) { * @param x the {@code int} value to be printed */ public void println(int x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -863,20 +743,9 @@ public void println(int x) { * @param x the {@code long} value to be printed */ public void println(long x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -888,20 +757,9 @@ public void println(long x) { * @param x the {@code float} value to be printed */ public void println(float x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -913,20 +771,9 @@ public void println(float x) { * @param x the {@code double} value to be printed */ public void println(double x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -938,20 +785,9 @@ public void println(double x) { * @param x the array of {@code char} values to be printed */ public void println(char[] x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -963,20 +799,9 @@ public void println(char[] x) { * @param x the {@code String} value to be printed */ public void println(String x) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(x); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(x); - println(); - } + synchronized (lock) { + print(x); + println(); } } @@ -991,20 +816,9 @@ public void println(String x) { */ public void println(Object x) { String s = String.valueOf(x); - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - print(s); - println(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - print(s); - println(); - } + synchronized (lock) { + print(s); + println(); } } @@ -1150,38 +964,24 @@ public PrintWriter printf(Locale l, String format, Object ... args) { * @since 1.5 */ public PrintWriter format(String format, Object ... args) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implFormat(format, args); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implFormat(format, args); + ensureOpen(); + if ((formatter == null) + || (formatter.locale() != Locale.getDefault())) + formatter = new Formatter(this); + formatter.format(Locale.getDefault(), format, args); + if (autoFlush) + out.flush(); + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + trouble = true; } } return this; } - private void implFormat(String format, Object ... args) { - try { - ensureOpen(); - if ((formatter == null) - || (formatter.locale() != Locale.getDefault())) - formatter = new Formatter(this); - formatter.format(Locale.getDefault(), format, args); - if (autoFlush) - out.flush(); - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - trouble = true; - } - } - /** * Writes a formatted string to this writer using the specified format * string and arguments. If automatic flushing is enabled, calls to this @@ -1224,37 +1024,23 @@ private void implFormat(String format, Object ... args) { * @since 1.5 */ public PrintWriter format(Locale l, String format, Object ... args) { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { try { - implFormat(l, format, args); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implFormat(l, format, args); + ensureOpen(); + if ((formatter == null) || (formatter.locale() != l)) + formatter = new Formatter(this, l); + formatter.format(l, format, args); + if (autoFlush) + out.flush(); + } catch (InterruptedIOException x) { + Thread.currentThread().interrupt(); + } catch (IOException x) { + trouble = true; } } return this; } - private void implFormat(Locale l, String format, Object ... args) { - try { - ensureOpen(); - if ((formatter == null) || (formatter.locale() != l)) - formatter = new Formatter(this, l); - formatter.format(l, format, args); - if (autoFlush) - out.flush(); - } catch (InterruptedIOException x) { - Thread.currentThread().interrupt(); - } catch (IOException x) { - trouble = true; - } - } - /** * Appends the specified character sequence to this writer. * @@ -1346,12 +1132,4 @@ public PrintWriter append(char c) { write(c); return this; } - - static { - SharedSecrets.setJavaIOCPrintWriterAccess(new JavaIOPrintWriterAccess() { - public Object lock(PrintWriter pw) { - return pw.lock; - } - }); - } } diff --git a/src/java.base/share/classes/java/io/ProxyingConsole.java b/src/java.base/share/classes/java/io/ProxyingConsole.java index 1babceb665fa9..cc5cd92626470 100644 --- a/src/java.base/share/classes/java/io/ProxyingConsole.java +++ b/src/java.base/share/classes/java/io/ProxyingConsole.java @@ -117,6 +117,18 @@ public String readln(String prompt) { } } + /** + * {@inheritDoc} + * + * @throws IOError {@inheritDoc} + */ + @Override + public String readln() { + synchronized (readLock) { + return delegate.readln(); + } + } + /** * {@inheritDoc} */ diff --git a/src/java.base/share/classes/java/io/PushbackInputStream.java b/src/java.base/share/classes/java/io/PushbackInputStream.java index 0c74205ba0e11..5aa0e133df97e 100644 --- a/src/java.base/share/classes/java/io/PushbackInputStream.java +++ b/src/java.base/share/classes/java/io/PushbackInputStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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 @@ -27,7 +27,6 @@ import java.util.Arrays; import java.util.Objects; -import jdk.internal.misc.InternalLock; /** * A {@code PushbackInputStream} adds @@ -54,10 +53,6 @@ * @since 1.0 */ public class PushbackInputStream extends FilterInputStream { - - // initialized to null when PushbackInputStream is sub-classed - private final InternalLock closeLock; - /** * The pushback buffer. * @since 1.1 @@ -101,13 +96,6 @@ public PushbackInputStream(InputStream in, int size) { } this.buf = new byte[size]; this.pos = size; - - // use monitors when PushbackInputStream is sub-classed - if (getClass() == PushbackInputStream.class) { - closeLock = InternalLock.newLockOrNull(); - } else { - closeLock = null; - } } /** @@ -386,27 +374,12 @@ public void reset() throws IOException { * * @throws IOException if an I/O error occurs. */ - public void close() throws IOException { - if (closeLock != null) { - closeLock.lock(); - try { - implClose(); - } finally { - closeLock.unlock(); - } - } else { - synchronized (this) { - implClose(); - } - } - } - - private void implClose() throws IOException { - if (in != null) { - in.close(); - in = null; - buf = null; - } + public synchronized void close() throws IOException { + if (in == null) + return; + in.close(); + in = null; + buf = null; } @Override diff --git a/src/java.base/share/classes/java/io/Reader.java b/src/java.base/share/classes/java/io/Reader.java index 9fca28a3a96cf..1654156bee19a 100644 --- a/src/java.base/share/classes/java/io/Reader.java +++ b/src/java.base/share/classes/java/io/Reader.java @@ -28,7 +28,6 @@ import java.nio.CharBuffer; import java.nio.ReadOnlyBufferException; import java.util.Objects; -import jdk.internal.misc.InternalLock; /** * Abstract class for reading character streams. The only methods that a @@ -283,21 +282,6 @@ protected Reader(Object lock) { this.lock = lock; } - /** - * For use by BufferedReader to create a character-stream reader that uses an - * internal lock when BufferedReader is not extended and the given reader is - * trusted, otherwise critical sections will synchronize on the given reader. - */ - Reader(Reader in) { - Class clazz = in.getClass(); - if (getClass() == BufferedReader.class && - (clazz == InputStreamReader.class || clazz == FileReader.class)) { - this.lock = InternalLock.newLockOr(in); - } else { - this.lock = in; - } - } - /** * Attempts to read characters into the specified character buffer. * The buffer is used as a repository of characters as-is: the only @@ -429,33 +413,19 @@ public int read(char[] cbuf) throws IOException { public long skip(long n) throws IOException { if (n < 0L) throw new IllegalArgumentException("skip value is negative"); - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return implSkip(n); - } finally { - locker.unlock(); + synchronized (lock) { + int nn = (int) Math.min(n, maxSkipBufferSize); + if ((skipBuffer == null) || (skipBuffer.length < nn)) + skipBuffer = new char[nn]; + long r = n; + while (r > 0) { + int nc = read(skipBuffer, 0, (int)Math.min(r, nn)); + if (nc == -1) + break; + r -= nc; } - } else { - synchronized (lock) { - return implSkip(n); - } - } - } - - private long implSkip(long n) throws IOException { - int nn = (int) Math.min(n, maxSkipBufferSize); - if ((skipBuffer == null) || (skipBuffer.length < nn)) - skipBuffer = new char[nn]; - long r = n; - while (r > 0) { - int nc = read(skipBuffer, 0, (int)Math.min(r, nn)); - if (nc == -1) - break; - r -= nc; + return n - r; } - return n - r; } /** diff --git a/src/java.base/share/classes/java/io/Writer.java b/src/java.base/share/classes/java/io/Writer.java index 62fe6b053e5ef..433a116a4bbcd 100644 --- a/src/java.base/share/classes/java/io/Writer.java +++ b/src/java.base/share/classes/java/io/Writer.java @@ -26,7 +26,6 @@ package java.io; import java.util.Objects; -import jdk.internal.misc.InternalLock; /** * Abstract class for writing to character streams. The only methods that a @@ -162,21 +161,6 @@ protected Writer() { this.lock = this; } - /** - * For use by BufferedWriter to create a character-stream writer that uses an - * internal lock when BufferedWriter is not extended and the given writer is - * trusted, otherwise critical sections will synchronize on the given writer. - */ - Writer(Writer writer) { - Class clazz = writer.getClass(); - if (getClass() == BufferedWriter.class && - (clazz == OutputStreamWriter.class || clazz == FileWriter.class)) { - this.lock = InternalLock.newLockOr(writer); - } else { - this.lock = writer; - } - } - /** * Creates a new character-stream writer whose critical sections will * synchronize on the given object. @@ -206,29 +190,15 @@ protected Writer(Object lock) { * If an I/O error occurs */ public void write(int c) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implWrite(c); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implWrite(c); + synchronized (lock) { + if (writeBuffer == null){ + writeBuffer = new char[WRITE_BUFFER_SIZE]; } + writeBuffer[0] = (char) c; + write(writeBuffer, 0, 1); } } - private void implWrite(int c) throws IOException { - if (writeBuffer == null){ - writeBuffer = new char[WRITE_BUFFER_SIZE]; - } - writeBuffer[0] = (char) c; - write(writeBuffer, 0, 1); - } - /** * Writes an array of characters. * @@ -305,33 +275,19 @@ public void write(String str) throws IOException { * If an I/O error occurs */ public void write(String str, int off, int len) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - implWrite(str, off, len); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - implWrite(str, off, len); - } - } - } - - private void implWrite(String str, int off, int len) throws IOException { - char cbuf[]; - if (len <= WRITE_BUFFER_SIZE) { - if (writeBuffer == null) { - writeBuffer = new char[WRITE_BUFFER_SIZE]; + synchronized (lock) { + char cbuf[]; + if (len <= WRITE_BUFFER_SIZE) { + if (writeBuffer == null) { + writeBuffer = new char[WRITE_BUFFER_SIZE]; + } + cbuf = writeBuffer; + } else { // Don't permanently allocate very large buffers. + cbuf = new char[len]; } - cbuf = writeBuffer; - } else { // Don't permanently allocate very large buffers. - cbuf = new char[len]; + str.getChars(off, (off + len), cbuf, 0); + write(cbuf, 0, len); } - str.getChars(off, (off + len), cbuf, 0); - write(cbuf, 0, len); } /** diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java index bb091235646bd..ba63f2d538f8a 100644 --- a/src/java.base/share/classes/java/lang/Class.java +++ b/src/java.base/share/classes/java/lang/Class.java @@ -30,7 +30,6 @@ import java.lang.constant.ConstantDescs; import java.lang.invoke.TypeDescriptor; import java.lang.invoke.MethodHandles; -import java.lang.module.ModuleReader; import java.lang.ref.SoftReference; import java.io.IOException; import java.io.InputStream; @@ -54,9 +53,7 @@ import java.lang.reflect.TypeVariable; import java.lang.constant.Constable; import java.net.URL; -import java.security.AccessController; import java.security.Permissions; -import java.security.PrivilegedAction; import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.Arrays; @@ -73,10 +70,8 @@ import java.util.stream.Collectors; import jdk.internal.constant.ConstantUtils; -import jdk.internal.javac.PreviewFeature; import jdk.internal.loader.BootLoader; import jdk.internal.loader.BuiltinClassLoader; -import jdk.internal.misc.PreviewFeatures; import jdk.internal.misc.Unsafe; import jdk.internal.module.Resources; import jdk.internal.reflect.CallerSensitive; @@ -84,7 +79,6 @@ import jdk.internal.reflect.ConstantPool; import jdk.internal.reflect.Reflection; import jdk.internal.reflect.ReflectionFactory; -import jdk.internal.vm.annotation.ForceInline; import jdk.internal.vm.annotation.IntrinsicCandidate; import jdk.internal.vm.annotation.Stable; @@ -540,41 +534,10 @@ private static Class forName(String className, Class caller) * @jls 13.1 The Form of a Binary * @since 1.2 */ - @CallerSensitive - public static Class forName(String name, boolean initialize, - ClassLoader loader) + public static Class forName(String name, boolean initialize, ClassLoader loader) throws ClassNotFoundException { - Class caller = null; - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - // Reflective call to get caller class is only needed if a security manager - // is present. Avoid the overhead of making this call otherwise. - caller = Reflection.getCallerClass(); - } - return forName(name, initialize, loader, caller); - } - - // Caller-sensitive adapter method for reflective invocation - @CallerSensitiveAdapter - private static Class forName(String name, boolean initialize, ClassLoader loader, Class caller) - throws ClassNotFoundException - { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - // Reflective call to get caller class is only needed if a security manager - // is present. Avoid the overhead of making this call otherwise. - if (loader == null) { - ClassLoader ccl = ClassLoader.getClassLoader(caller); - if (ccl != null) { - sm.checkPermission( - SecurityConstants.GET_CLASSLOADER_PERMISSION); - } - } - } - return forName0(name, initialize, loader, caller); + return forName0(name, initialize, loader, null); } /** Called after security check for system loader access checks have been made. */ @@ -620,38 +583,11 @@ private static native Class forName0(String name, boolean initialize, * @jls 12.3 Linking of Classes and Interfaces * @since 9 */ - @SuppressWarnings("removal") - @CallerSensitive public static Class forName(Module module, String name) { - Class caller = null; - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - caller = Reflection.getCallerClass(); - } - return forName(module, name, caller); - } - - // Caller-sensitive adapter method for reflective invocation - @SuppressWarnings("removal") - @CallerSensitiveAdapter - private static Class forName(Module module, String name, Class caller) { Objects.requireNonNull(module); Objects.requireNonNull(name); - ClassLoader cl; - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - if (caller != null && caller.getModule() != module) { - // if caller is null, Class.forName is the last java frame on the stack. - // java.base has all permissions - sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); - } - PrivilegedAction pa = module::getClassLoader; - cl = AccessController.doPrivileged(pa); - } else { - cl = module.getClassLoader(); - } - + ClassLoader cl = module.getClassLoader(); if (cl != null) { return cl.loadClass(module, name); } else { @@ -740,17 +676,11 @@ public static Class forPrimitiveName(String primitiveName) { * @throws ExceptionInInitializerError if the initialization * provoked by this method fails. */ - @SuppressWarnings("removal") @CallerSensitive @Deprecated(since="9") public T newInstance() throws InstantiationException, IllegalAccessException { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false); - } - // Constructor lookup Constructor tmpConstructor = cachedConstructor; if (tmpConstructor == null) { @@ -765,13 +695,7 @@ public T newInstance() getConstructor0(empty, Member.DECLARED)); // Disable accessibility checks on the constructor // access check is done with the true caller - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction<>() { - public Void run() { - c.setAccessible(true); - return null; - } - }); + c.setAccessible(true); cachedConstructor = tmpConstructor = c; } catch (NoSuchMethodException e) { throw (InstantiationException) @@ -1035,18 +959,8 @@ public String getName() { * represented by this {@code Class} object. * @see java.lang.ClassLoader */ - @CallerSensitive - @ForceInline // to ensure Reflection.getCallerClass optimization public ClassLoader getClassLoader() { - ClassLoader cl = classLoader; - if (cl == null) - return null; - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - ClassLoader.checkClassLoaderPermission(cl, Reflection.getCallerClass()); - } - return cl; + return classLoader; } // Package-private to allow ClassLoader access @@ -1511,7 +1425,6 @@ void setSigners(Object[] signers) { * * @since 1.5 */ - @CallerSensitive public Method getEnclosingMethod() { EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo(); @@ -1533,14 +1446,7 @@ public Method getEnclosingMethod() { for(int i = 0; i < parameterClasses.length; i++) parameterClasses[i] = toClass(parameterTypes[i]); - // Perform access check final Class enclosingCandidate = enclosingInfo.getEnclosingClass(); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - enclosingCandidate.checkMemberAccess(sm, Member.DECLARED, - Reflection.getCallerClass(), true); - } Method[] candidates = enclosingCandidate.privateGetDeclaredMethods(false); /* @@ -1648,7 +1554,6 @@ private static Class toClass(Type o) { * * @since 1.5 */ - @CallerSensitive public Constructor getEnclosingConstructor() { EnclosingMethodInfo enclosingInfo = getEnclosingMethodInfo(); @@ -1666,18 +1571,11 @@ public Constructor getEnclosingConstructor() { // Convert Types to Classes; returned types *should* // be class objects since the methodDescriptor's used // don't have generics information - for(int i = 0; i < parameterClasses.length; i++) + for (int i = 0; i < parameterClasses.length; i++) parameterClasses[i] = toClass(parameterTypes[i]); - // Perform access check - final Class enclosingCandidate = enclosingInfo.getEnclosingClass(); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - enclosingCandidate.checkMemberAccess(sm, Member.DECLARED, - Reflection.getCallerClass(), true); - } + final Class enclosingCandidate = enclosingInfo.getEnclosingClass(); Constructor[] candidates = enclosingCandidate .privateGetDeclaredConstructors(false); /* @@ -1708,19 +1606,8 @@ public Constructor getEnclosingConstructor() { * @return the declaring class for this class * @since 1.1 */ - @CallerSensitive public Class getDeclaringClass() { - final Class candidate = getDeclaringClass0(); - - if (candidate != null) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - candidate.checkPackageAccess(sm, - ClassLoader.getClassLoader(Reflection.getCallerClass()), true); - } - } - return candidate; + return getDeclaringClass0(); } private native Class getDeclaringClass0(); @@ -1733,7 +1620,6 @@ public Class getDeclaringClass() { * @return the immediately enclosing class of the underlying class * @since 1.5 */ - @CallerSensitive public Class getEnclosingClass() { // There are five kinds of classes (or interfaces): // a) Top level classes @@ -1760,15 +1646,6 @@ public Class getEnclosingClass() { else enclosingCandidate = enclosingClass; } - - if (enclosingCandidate != null) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - enclosingCandidate.checkPackageAccess(sm, - ClassLoader.getClassLoader(Reflection.getCallerClass()), true); - } - } return enclosingCandidate; } @@ -1991,36 +1868,18 @@ private boolean hasEnclosingMethodInfo() { * members of this class * @since 1.1 */ - @SuppressWarnings("removal") - @CallerSensitive public Class[] getClasses() { - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), false); - } - - // Privileged so this implementation can look at DECLARED classes, - // something the caller might not have privilege to do. The code here - // is allowed to look at DECLARED classes because (1) it does not hand - // out anything other than public members and (2) public member access - // has already been ok'd by the SecurityManager. - - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction<>() { - public Class[] run() { - List> list = new ArrayList<>(); - Class currentClass = Class.this; - while (currentClass != null) { - for (Class m : currentClass.getDeclaredClasses()) { - if (Modifier.isPublic(m.getModifiers())) { - list.add(m); - } - } - currentClass = currentClass.getSuperclass(); - } - return list.toArray(new Class[0]); + List> list = new ArrayList<>(); + Class currentClass = Class.this; + while (currentClass != null) { + for (Class m : currentClass.getDeclaredClasses()) { + if (Modifier.isPublic(m.getModifiers())) { + list.add(m); } - }); + } + currentClass = currentClass.getSuperclass(); + } + return list.toArray(new Class[0]); } @@ -2054,13 +1913,7 @@ public Class[] run() { * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ - @CallerSensitive public Field[] getFields() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true); - } return copyFields(privateGetPublicFields()); } @@ -2138,13 +1991,7 @@ public Field[] getFields() { * @jls 8.4 Method Declarations * @since 1.1 */ - @CallerSensitive public Method[] getMethods() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true); - } return copyMethods(privateGetPublicMethods()); } @@ -2173,13 +2020,7 @@ public Method[] getMethods() { * @see #getDeclaredConstructors() * @since 1.1 */ - @CallerSensitive public Constructor[] getConstructors() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true); - } return copyConstructors(privateGetDeclaredConstructors(true)); } @@ -2219,14 +2060,8 @@ public Constructor[] getConstructors() { * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ - @CallerSensitive public Field getField(String name) throws NoSuchFieldException { Objects.requireNonNull(name); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true); - } Field field = getField0(name); if (field == null) { throw new NoSuchFieldException(name); @@ -2322,15 +2157,9 @@ public Field getField(String name) throws NoSuchFieldException { * @jls 8.4 Method Declarations * @since 1.1 */ - @CallerSensitive public Method getMethod(String name, Class... parameterTypes) throws NoSuchMethodException { Objects.requireNonNull(name); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true); - } Method method = getMethod0(name, parameterTypes); if (method == null) { throw new NoSuchMethodException(methodToString(name, parameterTypes)); @@ -2363,14 +2192,8 @@ public Method getMethod(String name, Class... parameterTypes) * @see #getDeclaredConstructor(Class[]) * @since 1.1 */ - @CallerSensitive public Constructor getConstructor(Class... parameterTypes) throws NoSuchMethodException { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.PUBLIC, Reflection.getCallerClass(), true); - } return getReflectionFactory().copyConstructor( getConstructor0(parameterTypes, Member.PUBLIC)); } @@ -2392,13 +2215,7 @@ public Constructor getConstructor(Class... parameterTypes) * @since 1.1 * @jls 8.5 Member Class and Interface Declarations */ - @CallerSensitive public Class[] getDeclaredClasses() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), false); - } return getDeclaredClasses0(); } @@ -2425,13 +2242,7 @@ public Class[] getDeclaredClasses() { * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ - @CallerSensitive public Field[] getDeclaredFields() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true); - } return copyFields(privateGetDeclaredFields(false)); } @@ -2467,13 +2278,7 @@ public Field[] getDeclaredFields() { * @jls 8.10 Record Classes * @since 16 */ - @CallerSensitive public RecordComponent[] getRecordComponents() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true); - } if (!isRecord()) { return null; } @@ -2519,13 +2324,7 @@ public RecordComponent[] getRecordComponents() { * programming language and JVM modeling in core reflection * @since 1.1 */ - @CallerSensitive public Method[] getDeclaredMethods() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true); - } return copyMethods(privateGetDeclaredMethods(false)); } @@ -2550,13 +2349,7 @@ public Method[] getDeclaredMethods() { * @see #getConstructors() * @jls 8.8 Constructor Declarations */ - @CallerSensitive public Constructor[] getDeclaredConstructors() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true); - } return copyConstructors(privateGetDeclaredConstructors(false)); } @@ -2581,14 +2374,8 @@ public Constructor[] getDeclaredConstructors() { * @jls 8.2 Class Members * @jls 8.3 Field Declarations */ - @CallerSensitive public Field getDeclaredField(String name) throws NoSuchFieldException { Objects.requireNonNull(name); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true); - } Field field = searchFields(privateGetDeclaredFields(false), name); if (field == null) { throw new NoSuchFieldException(name); @@ -2626,15 +2413,9 @@ public Field getDeclaredField(String name) throws NoSuchFieldException { * @jls 8.4 Method Declarations * @since 1.1 */ - @CallerSensitive public Method getDeclaredMethod(String name, Class... parameterTypes) throws NoSuchMethodException { Objects.requireNonNull(name); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true); - } Method method = searchMethods(privateGetDeclaredMethods(false), name, parameterTypes); if (method == null) { throw new NoSuchMethodException(methodToString(name, parameterTypes)); @@ -2703,15 +2484,8 @@ Method findMethod(boolean publicOnly, String name, Class... parameterTypes) { * @see #getConstructor(Class[]) * @since 1.1 */ - @CallerSensitive public Constructor getDeclaredConstructor(Class... parameterTypes) throws NoSuchMethodException { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkMemberAccess(sm, Member.DECLARED, Reflection.getCallerClass(), true); - } - return getReflectionFactory().copyConstructor( getConstructor0(parameterTypes, Member.DECLARED)); } @@ -2933,11 +2707,6 @@ private boolean isOpenToCaller(String name, Class caller) { * @since 1.2 */ public ProtectionDomain getProtectionDomain() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(SecurityConstants.GET_PD_PERMISSION); - } return protectionDomain(); } @@ -2972,91 +2741,6 @@ ProtectionDomain protectionDomain() { */ static native Class getPrimitiveClass(String name); - /* - * Check if client is allowed to access members. If access is denied, - * throw a SecurityException. - * - * This method also enforces package access. - * - *

Default policy: allow all clients access with normal Java access - * control. - * - *

NOTE: should only be called if a SecurityManager is installed - */ - private void checkMemberAccess(@SuppressWarnings("removal") SecurityManager sm, int which, - Class caller, boolean checkProxyInterfaces) { - /* Default policy allows access to all {@link Member#PUBLIC} members, - * as well as access to classes that have the same class loader as the caller. - * In all other cases, it requires RuntimePermission("accessDeclaredMembers") - * permission. - */ - final ClassLoader ccl = ClassLoader.getClassLoader(caller); - if (which != Member.PUBLIC) { - final ClassLoader cl = classLoader; - if (ccl != cl) { - sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); - } - } - this.checkPackageAccess(sm, ccl, checkProxyInterfaces); - } - - /* - * Checks if a client loaded in ClassLoader ccl is allowed to access this - * class under the current package access policy. If access is denied, - * throw a SecurityException. - * - * NOTE: this method should only be called if a SecurityManager is active - */ - private void checkPackageAccess(@SuppressWarnings("removal") SecurityManager sm, final ClassLoader ccl, - boolean checkProxyInterfaces) { - final ClassLoader cl = classLoader; - - if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) { - String pkg = this.getPackageName(); - if (!pkg.isEmpty()) { - // skip the package access check on a proxy class in default proxy package - if (!Proxy.isProxyClass(this) || ReflectUtil.isNonPublicProxyClass(this)) { - sm.checkPackageAccess(pkg); - } - } - } - // check package access on the proxy interfaces - if (checkProxyInterfaces && Proxy.isProxyClass(this)) { - ReflectUtil.checkProxyPackageAccess(ccl, this.getInterfaces(/* cloneArray */ false)); - } - } - - /* - * Checks if a client loaded in ClassLoader ccl is allowed to access the provided - * classes under the current package access policy. If access is denied, - * throw a SecurityException. - * - * NOTE: this method should only be called if a SecurityManager is active - * classes must be non-empty - * all classes provided must be loaded by the same ClassLoader - * NOTE: this method does not support Proxy classes - */ - private static void checkPackageAccessForPermittedSubclasses(@SuppressWarnings("removal") SecurityManager sm, - final ClassLoader ccl, Class[] subClasses) { - final ClassLoader cl = subClasses[0].classLoader; - - if (ReflectUtil.needsPackageAccessCheck(ccl, cl)) { - Set packages = new HashSet<>(); - - for (Class c : subClasses) { - if (Proxy.isProxyClass(c)) - throw new InternalError("a permitted subclass should not be a proxy class: " + c); - String pkg = c.getPackageName(); - if (!pkg.isEmpty()) { - packages.add(pkg); - } - } - for (String pkg : packages) { - sm.checkPackageAccess(pkg); - } - } - } - /** * Add a package name prefix if the name is not absolute. Remove leading "/" * if name is absolute @@ -3732,15 +3416,12 @@ public boolean isRecord() { } // Fetches the factory for reflective objects - @SuppressWarnings("removal") private static ReflectionFactory getReflectionFactory() { var factory = reflectionFactory; if (factory != null) { return factory; } - return reflectionFactory = - java.security.AccessController.doPrivileged - (new ReflectionFactory.GetReflectionFactoryAction()); + return reflectionFactory = ReflectionFactory.getReflectionFactory(); } private static ReflectionFactory reflectionFactory; @@ -3766,20 +3447,13 @@ public T[] getEnumConstants() { * identical to getEnumConstants except that the result is * uncloned, cached, and shared by all callers. */ - @SuppressWarnings("removal") T[] getEnumConstantsShared() { T[] constants = enumConstants; if (constants == null) { if (!isEnum()) return null; try { final Method values = getMethod("values"); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction<>() { - public Void run() { - values.setAccessible(true); - return null; - } - }); + values.setAccessible(true); @SuppressWarnings("unchecked") T[] temporaryConstants = (T[])values.invoke(null); enumConstants = constants = temporaryConstants; @@ -4160,24 +3834,11 @@ public AnnotatedType[] getAnnotatedInterfaces() { * @jvms 4.7.29 The {@code NestMembers} Attribute * @jvms 5.4.4 Access Control */ - @CallerSensitive public Class getNestHost() { if (isPrimitive() || isArray()) { return this; } - - Class host = getNestHost0(); - if (host == this) { - return this; - } - // returning a different class requires a security check - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkPackageAccess(sm, - ClassLoader.getClassLoader(Reflection.getCallerClass()), true); - } - return host; + return getNestHost0(); } /** @@ -4244,7 +3905,6 @@ public boolean isNestmateOf(Class c) { * @jvms 4.7.28 The {@code NestHost} Attribute * @jvms 4.7.29 The {@code NestMembers} Attribute */ - @CallerSensitive public Class[] getNestMembers() { if (isPrimitive() || isArray()) { return new Class[] { this }; @@ -4252,17 +3912,6 @@ public Class[] getNestMembers() { Class[] members = getNestMembers0(); // Can't actually enable this due to bootstrapping issues // assert(members.length != 1 || members[0] == this); // expected invariant from VM - - if (members.length > 1) { - // If we return anything other than the current class we need - // a security check - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkPackageAccess(sm, - ClassLoader.getClassLoader(Reflection.getCallerClass()), true); - } - } return members; } @@ -4432,7 +4081,6 @@ public Optional describeConstable() { * @jls 9.1 Interface Declarations * @since 17 */ - @CallerSensitive public Class[] getPermittedSubclasses() { Class[] subClasses; if (isArray() || isPrimitive() || (subClasses = getPermittedSubclasses0()) == null) { @@ -4445,16 +4093,6 @@ public Class[] getPermittedSubclasses() { .toArray(s -> new Class[s]); } } - if (subClasses.length > 0) { - // If we return some classes we need a security check: - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkPackageAccessForPermittedSubclasses(sm, - ClassLoader.getClassLoader(Reflection.getCallerClass()), - subClasses); - } - } return subClasses; } diff --git a/src/java.base/share/classes/java/lang/ClassLoader.java b/src/java.base/share/classes/java/lang/ClassLoader.java index 85fc315c76715..55341635d8af9 100644 --- a/src/java.base/share/classes/java/lang/ClassLoader.java +++ b/src/java.base/share/classes/java/lang/ClassLoader.java @@ -64,7 +64,6 @@ import jdk.internal.reflect.CallerSensitiveAdapter; import jdk.internal.reflect.Reflection; import jdk.internal.util.StaticProperty; -import sun.security.util.SecurityConstants; /** * A class loader is an object that is responsible for loading classes. The @@ -357,12 +356,6 @@ private static Void checkCreateClassLoader(String name) { if (name != null && name.isEmpty()) { throw new IllegalArgumentException("name must be non-empty or null"); } - - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkCreateClassLoader(); - } return null; } @@ -1735,18 +1728,7 @@ public static InputStream getSystemResourceAsStream(String name) { * * @since 1.2 */ - @CallerSensitive public final ClassLoader getParent() { - if (parent == null) - return null; - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - // Check access to the parent class loader - // If the caller's class loader is same as this class loader, - // permission check is performed. - checkClassLoaderPermission(parent, Reflection.getCallerClass()); - } return parent; } @@ -1774,15 +1756,8 @@ public final Module getUnnamedModule() { * * @since 9 */ - @CallerSensitive public static ClassLoader getPlatformClassLoader() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - ClassLoader loader = getBuiltinPlatformClassLoader(); - if (sm != null) { - checkClassLoaderPermission(loader, Reflection.getCallerClass()); - } - return loader; + return getBuiltinPlatformClassLoader(); } /** @@ -1853,7 +1828,6 @@ public static ClassLoader getPlatformClassLoader() { * underlying cause of the error can be retrieved via the * {@link Throwable#getCause()} method. */ - @CallerSensitive public static ClassLoader getSystemClassLoader() { switch (VM.initLevel()) { case 0: @@ -1867,11 +1841,6 @@ public static ClassLoader getSystemClassLoader() { default: // system fully initialized assert VM.isBooted() && scl != null; - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - checkClassLoaderPermission(scl, Reflection.getCallerClass()); - } return scl; } } @@ -1902,8 +1871,6 @@ static synchronized ClassLoader initSystemClassLoader() { } ClassLoader builtinLoader = getBuiltinAppClassLoader(); - - // All are privileged frames. No need to call doPrivileged. String cn = System.getProperty("java.system.class.loader"); if (cn != null) { try { @@ -1930,36 +1897,6 @@ static synchronized ClassLoader initSystemClassLoader() { return scl; } - // Returns true if the specified class loader can be found in this class - // loader's delegation chain. - boolean isAncestor(ClassLoader cl) { - ClassLoader acl = this; - do { - acl = acl.parent; - if (cl == acl) { - return true; - } - } while (acl != null); - return false; - } - - // Tests if class loader access requires "getClassLoader" permission - // check. A class loader 'from' can access class loader 'to' if - // class loader 'from' is same as class loader 'to' or an ancestor - // of 'to'. The class loader in a system domain can access - // any class loader. - private static boolean needsClassLoaderPermissionCheck(ClassLoader from, - ClassLoader to) - { - if (from == to) - return false; - - if (from == null) - return false; - - return !to.isAncestor(from); - } - // Returns the class's class loader, or null if none. static ClassLoader getClassLoader(Class caller) { // This can be null if the VM is requesting it @@ -1970,23 +1907,6 @@ static ClassLoader getClassLoader(Class caller) { return caller.getClassLoader0(); } - /* - * Checks RuntimePermission("getClassLoader") permission - * if caller's class loader is not null and caller's class loader - * is not the same as or an ancestor of the given cl argument. - */ - static void checkClassLoaderPermission(ClassLoader cl, Class caller) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - // caller can be null if the VM is requesting it - ClassLoader ccl = getClassLoader(caller); - if (needsClassLoaderPermissionCheck(ccl, cl)) { - sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); - } - } - } - // The system class loader // @GuardedBy("ClassLoader.class") private static volatile ClassLoader scl; diff --git a/src/java.base/share/classes/java/lang/Module.java b/src/java.base/share/classes/java/lang/Module.java index a90fbc992602b..4f9c09bace492 100644 --- a/src/java.base/share/classes/java/lang/Module.java +++ b/src/java.base/share/classes/java/lang/Module.java @@ -39,8 +39,6 @@ import java.lang.reflect.AnnotatedElement; import java.net.URI; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -64,14 +62,12 @@ import jdk.internal.misc.Unsafe; import jdk.internal.misc.VM; import jdk.internal.module.ModuleBootstrap; -import jdk.internal.module.ModuleBootstrap.IllegalNativeAccess; import jdk.internal.module.ModuleLoaderMap; import jdk.internal.module.ServicesCatalog; import jdk.internal.module.Resources; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; import jdk.internal.vm.annotation.Stable; -import sun.security.util.SecurityConstants; /** * Represents a run-time module, either {@link #isNamed() named} or unnamed. @@ -198,11 +194,6 @@ public String getName() { * @return The class loader for this module */ public ClassLoader getClassLoader() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); - } return loader; } @@ -1556,7 +1547,6 @@ public Annotation[] getDeclaredAnnotations() { // cached class file with annotations private volatile Class moduleInfoClass; - @SuppressWarnings("removal") private Class moduleInfoClass() { Class clazz = this.moduleInfoClass; if (clazz != null) @@ -1566,8 +1556,7 @@ private Class moduleInfoClass() { clazz = this.moduleInfoClass; if (clazz == null) { if (isNamed()) { - PrivilegedAction> pa = this::loadModuleInfoClass; - clazz = AccessController.doPrivileged(pa); + clazz = loadModuleInfoClass(); } if (clazz == null) { class DummyModuleInfo { } diff --git a/src/java.base/share/classes/java/lang/ModuleLayer.java b/src/java.base/share/classes/java/lang/ModuleLayer.java index 4ee2b02414dee..5dfd93796d2a4 100644 --- a/src/java.base/share/classes/java/lang/ModuleLayer.java +++ b/src/java.base/share/classes/java/lang/ModuleLayer.java @@ -44,7 +44,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import jdk.internal.javac.PreviewFeature; import jdk.internal.javac.Restricted; import jdk.internal.loader.ClassLoaderValue; import jdk.internal.loader.Loader; @@ -54,7 +53,6 @@ import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; import jdk.internal.vm.annotation.Stable; -import sun.security.util.SecurityConstants; /** * A layer of modules in the Java virtual machine. @@ -505,9 +503,6 @@ public static Controller defineModulesWithOneLoader(Configuration cf, List parents = List.copyOf(parentLayers); checkConfiguration(cf, parents); - checkCreateClassLoaderPermission(); - checkGetClassLoaderPermission(); - try { Loader loader = new Loader(cf.modules(), parentLoader); loader.initRemotePackageMap(cf, parents); @@ -572,9 +567,6 @@ public static Controller defineModulesWithManyLoaders(Configuration cf, List parents = List.copyOf(parentLayers); checkConfiguration(cf, parents); - checkCreateClassLoaderPermission(); - checkGetClassLoaderPermission(); - LoaderPool pool = new LoaderPool(cf, parents, parentLoader); try { ModuleLayer layer = new ModuleLayer(cf, parents, pool::loaderFor); @@ -654,8 +646,6 @@ public static Controller defineModules(Configuration cf, checkConfiguration(cf, parents); Objects.requireNonNull(clf); - checkGetClassLoaderPermission(); - // The boot layer is checked during module system initialization if (boot() != null) { checkForDuplicatePkgs(cf, clf); @@ -693,20 +683,6 @@ private static void checkConfiguration(Configuration cf, } } - private static void checkCreateClassLoaderPermission() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(SecurityConstants.CREATE_CLASSLOADER_PERMISSION); - } - - private static void checkGetClassLoaderPermission() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); - } - /** * Checks a configuration and the module-to-loader mapping to ensure that * no two modules mapped to the same class loader have the same package. diff --git a/src/java.base/share/classes/java/lang/Package.java b/src/java.base/share/classes/java/lang/Package.java index d48320a66cf52..424c390c8ef37 100644 --- a/src/java.base/share/classes/java/lang/Package.java +++ b/src/java.base/share/classes/java/lang/Package.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -30,8 +30,6 @@ import java.net.MalformedURLException; import java.net.URI; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Objects; import jdk.internal.loader.BootLoader; @@ -417,9 +415,7 @@ private Class getPackageInfo() { // find package-info.class defined by loader String cn = packageName() + ".package-info"; Module module = module(); - PrivilegedAction pa = module::getClassLoader; - @SuppressWarnings("removal") - ClassLoader loader = AccessController.doPrivileged(pa); + ClassLoader loader = module.getClassLoader(); Class c; if (loader != null) { c = loader.loadClass(module, cn); diff --git a/src/java.base/share/classes/java/lang/ProcessBuilder.java b/src/java.base/share/classes/java/lang/ProcessBuilder.java index c3cb9bfd14515..9cb5848bdff55 100644 --- a/src/java.base/share/classes/java/lang/ProcessBuilder.java +++ b/src/java.base/share/classes/java/lang/ProcessBuilder.java @@ -339,11 +339,6 @@ public List command() { * @see System#getenv() */ public Map environment() { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) - security.checkPermission(new RuntimePermission("getenv.*")); - if (environment == null) environment = ProcessEnvironment.environment(); @@ -1069,11 +1064,6 @@ private Process start(Redirect[] redirects) throws IOException { // Throws IndexOutOfBoundsException if command is empty String prog = cmdarray[0]; - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) - security.checkExec(prog); - String dir = directory == null ? null : directory.toString(); for (String s : cmdarray) { @@ -1112,24 +1102,13 @@ private Process start(Redirect[] redirects) throws IOException { } return process; } catch (IOException | IllegalArgumentException e) { - String exceptionInfo = ": " + e.getMessage(); - Throwable cause = e; - if ((e instanceof IOException) && security != null) { - // Can not disclose the fail reason for read-protected files. - try { - security.checkRead(prog); - } catch (SecurityException se) { - exceptionInfo = ""; - cause = se; - } - } // It's much easier for us to create a high-quality error // message than the low-level C code which found the problem. throw new IOException( "Cannot run program \"" + prog + "\"" + (dir == null ? "" : " (in directory \"" + dir + "\")") - + exceptionInfo, - cause); + + ": " + e.getMessage(), + e); } } diff --git a/src/java.base/share/classes/java/lang/ProcessHandleImpl.java b/src/java.base/share/classes/java/lang/ProcessHandleImpl.java index 7dd6bf6a5e458..a7243b8b6f444 100644 --- a/src/java.base/share/classes/java/lang/ProcessHandleImpl.java +++ b/src/java.base/share/classes/java/lang/ProcessHandleImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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 @@ -84,28 +84,28 @@ final class ProcessHandleImpl implements ProcessHandle { /** * The thread pool of "process reaper" daemon threads. */ - @SuppressWarnings("removal") - private static final Executor processReaperExecutor = - AccessController.doPrivileged((PrivilegedAction) () -> { - // Initialize ThreadLocalRandom now to avoid using the smaller stack - // of the processReaper threads. - ThreadLocalRandom.current(); - - // For a debug build, the stack shadow zone is larger; - // Increase the total stack size to avoid potential stack overflow. - int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4*4096); - final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize") - ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta; - - ThreadFactory threadFactory = grimReaper -> { - Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper, - stackSize, Thread.MAX_PRIORITY); - privilegedThreadSetDaemon(t, true); - return t; - }; - - return Executors.newCachedThreadPool(threadFactory); - }); + private static final Executor processReaperExecutor = initReaper(); + + private static Executor initReaper() { + // Initialize ThreadLocalRandom now to avoid using the smaller stack + // of the processReaper threads. + ThreadLocalRandom.current(); + + // For a debug build, the stack shadow zone is larger; + // Increase the total stack size to avoid potential stack overflow. + int debugDelta = "release".equals(System.getProperty("jdk.debug")) ? 0 : (4 * 4096); + final long stackSize = Boolean.getBoolean("jdk.lang.processReaperUseDefaultStackSize") + ? 0 : REAPER_DEFAULT_STACKSIZE + debugDelta; + + ThreadFactory threadFactory = grimReaper -> { + Thread t = InnocuousThread.newSystemThread("process reaper", grimReaper, + stackSize, Thread.MAX_PRIORITY); + t.setDaemon(true); + return t; + }; + + return Executors.newCachedThreadPool(threadFactory); + } private static class ExitCompletion extends CompletableFuture { final boolean isReaping; @@ -115,22 +115,6 @@ private static class ExitCompletion extends CompletableFuture { } } - @SuppressWarnings("removal") - private static void privilegedThreadSetName(Thread thread, String name) { - AccessController.doPrivileged((PrivilegedAction) () -> { - thread.setName(name); - return null; - }); - } - - @SuppressWarnings("removal") - private static void privilegedThreadSetDaemon(Thread thread, boolean on) { - AccessController.doPrivileged((PrivilegedAction) () -> { - thread.setDaemon(on); - return null; - }); - } - /** * Returns a CompletableFuture that completes with process exit status when * the process completes. @@ -158,7 +142,7 @@ static CompletableFuture completion(long pid, boolean shouldReap) { public void run() { Thread t = Thread.currentThread(); String threadName = t.getName(); - privilegedThreadSetName(t, "process reaper (pid " + pid + ")"); + t.setName("process reaper (pid " + pid + ")"); try { int exitValue = waitForProcessExit0(pid, shouldReap); if (exitValue == NOT_A_CHILD) { @@ -189,7 +173,7 @@ public void run() { completions.remove(pid, newCompletion); } finally { // Restore thread name - privilegedThreadSetName(t, threadName); + t.setName(threadName); } } }); @@ -255,14 +239,8 @@ private ProcessHandleImpl(long pid, long startTime) { * @param pid the native process identifier * @return The ProcessHandle for the pid if the process is alive; * or {@code null} if the process ID does not exist in the native system. - * @throws SecurityException if RuntimePermission("manageProcess") is not granted */ static Optional get(long pid) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("manageProcess")); - } long start = isAlive0(pid); return (start >= 0) ? Optional.of(new ProcessHandleImpl(pid, start)) @@ -296,14 +274,8 @@ public long pid() { * Returns the ProcessHandle for the current native process. * * @return The ProcessHandle for the OS process. - * @throws SecurityException if RuntimePermission("manageProcess") is not granted */ public static ProcessHandleImpl current() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("manageProcess")); - } return current; } @@ -319,15 +291,8 @@ public static ProcessHandleImpl current() { * * @return a ProcessHandle of the parent process; {@code null} is returned * if the child process does not have a parent - * @throws SecurityException if permission is not granted by the - * security policy */ public Optional parent() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("manageProcess")); - } long ppid = parent0(pid, startTime); if (ppid <= 0) { return Optional.empty(); @@ -442,11 +407,6 @@ public Stream children() { * @return a stream of ProcessHandles */ static Stream children(long pid) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("manageProcess")); - } int size = 100; long[] childpids = null; long[] starttimes = null; @@ -463,11 +423,6 @@ static Stream children(long pid) { @Override public Stream descendants() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("manageProcess")); - } int size = 100; long[] pids = null; long[] ppids = null; diff --git a/src/java.base/share/classes/java/lang/PublicMethods.java b/src/java.base/share/classes/java/lang/PublicMethods.java index b9851e2f049f2..03b3ad86a7ab4 100644 --- a/src/java.base/share/classes/java/lang/PublicMethods.java +++ b/src/java.base/share/classes/java/lang/PublicMethods.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, 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 @@ -28,7 +28,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.security.AccessController; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; @@ -88,10 +87,7 @@ Method[] toArray() { * Method (name, parameter types) tuple. */ private static final class Key { - @SuppressWarnings("removal") - private static final ReflectionFactory reflectionFactory = - AccessController.doPrivileged( - new ReflectionFactory.GetReflectionFactoryAction()); + private static final ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory(); private final String name; // must be interned (as from Method.getName()) private final Class[] ptypes; diff --git a/src/java.base/share/classes/java/lang/StringLatin1.java b/src/java.base/share/classes/java/lang/StringLatin1.java index c12b8afc21f37..7680bcbfa45df 100644 --- a/src/java.base/share/classes/java/lang/StringLatin1.java +++ b/src/java.base/share/classes/java/lang/StringLatin1.java @@ -830,22 +830,22 @@ static Stream lines(byte[] value) { static void putCharsAt(byte[] val, int index, int c1, int c2, int c3, int c4) { assert index >= 0 && index + 3 < length(val) : "Trusted caller missed bounds check"; // Don't use the putChar method, Its instrinsic will cause C2 unable to combining values into larger stores. - long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + index; - UNSAFE.putByte(val, address , (byte)(c1)); - UNSAFE.putByte(val, address + 1, (byte)(c2)); - UNSAFE.putByte(val, address + 2, (byte)(c3)); - UNSAFE.putByte(val, address + 3, (byte)(c4)); + long offset = (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + UNSAFE.putByte(val, offset , (byte)(c1)); + UNSAFE.putByte(val, offset + 1, (byte)(c2)); + UNSAFE.putByte(val, offset + 2, (byte)(c3)); + UNSAFE.putByte(val, offset + 3, (byte)(c4)); } static void putCharsAt(byte[] val, int index, int c1, int c2, int c3, int c4, int c5) { assert index >= 0 && index + 4 < length(val) : "Trusted caller missed bounds check"; // Don't use the putChar method, Its instrinsic will cause C2 unable to combining values into larger stores. - long address = Unsafe.ARRAY_BYTE_BASE_OFFSET + index; - UNSAFE.putByte(val, address , (byte)(c1)); - UNSAFE.putByte(val, address + 1, (byte)(c2)); - UNSAFE.putByte(val, address + 2, (byte)(c3)); - UNSAFE.putByte(val, address + 3, (byte)(c4)); - UNSAFE.putByte(val, address + 4, (byte)(c5)); + long offset = (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + UNSAFE.putByte(val, offset , (byte)(c1)); + UNSAFE.putByte(val, offset + 1, (byte)(c2)); + UNSAFE.putByte(val, offset + 2, (byte)(c3)); + UNSAFE.putByte(val, offset + 3, (byte)(c4)); + UNSAFE.putByte(val, offset + 4, (byte)(c5)); } public static void putChar(byte[] val, int index, int c) { diff --git a/src/java.base/share/classes/java/lang/System.java b/src/java.base/share/classes/java/lang/System.java index 8b2e97ec73115..b5cea4236adab 100644 --- a/src/java.base/share/classes/java/lang/System.java +++ b/src/java.base/share/classes/java/lang/System.java @@ -47,7 +47,6 @@ import java.nio.channels.spi.SelectorProvider; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; -import java.security.AccessControlContext; import java.security.AccessController; import java.security.CodeSource; import java.security.PrivilegedAction; @@ -2134,9 +2133,6 @@ public void blockedOn(Interruptible b) { public void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook) { Shutdown.add(slot, registerShutdownInProgress, hook); } - public Thread newThreadWithAcc(Runnable target, @SuppressWarnings("removal") AccessControlContext acc) { - return new Thread(target, acc); - } @SuppressWarnings("removal") public void invokeFinalize(Object o) throws Throwable { o.finalize(); diff --git a/src/java.base/share/classes/java/lang/Thread.java b/src/java.base/share/classes/java/lang/Thread.java index 16b1272116971..7e54d04457991 100644 --- a/src/java.base/share/classes/java/lang/Thread.java +++ b/src/java.base/share/classes/java/lang/Thread.java @@ -27,9 +27,6 @@ import java.lang.ref.Reference; import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.AccessControlContext; -import java.security.PrivilegedAction; import java.time.Duration; import java.util.Map; import java.util.HashMap; @@ -41,8 +38,6 @@ import jdk.internal.misc.TerminatingThreadLocal; import jdk.internal.misc.Unsafe; import jdk.internal.misc.VM; -import jdk.internal.reflect.CallerSensitive; -import jdk.internal.reflect.Reflection; import jdk.internal.vm.Continuation; import jdk.internal.vm.ScopedValueContainer; import jdk.internal.vm.StackableScope; @@ -52,7 +47,6 @@ import jdk.internal.vm.annotation.IntrinsicCandidate; import jdk.internal.vm.annotation.Stable; import sun.nio.ch.Interruptible; -import sun.security.util.SecurityConstants; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -652,21 +646,6 @@ static long next() { } } - /** - * Returns the context class loader to inherit from the parent thread. - * See Thread initialization. - */ - private static ClassLoader contextClassLoader(Thread parent) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm == null || isCCLOverridden(parent.getClass())) { - return parent.getContextClassLoader(); - } else { - // skip call to getContextClassLoader - return parent.contextClassLoader; - } - } - /** * Initializes a platform Thread. * @@ -676,11 +655,8 @@ private static ClassLoader contextClassLoader(Thread parent) { * @param task the object whose run() method gets called * @param stackSize the desired stack size for the new thread, or * zero to indicate that this parameter is to be ignored. - * @param acc ignored */ - @SuppressWarnings("removal") - Thread(ThreadGroup g, String name, int characteristics, Runnable task, - long stackSize, AccessControlContext acc) { + Thread(ThreadGroup g, String name, int characteristics, Runnable task, long stackSize) { Thread parent = currentThread(); boolean attached = (parent == this); // primordial or JNI attached @@ -691,27 +667,10 @@ private static ClassLoader contextClassLoader(Thread parent) { } this.holder = new FieldHolder(g, task, stackSize, NORM_PRIORITY, false); } else { - SecurityManager sm = System.getSecurityManager(); if (g == null) { - // the security manager can choose the thread group - if (sm != null) { - g = sm.getThreadGroup(); - } - // default to current thread's group - if (g == null) { - g = parent.getThreadGroup(); - } + g = parent.getThreadGroup(); } - - // permission checks when creating a child Thread - if (sm != null) { - sm.checkAccess(g); - if (isCCLOverridden(getClass())) { - sm.checkPermission(SecurityConstants.SUBCLASS_IMPLEMENTATION_PERMISSION); - } - } - int priority = Math.min(parent.getPriority(), g.getMaxPriority()); this.holder = new FieldHolder(g, task, stackSize, priority, parent.isDaemon()); } @@ -732,7 +691,7 @@ private static ClassLoader contextClassLoader(Thread parent) { this.inheritableThreadLocals = ThreadLocal.createInheritedMap(parentMap); } if (VM.isBooted()) { - this.contextClassLoader = contextClassLoader(parent); + this.contextClassLoader = parent.getContextClassLoader(); } } else if (VM.isBooted()) { // default CCL to the system class loader when not inheriting @@ -763,7 +722,7 @@ private static ClassLoader contextClassLoader(Thread parent) { if (parentMap != null && parentMap.size() > 0) { this.inheritableThreadLocals = ThreadLocal.createInheritedMap(parentMap); } - this.contextClassLoader = contextClassLoader(parent); + this.contextClassLoader = parent.getContextClassLoader(); } else { // default CCL to the system class loader when not inheriting this.contextClassLoader = ClassLoader.getSystemClassLoader(); @@ -1105,7 +1064,7 @@ private static String checkName(String name) { * @see Inheritance when creating threads */ public Thread() { - this(null, null, 0, null, 0, null); + this(null, null, 0, null, 0); } /** @@ -1126,16 +1085,7 @@ public Thread() { * @see Inheritance when creating threads */ public Thread(Runnable task) { - this(null, null, 0, task, 0, null); - } - - /** - * Creates a new Thread that inherits the given AccessControlContext - * but thread-local variables are not inherited. - * This is not a public constructor. - */ - Thread(Runnable task, @SuppressWarnings("removal") AccessControlContext acc) { - this(null, null, 0, task, 0, acc); + this(null, null, 0, task, 0); } /** @@ -1160,7 +1110,7 @@ public Thread(Runnable task) { * @see Inheritance when creating threads */ public Thread(ThreadGroup group, Runnable task) { - this(group, null, 0, task, 0, null); + this(group, null, 0, task, 0); } /** @@ -1177,7 +1127,7 @@ public Thread(ThreadGroup group, Runnable task) { * @see Inheritance when creating threads */ public Thread(String name) { - this(null, checkName(name), 0, null, 0, null); + this(null, checkName(name), 0, null, 0); } /** @@ -1198,7 +1148,7 @@ public Thread(String name) { * @see Inheritance when creating threads */ public Thread(ThreadGroup group, String name) { - this(group, checkName(name), 0, null, 0, null); + this(group, checkName(name), 0, null, 0); } /** @@ -1220,7 +1170,7 @@ public Thread(ThreadGroup group, String name) { * @see Inheritance when creating threads */ public Thread(Runnable task, String name) { - this(null, checkName(name), 0, task, 0, null); + this(null, checkName(name), 0, task, 0); } /** @@ -1256,7 +1206,7 @@ public Thread(Runnable task, String name) { * @see Inheritance when creating threads */ public Thread(ThreadGroup group, Runnable task, String name) { - this(group, checkName(name), 0, task, 0, null); + this(group, checkName(name), 0, task, 0); } /** @@ -1330,7 +1280,7 @@ public Thread(ThreadGroup group, Runnable task, String name) { * @see Inheritance when creating threads */ public Thread(ThreadGroup group, Runnable task, String name, long stackSize) { - this(group, checkName(name), 0, task, stackSize, null); + this(group, checkName(name), 0, task, stackSize); } /** @@ -1390,7 +1340,7 @@ public Thread(ThreadGroup group, Runnable task, String name, long stackSize, boolean inheritInheritableThreadLocals) { this(group, checkName(name), (inheritInheritableThreadLocals ? 0 : NO_INHERIT_THREAD_LOCALS), - task, stackSize, null); + task, stackSize); } /** @@ -2140,18 +2090,8 @@ public String toString() { * * @since 1.2 */ - @CallerSensitive public ClassLoader getContextClassLoader() { - ClassLoader cl = this.contextClassLoader; - if (cl == null) - return null; - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - Class caller = Reflection.getCallerClass(); - ClassLoader.checkClassLoaderPermission(cl, caller); - } - return cl; + return contextClassLoader; } /** @@ -2167,11 +2107,6 @@ public ClassLoader getContextClassLoader() { * @since 1.2 */ public void setContextClassLoader(ClassLoader cl) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("setContextClassLoader")); - } contextClassLoader = cl; } @@ -2220,12 +2155,6 @@ public void setContextClassLoader(ClassLoader cl) { */ public StackTraceElement[] getStackTrace() { if (this != Thread.currentThread()) { - // check for getStackTrace permission - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkPermission(SecurityConstants.GET_STACK_TRACE_PERMISSION); - } // optimization so we do not call into the vm for threads that // have not yet started or have terminated if (!isAlive()) { @@ -2285,14 +2214,6 @@ StackTraceElement[] asyncGetStackTrace() { * @since 1.5 */ public static Map getAllStackTraces() { - // check for getStackTrace permission - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkPermission(SecurityConstants.GET_STACK_TRACE_PERMISSION); - security.checkPermission(SecurityConstants.MODIFY_THREADGROUP_PERMISSION); - } - // Get a snapshot of the list of all threads Thread[] threads = getThreads(); StackTraceElement[][] traces = dumpThreads(threads); @@ -2307,64 +2228,6 @@ public static Map getAllStackTraces() { return m; } - /** cache of subclass security audit results */ - private static class Caches { - /** cache of subclass security audit results */ - static final ClassValue subclassAudits = - new ClassValue<>() { - @Override - protected Boolean computeValue(Class type) { - return auditSubclass(type); - } - }; - } - - /** - * Verifies that this (possibly subclass) instance can be constructed - * without violating security constraints: the subclass must not override - * security-sensitive non-final methods, or else the - * "enableContextClassLoaderOverride" RuntimePermission is checked. - */ - private static boolean isCCLOverridden(Class cl) { - if (cl == Thread.class) - return false; - - return Caches.subclassAudits.get(cl); - } - - /** - * Performs reflective checks on given subclass to verify that it doesn't - * override security-sensitive non-final methods. Returns true if the - * subclass overrides any of the methods, false otherwise. - */ - private static boolean auditSubclass(final Class subcl) { - @SuppressWarnings("removal") - Boolean result = AccessController.doPrivileged( - new PrivilegedAction<>() { - public Boolean run() { - for (Class cl = subcl; - cl != Thread.class; - cl = cl.getSuperclass()) - { - try { - cl.getDeclaredMethod("getContextClassLoader", new Class[0]); - return Boolean.TRUE; - } catch (NoSuchMethodException ex) { - } - try { - Class[] params = {ClassLoader.class}; - cl.getDeclaredMethod("setContextClassLoader", params); - return Boolean.TRUE; - } catch (NoSuchMethodException ex) { - } - } - return Boolean.FALSE; - } - } - ); - return result.booleanValue(); - } - /** * Return an array of all live threads. */ @@ -2603,12 +2466,6 @@ public interface UncaughtExceptionHandler { * @since 1.5 */ public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler ueh) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission( - new RuntimePermission("setDefaultUncaughtExceptionHandler")); - } defaultUncaughtExceptionHandler = ueh; } @@ -2675,7 +2532,6 @@ void dispatchUncaughtException(Throwable e) { /** * Holder class for constants. */ - @SuppressWarnings("removal") private static class Constants { // Thread group for virtual threads. static final ThreadGroup VTHREAD_GROUP; diff --git a/src/java.base/share/classes/java/lang/ThreadBuilders.java b/src/java.base/share/classes/java/lang/ThreadBuilders.java index 234807d4cc2a7..62c29651d11ee 100644 --- a/src/java.base/share/classes/java/lang/ThreadBuilders.java +++ b/src/java.base/share/classes/java/lang/ThreadBuilders.java @@ -179,7 +179,7 @@ public OfPlatform stackSize(long stackSize) { public Thread unstarted(Runnable task) { Objects.requireNonNull(task); String name = nextThreadName(); - var thread = new Thread(group, name, characteristics(), task, stackSize, null); + var thread = new Thread(group, name, characteristics(), task, stackSize); if (daemonChanged) thread.daemon(daemon); if (priority != 0) @@ -353,7 +353,7 @@ String nextThreadName() { public Thread newThread(Runnable task) { Objects.requireNonNull(task); String name = nextThreadName(); - Thread thread = new Thread(group, name, characteristics(), task, stackSize, null); + Thread thread = new Thread(group, name, characteristics(), task, stackSize); if (daemonChanged) thread.daemon(daemon); if (priority != 0) diff --git a/src/java.base/share/classes/java/lang/Throwable.java b/src/java.base/share/classes/java/lang/Throwable.java index 275961a9a9f18..8c0ce29dbeefc 100644 --- a/src/java.base/share/classes/java/lang/Throwable.java +++ b/src/java.base/share/classes/java/lang/Throwable.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2024, 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 @@ -27,9 +27,7 @@ import java.io.*; import java.util.*; -import jdk.internal.access.SharedSecrets; import jdk.internal.event.ThrowableTracer; -import jdk.internal.misc.InternalLock; /** * The {@code Throwable} class is the superclass of all errors and @@ -689,39 +687,27 @@ public void printStackTrace(PrintStream s) { } private void printStackTrace(PrintStreamOrWriter s) { - Object lock = s.lock(); - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - lockedPrintStackTrace(s); - } finally { - locker.unlock(); - } - } else synchronized (lock) { - lockedPrintStackTrace(s); - } - } - - private void lockedPrintStackTrace(PrintStreamOrWriter s) { // Guard against malicious overrides of Throwable.equals by // using a Set with identity equality semantics. Set dejaVu = Collections.newSetFromMap(new IdentityHashMap<>()); dejaVu.add(this); - // Print our stack trace - s.println(this); - StackTraceElement[] trace = getOurStackTrace(); - for (StackTraceElement traceElement : trace) - s.println("\tat " + traceElement); + synchronized(s.lock()) { + // Print our stack trace + s.println(this); + StackTraceElement[] trace = getOurStackTrace(); + for (StackTraceElement traceElement : trace) + s.println("\tat " + traceElement); - // Print suppressed exceptions, if any - for (Throwable se : getSuppressed()) - se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu); + // Print suppressed exceptions, if any + for (Throwable se : getSuppressed()) + se.printEnclosedStackTrace(s, trace, SUPPRESSED_CAPTION, "\t", dejaVu); - // Print cause, if any - Throwable ourCause = getCause(); - if (ourCause != null) - ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu); + // Print cause, if any + Throwable ourCause = getCause(); + if (ourCause != null) + ourCause.printEnclosedStackTrace(s, trace, CAUSE_CAPTION, "", dejaVu); + } } /** @@ -733,7 +719,7 @@ private void printEnclosedStackTrace(PrintStreamOrWriter s, String caption, String prefix, Set dejaVu) { - assert s.isLockedByCurrentThread(); + assert Thread.holdsLock(s.lock()); if (dejaVu.contains(this)) { s.println(prefix + caption + "[CIRCULAR REFERENCE: " + this + "]"); } else { @@ -785,15 +771,6 @@ private abstract static class PrintStreamOrWriter { /** Returns the object to be locked when using this StreamOrWriter */ abstract Object lock(); - boolean isLockedByCurrentThread() { - Object lock = lock(); - if (lock instanceof InternalLock locker) { - return locker.isHeldByCurrentThread(); - } else { - return Thread.holdsLock(lock); - } - } - /** Prints the specified string as a line on this StreamOrWriter */ abstract void println(Object o); } @@ -806,7 +783,7 @@ private static class WrappedPrintStream extends PrintStreamOrWriter { } Object lock() { - return SharedSecrets.getJavaIOPrintStreamAccess().lock(printStream); + return printStream; } void println(Object o) { @@ -822,7 +799,7 @@ private static class WrappedPrintWriter extends PrintStreamOrWriter { } Object lock() { - return SharedSecrets.getJavaIOPrintWriterAccess().lock(printWriter); + return printWriter; } void println(Object o) { diff --git a/src/java.base/share/classes/java/lang/VirtualThread.java b/src/java.base/share/classes/java/lang/VirtualThread.java index 80838ff9d176e..1bf4367bed4c7 100644 --- a/src/java.base/share/classes/java/lang/VirtualThread.java +++ b/src/java.base/share/classes/java/lang/VirtualThread.java @@ -24,8 +24,6 @@ */ package java.lang; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Locale; import java.util.Objects; import java.util.concurrent.CountDownLatch; @@ -58,7 +56,6 @@ import jdk.internal.vm.annotation.JvmtiMountTransition; import jdk.internal.vm.annotation.ReservedStackAccess; import sun.nio.ch.Interruptible; -import sun.security.action.GetPropertyAction; import static java.util.concurrent.TimeUnit.*; /** @@ -1013,7 +1010,6 @@ void blockedOn(Interruptible b) { } @Override - @SuppressWarnings("removal") public void interrupt() { if (Thread.currentThread() != this) { // if current thread is a virtual thread then prevent it from being @@ -1409,39 +1405,32 @@ private void setCarrierThread(Thread carrier) { /** * Creates the default ForkJoinPool scheduler. */ - @SuppressWarnings("removal") private static ForkJoinPool createDefaultScheduler() { - ForkJoinWorkerThreadFactory factory = pool -> { - PrivilegedAction pa = () -> new CarrierThread(pool); - return AccessController.doPrivileged(pa); - }; - PrivilegedAction pa = () -> { - int parallelism, maxPoolSize, minRunnable; - String parallelismValue = System.getProperty("jdk.virtualThreadScheduler.parallelism"); - String maxPoolSizeValue = System.getProperty("jdk.virtualThreadScheduler.maxPoolSize"); - String minRunnableValue = System.getProperty("jdk.virtualThreadScheduler.minRunnable"); - if (parallelismValue != null) { - parallelism = Integer.parseInt(parallelismValue); - } else { - parallelism = Runtime.getRuntime().availableProcessors(); - } - if (maxPoolSizeValue != null) { - maxPoolSize = Integer.parseInt(maxPoolSizeValue); - parallelism = Integer.min(parallelism, maxPoolSize); - } else { - maxPoolSize = Integer.max(parallelism, 256); - } - if (minRunnableValue != null) { - minRunnable = Integer.parseInt(minRunnableValue); - } else { - minRunnable = Integer.max(parallelism / 2, 1); - } - Thread.UncaughtExceptionHandler handler = (t, e) -> { }; - boolean asyncMode = true; // FIFO - return new ForkJoinPool(parallelism, factory, handler, asyncMode, - 0, maxPoolSize, minRunnable, pool -> true, 30, SECONDS); - }; - return AccessController.doPrivileged(pa); + ForkJoinWorkerThreadFactory factory = pool -> new CarrierThread(pool); + int parallelism, maxPoolSize, minRunnable; + String parallelismValue = System.getProperty("jdk.virtualThreadScheduler.parallelism"); + String maxPoolSizeValue = System.getProperty("jdk.virtualThreadScheduler.maxPoolSize"); + String minRunnableValue = System.getProperty("jdk.virtualThreadScheduler.minRunnable"); + if (parallelismValue != null) { + parallelism = Integer.parseInt(parallelismValue); + } else { + parallelism = Runtime.getRuntime().availableProcessors(); + } + if (maxPoolSizeValue != null) { + maxPoolSize = Integer.parseInt(maxPoolSizeValue); + parallelism = Integer.min(parallelism, maxPoolSize); + } else { + maxPoolSize = Integer.max(parallelism, 256); + } + if (minRunnableValue != null) { + minRunnable = Integer.parseInt(minRunnableValue); + } else { + minRunnable = Integer.max(parallelism / 2, 1); + } + Thread.UncaughtExceptionHandler handler = (t, e) -> { }; + boolean asyncMode = true; // FIFO + return new ForkJoinPool(parallelism, factory, handler, asyncMode, + 0, maxPoolSize, minRunnable, pool -> true, 30, SECONDS); } /** @@ -1458,7 +1447,7 @@ private static Future schedule(Runnable command, long delay, TimeUnit unit) { */ private static ScheduledExecutorService[] createDelayedTaskSchedulers() { String propName = "jdk.virtualThreadScheduler.timerQueues"; - String propValue = GetPropertyAction.privilegedGetProperty(propName); + String propValue = System.getProperty(propName); int queueCount; if (propValue != null) { queueCount = Integer.parseInt(propValue); diff --git a/src/java.base/share/classes/java/lang/classfile/AccessFlags.java b/src/java.base/share/classes/java/lang/classfile/AccessFlags.java index 4abe17c1cf59e..b1d026f52e4c4 100644 --- a/src/java.base/share/classes/java/lang/classfile/AccessFlags.java +++ b/src/java.base/share/classes/java/lang/classfile/AccessFlags.java @@ -28,16 +28,14 @@ import java.util.Set; import jdk.internal.classfile.impl.AccessFlagsImpl; -import jdk.internal.javac.PreviewFeature; /** * Models the access flags for a class, method, or field. Delivered as a * {@link ClassElement}, {@link FieldElement}, or {@link MethodElement} * when traversing the corresponding model type. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface AccessFlags extends ClassElement, MethodElement, FieldElement permits AccessFlagsImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/Annotation.java b/src/java.base/share/classes/java/lang/classfile/Annotation.java index 4f222084cb7ab..98b6ea783d50c 100644 --- a/src/java.base/share/classes/java/lang/classfile/Annotation.java +++ b/src/java.base/share/classes/java/lang/classfile/Annotation.java @@ -35,7 +35,6 @@ import jdk.internal.classfile.impl.AnnotationImpl; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models an {@code annotation} structure (JVMS {@jvms 4.7.16}) or part of a {@code @@ -63,9 +62,8 @@ * @see RuntimeVisibleParameterAnnotationsAttribute * @see RuntimeInvisibleParameterAnnotationsAttribute * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Annotation permits AnnotationImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/AnnotationElement.java b/src/java.base/share/classes/java/lang/classfile/AnnotationElement.java index 7c4283c49bf4d..4381bb9733a7b 100644 --- a/src/java.base/share/classes/java/lang/classfile/AnnotationElement.java +++ b/src/java.base/share/classes/java/lang/classfile/AnnotationElement.java @@ -29,7 +29,6 @@ import jdk.internal.classfile.impl.AnnotationImpl; import jdk.internal.classfile.impl.TemporaryConstantPool; -import jdk.internal.javac.PreviewFeature; /** * Models an element-value pair in the {@code element_value_pairs} @@ -43,9 +42,8 @@ * @see Annotation * @see AnnotationValue * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface AnnotationElement permits AnnotationImpl.AnnotationElementImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/AnnotationValue.java b/src/java.base/share/classes/java/lang/classfile/AnnotationValue.java index e1e91f2c9edb1..8e92ef59a500d 100644 --- a/src/java.base/share/classes/java/lang/classfile/AnnotationValue.java +++ b/src/java.base/share/classes/java/lang/classfile/AnnotationValue.java @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.AnnotationImpl; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -48,18 +47,16 @@ * @see AnnotationElement * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface AnnotationValue { /** * Models an annotation value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_ANNOTATION}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfAnnotation extends AnnotationValue permits AnnotationImpl.OfAnnotationImpl { /** {@return the annotation value} */ @@ -70,9 +67,8 @@ sealed interface OfAnnotation extends AnnotationValue * Models an array value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_ARRAY}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfArray extends AnnotationValue permits AnnotationImpl.OfArrayImpl { /** @@ -91,9 +87,8 @@ sealed interface OfArray extends AnnotationValue * Models a constant value of an element-value pair. * * @sealedGraph - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfConstant extends AnnotationValue { /** * {@return the constant pool entry backing this constant element} @@ -128,9 +123,8 @@ sealed interface OfConstant extends AnnotationValue { * Models a string value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_STRING}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfString extends OfConstant permits AnnotationImpl.OfStringImpl { /** {@return the backing UTF8 entry} */ @@ -156,9 +150,8 @@ default String resolvedValue() { * Models a double value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_DOUBLE}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfDouble extends OfConstant permits AnnotationImpl.OfDoubleImpl { /** {@return the backing double entry} */ @@ -184,9 +177,8 @@ default Double resolvedValue() { * Models a float value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_FLOAT}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfFloat extends OfConstant permits AnnotationImpl.OfFloatImpl { /** {@return the backing float entry} */ @@ -212,9 +204,8 @@ default Float resolvedValue() { * Models a long value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_LONG}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfLong extends OfConstant permits AnnotationImpl.OfLongImpl { /** {@return the backing long entry} */ @@ -240,9 +231,8 @@ default Long resolvedValue() { * Models an int value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_INT}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfInt extends OfConstant permits AnnotationImpl.OfIntImpl { /** {@return the backing integer entry} */ @@ -268,9 +258,8 @@ default Integer resolvedValue() { * Models a short value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_SHORT}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfShort extends OfConstant permits AnnotationImpl.OfShortImpl { /** {@return the backing integer entry} */ @@ -299,9 +288,8 @@ default Short resolvedValue() { * Models a char value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_CHAR}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfChar extends OfConstant permits AnnotationImpl.OfCharImpl { /** {@return the backing integer entry} */ @@ -330,9 +318,8 @@ default Character resolvedValue() { * Models a byte value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_BYTE}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfByte extends OfConstant permits AnnotationImpl.OfByteImpl { /** {@return the backing integer entry} */ @@ -361,9 +348,8 @@ default Byte resolvedValue() { * Models a boolean value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_BOOLEAN}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfBoolean extends OfConstant permits AnnotationImpl.OfBooleanImpl { /** {@return the backing integer entry} */ @@ -392,9 +378,8 @@ default Boolean resolvedValue() { * Models a class value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_CLASS}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfClass extends AnnotationValue permits AnnotationImpl.OfClassImpl { /** {@return the class descriptor string} */ @@ -410,9 +395,8 @@ default ClassDesc classSymbol() { * Models an enum value of an element-value pair. * The {@linkplain #tag tag} of this value is {@value TAG_ENUM}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OfEnum extends AnnotationValue permits AnnotationImpl.OfEnumImpl { /** {@return the enum class descriptor string} */ diff --git a/src/java.base/share/classes/java/lang/classfile/Attribute.java b/src/java.base/share/classes/java/lang/classfile/Attribute.java index e2f0072d3967f..bb5c7bdf8eaa9 100644 --- a/src/java.base/share/classes/java/lang/classfile/Attribute.java +++ b/src/java.base/share/classes/java/lang/classfile/Attribute.java @@ -25,10 +25,10 @@ package java.lang.classfile; import java.lang.classfile.attribute.*; +import java.lang.classfile.constantpool.Utf8Entry; import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models a classfile attribute (JVMS {@jvms 4.7}). Many, though not all, subtypes of @@ -41,9 +41,8 @@ * @param the attribute type * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Attribute> extends ClassFileElement permits AnnotationDefaultAttribute, BootstrapMethodsAttribute, @@ -65,7 +64,7 @@ public sealed interface Attribute> /** * {@return the name of the attribute} */ - String attributeName(); + Utf8Entry attributeName(); /** * {@return the {@link AttributeMapper} associated with this attribute} diff --git a/src/java.base/share/classes/java/lang/classfile/AttributeMapper.java b/src/java.base/share/classes/java/lang/classfile/AttributeMapper.java index 0b46055423ae3..993da9aa4a8c8 100644 --- a/src/java.base/share/classes/java/lang/classfile/AttributeMapper.java +++ b/src/java.base/share/classes/java/lang/classfile/AttributeMapper.java @@ -24,8 +24,6 @@ */ package java.lang.classfile; -import jdk.internal.javac.PreviewFeature; - /** * Bidirectional mapper between the classfile representation of an attribute and * how that attribute is modeled in the API. The attribute mapper is used @@ -37,17 +35,15 @@ * CustomAttribute}. * @param the attribute type * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public interface AttributeMapper> { /** * Attribute stability indicator * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum AttributeStability { /** diff --git a/src/java.base/share/classes/java/lang/classfile/AttributedElement.java b/src/java.base/share/classes/java/lang/classfile/AttributedElement.java index fb1bf817480e0..478ad1e3f0a96 100644 --- a/src/java.base/share/classes/java/lang/classfile/AttributedElement.java +++ b/src/java.base/share/classes/java/lang/classfile/AttributedElement.java @@ -31,7 +31,6 @@ import java.util.Optional; import jdk.internal.classfile.impl.AbstractUnboundModel; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -40,9 +39,8 @@ * as a class, field, method, code attribute, or record component. * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface AttributedElement extends ClassFileElement permits ClassModel, CodeModel, FieldModel, MethodModel, RecordComponentInfo, AbstractUnboundModel { diff --git a/src/java.base/share/classes/java/lang/classfile/Attributes.java b/src/java.base/share/classes/java/lang/classfile/Attributes.java index ad63eec75de39..24684a36b021b 100644 --- a/src/java.base/share/classes/java/lang/classfile/Attributes.java +++ b/src/java.base/share/classes/java/lang/classfile/Attributes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -28,7 +28,6 @@ import java.lang.classfile.attribute.*; import jdk.internal.classfile.impl.AbstractAttributeMapper.*; -import jdk.internal.javac.PreviewFeature; /** * Attribute mappers for standard classfile attributes. @@ -89,9 +88,8 @@ * * @see AttributeMapper * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public final class Attributes { /** AnnotationDefault */ @@ -207,7 +205,6 @@ private Attributes() { /** * {@return Attribute mapper for the {@code AnnotationDefault} attribute} - * @since 23 */ public static AttributeMapper annotationDefault() { return AnnotationDefaultMapper.INSTANCE; @@ -215,7 +212,6 @@ public static AttributeMapper annotationDefault() { /** * {@return Attribute mapper for the {@code BootstrapMethods} attribute} - * @since 23 */ public static AttributeMapper bootstrapMethods() { return BootstrapMethodsMapper.INSTANCE; @@ -224,7 +220,6 @@ public static AttributeMapper bootstrapMethods() { /** * {@return Attribute mapper for the {@code CharacterRangeTable} attribute} * The mapper permits multiple instances in a given location. - * @since 23 */ public static AttributeMapper characterRangeTable() { return CharacterRangeTableMapper.INSTANCE; @@ -232,7 +227,6 @@ public static AttributeMapper characterRangeTable( /** * {@return Attribute mapper for the {@code Code} attribute} - * @since 23 */ public static AttributeMapper code() { return CodeMapper.INSTANCE; @@ -240,7 +234,6 @@ public static AttributeMapper code() { /** * {@return Attribute mapper for the {@code CompilationID} attribute} - * @since 23 */ public static AttributeMapper compilationId() { return CompilationIDMapper.INSTANCE; @@ -248,7 +241,6 @@ public static AttributeMapper compilationId() { /** * {@return Attribute mapper for the {@code ConstantValue} attribute} - * @since 23 */ public static AttributeMapper constantValue() { return ConstantValueMapper.INSTANCE; @@ -257,7 +249,6 @@ public static AttributeMapper constantValue() { /** * {@return Attribute mapper for the {@code Deprecated} attribute} * The mapper permits multiple instances in a given location. - * @since 23 */ public static AttributeMapper deprecated() { return DeprecatedMapper.INSTANCE; @@ -265,7 +256,6 @@ public static AttributeMapper deprecated() { /** * {@return Attribute mapper for the {@code EnclosingMethod} attribute} - * @since 23 */ public static AttributeMapper enclosingMethod() { return EnclosingMethodMapper.INSTANCE; @@ -273,7 +263,6 @@ public static AttributeMapper enclosingMethod() { /** * {@return Attribute mapper for the {@code Exceptions} attribute} - * @since 23 */ public static AttributeMapper exceptions() { return ExceptionsMapper.INSTANCE; @@ -281,7 +270,6 @@ public static AttributeMapper exceptions() { /** * {@return Attribute mapper for the {@code InnerClasses} attribute} - * @since 23 */ public static AttributeMapper innerClasses() { return InnerClassesMapper.INSTANCE; @@ -290,7 +278,6 @@ public static AttributeMapper innerClasses() { /** * {@return Attribute mapper for the {@code LineNumberTable} attribute} * The mapper permits multiple instances in a given location. - * @since 23 */ public static AttributeMapper lineNumberTable() { return LineNumberTableMapper.INSTANCE; @@ -299,7 +286,6 @@ public static AttributeMapper lineNumberTable() { /** * {@return Attribute mapper for the {@code LocalVariableTable} attribute} * The mapper permits multiple instances in a given location. - * @since 23 */ public static AttributeMapper localVariableTable() { return LocalVariableTableMapper.INSTANCE; @@ -308,7 +294,6 @@ public static AttributeMapper localVariableTable() /** * {@return Attribute mapper for the {@code LocalVariableTypeTable} attribute} * The mapper permits multiple instances in a given location. - * @since 23 */ public static AttributeMapper localVariableTypeTable() { return LocalVariableTypeTableMapper.INSTANCE; @@ -316,7 +301,6 @@ public static AttributeMapper localVariableType /** * {@return Attribute mapper for the {@code MethodParameters} attribute} - * @since 23 */ public static AttributeMapper methodParameters() { return MethodParametersMapper.INSTANCE; @@ -324,7 +308,6 @@ public static AttributeMapper methodParameters() { /** * {@return Attribute mapper for the {@code Module} attribute} - * @since 23 */ public static AttributeMapper module() { return ModuleMapper.INSTANCE; @@ -332,7 +315,6 @@ public static AttributeMapper module() { /** * {@return Attribute mapper for the {@code ModuleHashes} attribute} - * @since 23 */ public static AttributeMapper moduleHashes() { return ModuleHashesMapper.INSTANCE; @@ -340,7 +322,6 @@ public static AttributeMapper moduleHashes() { /** * {@return Attribute mapper for the {@code ModuleMainClass} attribute} - * @since 23 */ public static AttributeMapper moduleMainClass() { return ModuleMainClassMapper.INSTANCE; @@ -348,7 +329,6 @@ public static AttributeMapper moduleMainClass() { /** * {@return Attribute mapper for the {@code ModulePackages} attribute} - * @since 23 */ public static AttributeMapper modulePackages() { return ModulePackagesMapper.INSTANCE; @@ -356,7 +336,6 @@ public static AttributeMapper modulePackages() { /** * {@return Attribute mapper for the {@code ModuleResolution} attribute} - * @since 23 */ public static AttributeMapper moduleResolution() { return ModuleResolutionMapper.INSTANCE; @@ -364,7 +343,6 @@ public static AttributeMapper moduleResolution() { /** * {@return Attribute mapper for the {@code ModuleTarget} attribute} - * @since 23 */ public static AttributeMapper moduleTarget() { return ModuleTargetMapper.INSTANCE; @@ -372,7 +350,6 @@ public static AttributeMapper moduleTarget() { /** * {@return Attribute mapper for the {@code NestHost} attribute} - * @since 23 */ public static AttributeMapper nestHost() { return NestHostMapper.INSTANCE; @@ -380,7 +357,6 @@ public static AttributeMapper nestHost() { /** * {@return Attribute mapper for the {@code NestMembers} attribute} - * @since 23 */ public static AttributeMapper nestMembers() { return NestMembersMapper.INSTANCE; @@ -388,7 +364,6 @@ public static AttributeMapper nestMembers() { /** * {@return Attribute mapper for the {@code PermittedSubclasses} attribute} - * @since 23 */ public static AttributeMapper permittedSubclasses() { return PermittedSubclassesMapper.INSTANCE; @@ -396,7 +371,6 @@ public static AttributeMapper permittedSubclasses( /** * {@return Attribute mapper for the {@code Record} attribute} - * @since 23 */ public static AttributeMapper record() { return RecordMapper.INSTANCE; @@ -404,7 +378,6 @@ public static AttributeMapper record() { /** * {@return Attribute mapper for the {@code RuntimeInvisibleAnnotations} attribute} - * @since 23 */ public static AttributeMapper runtimeInvisibleAnnotations() { return RuntimeInvisibleAnnotationsMapper.INSTANCE; @@ -412,7 +385,6 @@ public static AttributeMapper runtimeInvis /** * {@return Attribute mapper for the {@code RuntimeInvisibleParameterAnnotations} attribute} - * @since 23 */ public static AttributeMapper runtimeInvisibleParameterAnnotations() { return RuntimeInvisibleParameterAnnotationsMapper.INSTANCE; @@ -420,7 +392,6 @@ public static AttributeMapper run /** * {@return Attribute mapper for the {@code RuntimeInvisibleTypeAnnotations} attribute} - * @since 23 */ public static AttributeMapper runtimeInvisibleTypeAnnotations() { return RuntimeInvisibleTypeAnnotationsMapper.INSTANCE; @@ -428,7 +399,6 @@ public static AttributeMapper runtimeI /** * {@return Attribute mapper for the {@code RuntimeVisibleAnnotations} attribute} - * @since 23 */ public static AttributeMapper runtimeVisibleAnnotations() { return RuntimeVisibleAnnotationsMapper.INSTANCE; @@ -436,7 +406,6 @@ public static AttributeMapper runtimeVisible /** * {@return Attribute mapper for the {@code RuntimeVisibleParameterAnnotations} attribute} - * @since 23 */ public static AttributeMapper runtimeVisibleParameterAnnotations() { return RuntimeVisibleParameterAnnotationsMapper.INSTANCE; @@ -444,7 +413,6 @@ public static AttributeMapper runti /** * {@return Attribute mapper for the {@code RuntimeVisibleTypeAnnotations} attribute} - * @since 23 */ public static AttributeMapper runtimeVisibleTypeAnnotations() { return RuntimeVisibleTypeAnnotationsMapper.INSTANCE; @@ -452,7 +420,6 @@ public static AttributeMapper runtimeVis /** * {@return Attribute mapper for the {@code Signature} attribute} - * @since 23 */ public static AttributeMapper signature() { return SignatureMapper.INSTANCE; @@ -460,7 +427,6 @@ public static AttributeMapper signature() { /** * {@return Attribute mapper for the {@code SourceDebugExtension} attribute} - * @since 23 */ public static AttributeMapper sourceDebugExtension() { return SourceDebugExtensionMapper.INSTANCE; @@ -468,7 +434,6 @@ public static AttributeMapper sourceDebugExtensio /** * {@return Attribute mapper for the {@code SourceFile} attribute} - * @since 23 */ public static AttributeMapper sourceFile() { return SourceFileMapper.INSTANCE; @@ -476,7 +441,6 @@ public static AttributeMapper sourceFile() { /** * {@return Attribute mapper for the {@code SourceID} attribute} - * @since 23 */ public static AttributeMapper sourceId() { return SourceIDMapper.INSTANCE; @@ -484,7 +448,6 @@ public static AttributeMapper sourceId() { /** * {@return Attribute mapper for the {@code StackMapTable} attribute} - * @since 23 */ public static AttributeMapper stackMapTable() { return StackMapTableMapper.INSTANCE; @@ -493,7 +456,6 @@ public static AttributeMapper stackMapTable() { /** * {@return Attribute mapper for the {@code Synthetic} attribute} * The mapper permits multiple instances in a given location. - * @since 23 */ public static AttributeMapper synthetic() { return SyntheticMapper.INSTANCE; diff --git a/src/java.base/share/classes/java/lang/classfile/BootstrapMethodEntry.java b/src/java.base/share/classes/java/lang/classfile/BootstrapMethodEntry.java index 0c4f99de29a9c..d12ca953be778 100644 --- a/src/java.base/share/classes/java/lang/classfile/BootstrapMethodEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/BootstrapMethodEntry.java @@ -33,7 +33,6 @@ import java.util.List; import jdk.internal.classfile.impl.BootstrapMethodEntryImpl; -import jdk.internal.javac.PreviewFeature; /** * Models an entry in the bootstrap method table. The bootstrap method table @@ -58,9 +57,8 @@ * } * * @see ConstantPoolBuilder#bsmEntry ConstantPoolBuilder::bsmEntry - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface BootstrapMethodEntry permits BootstrapMethodEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/BufWriter.java b/src/java.base/share/classes/java/lang/classfile/BufWriter.java index d60447c138843..c6779583eb140 100644 --- a/src/java.base/share/classes/java/lang/classfile/BufWriter.java +++ b/src/java.base/share/classes/java/lang/classfile/BufWriter.java @@ -29,16 +29,14 @@ import java.lang.classfile.constantpool.PoolEntry; import jdk.internal.classfile.impl.BufWriterImpl; -import jdk.internal.javac.PreviewFeature; /** * Supports writing portions of a classfile to a growable buffer. Methods * are provided to write various standard entities (e.g., {@code u2}, {@code u4}) * to the end of the buffer, as well as to create constant pool entries. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface BufWriter permits BufWriterImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/ClassBuilder.java b/src/java.base/share/classes/java/lang/classfile/ClassBuilder.java index 71f1cc5319458..996c63ddd0126 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassBuilder.java @@ -39,7 +39,6 @@ import jdk.internal.classfile.impl.ChainedClassBuilder; import jdk.internal.classfile.impl.DirectClassBuilder; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * A builder for classfiles. Builders are not created directly; they are passed @@ -50,9 +49,8 @@ * * @see ClassTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassBuilder extends ClassFileBuilder permits ChainedClassBuilder, DirectClassBuilder { diff --git a/src/java.base/share/classes/java/lang/classfile/ClassElement.java b/src/java.base/share/classes/java/lang/classfile/ClassElement.java index 6c918b7de4aab..c39ab3c4a64d8 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassElement.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,16 +26,13 @@ import java.lang.classfile.attribute.*; -import jdk.internal.javac.PreviewFeature; - /** * A marker interface for elements that can appear when traversing * a {@link ClassModel} or be presented to a {@link ClassBuilder}. * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassElement extends ClassFileElement permits AccessFlags, Superclass, Interfaces, ClassFileVersion, FieldModel, MethodModel, diff --git a/src/java.base/share/classes/java/lang/classfile/ClassFile.java b/src/java.base/share/classes/java/lang/classfile/ClassFile.java index 7051228c827b0..db293f415888a 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassFile.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassFile.java @@ -43,7 +43,6 @@ import jdk.internal.classfile.impl.ClassFileImpl; import jdk.internal.classfile.impl.TemporaryConstantPool; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; import static jdk.internal.constant.ConstantUtils.CD_module_info; @@ -53,9 +52,8 @@ * A {@code ClassFile} has a set of options that condition how parsing and * generation is done. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassFile permits ClassFileImpl { @@ -84,9 +82,8 @@ static ClassFile of(Option... options) { * An option that affects the parsing and writing of classfiles. * * @sealedGraph - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface Option { } @@ -94,9 +91,8 @@ sealed interface Option { * Option describing attribute mappers for custom attributes. * Default is only to process standard attributes. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface AttributeMapperOption extends Option permits ClassFileImpl.AttributeMapperOptionImpl { @@ -119,9 +115,8 @@ static AttributeMapperOption of(Function> attribut * Option describing the class hierarchy resolver to use when generating * stack maps. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface ClassHierarchyResolverOption extends Option permits ClassFileImpl.ClassHierarchyResolverOptionImpl { @@ -150,9 +145,8 @@ static ClassHierarchyResolverOption of(ClassHierarchyResolver classHierarchyReso * Default is {@code SHARED_POOL} to preserve the original constant * pool. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum ConstantPoolSharingOption implements Option { /** Preserves the original constant pool when transforming classfile */ @@ -167,9 +161,8 @@ enum ConstantPoolSharingOption implements Option { * Default is {@code PATCH_DEAD_CODE} to automatically patch out unreachable * code with NOPs. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum DeadCodeOption implements Option { /** Patch unreachable code */ @@ -188,9 +181,8 @@ enum DeadCodeOption implements Option { * Setting this option to {@code DROP_DEAD_LABELS} filters the above * elements instead. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum DeadLabelsOption implements Option { /** Fail on unresolved labels */ @@ -207,9 +199,8 @@ enum DeadLabelsOption implements Option { * reduce the overhead of parsing or transforming classfiles. * Default is {@code PASS_DEBUG} to process debug elements. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum DebugElementsOption implements Option { /** Process debug elements */ @@ -225,9 +216,8 @@ enum DebugElementsOption implements Option { * classfiles. * Default is {@code PASS_LINE_NUMBERS} to process line numbers. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum LineNumbersOption implements Option { /** Process line numbers */ @@ -243,9 +233,8 @@ enum LineNumbersOption implements Option { * Default is {@code FIX_SHORT_JUMPS} to automatically rewrite jump * instructions. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum ShortJumpsOption implements Option { /** Automatically convert short jumps to long when necessary */ @@ -262,9 +251,8 @@ enum ShortJumpsOption implements Option { * {@link #JAVA_6_VERSION} the stack maps may not be generated. * @jvms 4.10.1 Verification by Type Checking * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum StackMapsOption implements Option { /** Generate stack maps when required */ @@ -284,9 +272,8 @@ enum StackMapsOption implements Option { * Default is {@code PASS_ALL_ATTRIBUTES} to process all original attributes. * @see AttributeMapper.AttributeStability * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) enum AttributesProcessingOption implements Option { /** Process all original attributes during transformation */ @@ -648,16 +635,10 @@ default List verify(Path path) throws IOException { /** The class major version of JAVA_22. */ int JAVA_22_VERSION = 66; - /** - * The class major version of JAVA_23. - * @since 23 - */ + /** The class major version of JAVA_23. */ int JAVA_23_VERSION = 67; - /** - * The class major version of JAVA_24. - * @since 24 - */ + /** The class major version of JAVA_24. */ int JAVA_24_VERSION = 68; /** diff --git a/src/java.base/share/classes/java/lang/classfile/ClassFileBuilder.java b/src/java.base/share/classes/java/lang/classfile/ClassFileBuilder.java index 8b3f6544fff16..01eeefd0b9b1a 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassFileBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassFileBuilder.java @@ -29,7 +29,6 @@ import java.util.function.Consumer; import jdk.internal.classfile.impl.TransformImpl; -import jdk.internal.javac.PreviewFeature; /** * A builder for a classfile or portion of a classfile. Builders are rarely @@ -44,9 +43,8 @@ * @see ClassFileTransform * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassFileBuilder> extends Consumer permits ClassBuilder, FieldBuilder, MethodBuilder, CodeBuilder { diff --git a/src/java.base/share/classes/java/lang/classfile/ClassFileElement.java b/src/java.base/share/classes/java/lang/classfile/ClassFileElement.java index a4a8203038f15..ed84eb39d53b8 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassFileElement.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassFileElement.java @@ -24,8 +24,6 @@ */ package java.lang.classfile; -import jdk.internal.javac.PreviewFeature; - /** * Immutable model for a portion of (or the entirety of) a classfile. Elements * that model parts of the classfile that have attributes will implement {@link @@ -35,9 +33,8 @@ * will implement {@link ClassElement}, {@link MethodElement}, etc. * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassFileElement permits AttributedElement, CompoundElement, Attribute, ClassElement, CodeElement, FieldElement, MethodElement { diff --git a/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java b/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java index b9c5210881cb9..9fdafdf4331e1 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassFileTransform.java @@ -27,8 +27,6 @@ import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute; import java.util.function.Supplier; -import jdk.internal.javac.PreviewFeature; - /** * A transformation on streams of elements. Transforms are used during * transformation of classfile entities; a transform is provided to a method like @@ -73,9 +71,8 @@ * @param the builder type * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassFileTransform< C extends ClassFileTransform, E extends ClassFileElement, diff --git a/src/java.base/share/classes/java/lang/classfile/ClassFileVersion.java b/src/java.base/share/classes/java/lang/classfile/ClassFileVersion.java index b6ef3e57f6118..1916a185cc863 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassFileVersion.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassFileVersion.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -25,16 +25,14 @@ package java.lang.classfile; import jdk.internal.classfile.impl.ClassFileVersionImpl; -import jdk.internal.javac.PreviewFeature; /** * Models the classfile version information for a class. Delivered as a {@link * java.lang.classfile.ClassElement} when traversing the elements of a {@link * ClassModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassFileVersion extends ClassElement permits ClassFileVersionImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/ClassHierarchyResolver.java b/src/java.base/share/classes/java/lang/classfile/ClassHierarchyResolver.java index c2719e7aae062..2c612854a64d2 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassHierarchyResolver.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassHierarchyResolver.java @@ -37,7 +37,6 @@ import jdk.internal.classfile.impl.ClassHierarchyImpl.ClassLoadingClassHierarchyResolver; import jdk.internal.classfile.impl.ClassHierarchyImpl.StaticClassHierarchyResolver; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; import static java.lang.constant.ConstantDescs.CD_Object; import static java.util.Objects.requireNonNull; @@ -46,9 +45,8 @@ * Provides class hierarchy information for generating correct stack maps * during code building. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) @FunctionalInterface public interface ClassHierarchyResolver { @@ -71,9 +69,8 @@ static ClassHierarchyResolver defaultResolver() { /** * Information about a resolved class. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface ClassHierarchyInfo permits ClassHierarchyImpl.ClassHierarchyInfoImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/ClassModel.java b/src/java.base/share/classes/java/lang/classfile/ClassModel.java index 915b662b48838..db804348cfe9e 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassModel.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassModel.java @@ -31,16 +31,14 @@ import java.util.Optional; import jdk.internal.classfile.impl.ClassImpl; -import jdk.internal.javac.PreviewFeature; /** * Models a classfile. The contents of the classfile can be traversed via * a streaming view, or via random access (e.g., * {@link #flags()}), or by freely mixing the two. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassModel extends CompoundElement, AttributedElement permits ClassImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/ClassReader.java b/src/java.base/share/classes/java/lang/classfile/ClassReader.java index 58ee2aae5e58e..93f2ac5c810be 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassReader.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassReader.java @@ -33,7 +33,6 @@ import java.util.function.Function; import jdk.internal.classfile.impl.ClassReaderImpl; -import jdk.internal.javac.PreviewFeature; /** * Supports reading from a classfile. Methods are provided to read data of @@ -42,9 +41,8 @@ * Encapsulates additional reading context such as mappers for custom attributes * and processing options. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassReader extends ConstantPool permits ClassReaderImpl { @@ -122,7 +120,6 @@ public sealed interface ClassReader extends ConstantPool * @param cls the entry type * @throws ConstantPoolException if the index is out of range of the * constant pool size, or zero, or the entry is not of the given type - * @since 23 */ T readEntryOrNull(int offset, Class cls); diff --git a/src/java.base/share/classes/java/lang/classfile/ClassSignature.java b/src/java.base/share/classes/java/lang/classfile/ClassSignature.java index 5a57144c4abce..0e1329fd167e9 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassSignature.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassSignature.java @@ -27,27 +27,21 @@ import java.util.List; import jdk.internal.classfile.impl.SignaturesImpl; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; /** * Models the generic signature of a class file, as defined by JVMS {@jvms 4.7.9}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassSignature permits SignaturesImpl.ClassSignatureImpl { /** {@return the type parameters of this class} */ List typeParameters(); - /** - * {@return the instantiation of the superclass in this signature} - * - * @since 23 - */ + /** {@return the instantiation of the superclass in this signature} */ Signature.ClassTypeSig superclassSignature(); /** {@return the instantiation of the interfaces in this signature} */ @@ -60,7 +54,6 @@ public sealed interface ClassSignature * {@return a class signature} * @param superclassSignature the superclass * @param superinterfaceSignatures the interfaces - * @since 23 */ public static ClassSignature of(Signature.ClassTypeSig superclassSignature, Signature.ClassTypeSig... superinterfaceSignatures) { @@ -72,7 +65,6 @@ public static ClassSignature of(Signature.ClassTypeSig superclassSignature, * @param typeParameters the type parameters * @param superclassSignature the superclass * @param superinterfaceSignatures the interfaces - * @since 23 */ public static ClassSignature of(List typeParameters, Signature.ClassTypeSig superclassSignature, diff --git a/src/java.base/share/classes/java/lang/classfile/ClassTransform.java b/src/java.base/share/classes/java/lang/classfile/ClassTransform.java index f512683a9b652..82b61a1508952 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassTransform.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassTransform.java @@ -30,7 +30,6 @@ import java.util.function.Supplier; import jdk.internal.classfile.impl.TransformImpl; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -39,9 +38,8 @@ * * @see ClassFileTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) @FunctionalInterface public non-sealed interface ClassTransform extends ClassFileTransform { diff --git a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java index 11e83550d233d..1a074c1554a03 100644 --- a/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/CodeBuilder.java @@ -39,7 +39,6 @@ import java.util.function.Consumer; import jdk.internal.classfile.impl.*; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; import static jdk.internal.classfile.impl.BytecodeHelpers.handleDescToHandleInfo; @@ -75,9 +74,8 @@ * * @see CodeTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CodeBuilder extends ClassFileBuilder permits CodeBuilder.BlockCodeBuilder, ChainedCodeBuilder, TerminalCodeBuilder, NonterminalCodeBuilder { @@ -149,9 +147,8 @@ default CodeBuilder transforming(CodeTransform transform, Consumer /** * A builder for blocks of code. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface BlockCodeBuilder extends CodeBuilder permits BlockCodeBuilderImpl { /** @@ -290,9 +287,8 @@ default CodeBuilder ifThenElse(Opcode opcode, * * @see #trying * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface CatchBuilder permits CatchBuilderImpl { /** * Adds a catch block that catches an exception of the given type. @@ -385,7 +381,6 @@ default CodeBuilder trying(Consumer tryHandler, * @return this builder * @throws IllegalArgumentException if {@code tk} is {@link TypeKind#VOID void} * or {@code slot} is out of range - * @since 23 */ default CodeBuilder loadLocal(TypeKind tk, int slot) { return with(LoadInstruction.of(tk, slot)); @@ -398,7 +393,6 @@ default CodeBuilder loadLocal(TypeKind tk, int slot) { * @return this builder * @throws IllegalArgumentException if {@code tk} is {@link TypeKind#VOID void} * or {@code slot} is out of range - * @since 23 */ default CodeBuilder storeLocal(TypeKind tk, int slot) { return with(StoreInstruction.of(tk, slot)); @@ -410,7 +404,6 @@ default CodeBuilder storeLocal(TypeKind tk, int slot) { * @param op the branch opcode * @param target the branch target * @return this builder - * @since 23 */ default CodeBuilder branch(Opcode op, Label target) { return with(BranchInstruction.of(op, target)); @@ -420,7 +413,6 @@ default CodeBuilder branch(Opcode op, Label target) { * Generate return instruction * @param tk the return type * @return this builder - * @since 23 */ default CodeBuilder return_(TypeKind tk) { return with(ReturnInstruction.of(tk)); @@ -432,7 +424,6 @@ default CodeBuilder return_(TypeKind tk) { * @param opcode the field access opcode * @param ref the field reference * @return this builder - * @since 23 */ default CodeBuilder fieldAccess(Opcode opcode, FieldRefEntry ref) { return with(FieldInstruction.of(opcode, ref)); @@ -446,7 +437,6 @@ default CodeBuilder fieldAccess(Opcode opcode, FieldRefEntry ref) { * @param name the field name * @param type the field type * @return this builder - * @since 23 */ default CodeBuilder fieldAccess(Opcode opcode, ClassDesc owner, String name, ClassDesc type) { return fieldAccess(opcode, constantPool().fieldRefEntry(owner, name, type)); @@ -458,7 +448,6 @@ default CodeBuilder fieldAccess(Opcode opcode, ClassDesc owner, String name, Cla * @param opcode the invoke opcode * @param ref the interface method or method reference * @return this builder - * @since 23 */ default CodeBuilder invoke(Opcode opcode, MemberRefEntry ref) { return with(InvokeInstruction.of(opcode, ref)); @@ -473,7 +462,6 @@ default CodeBuilder invoke(Opcode opcode, MemberRefEntry ref) { * @param desc the method type * @param isInterface the interface method invocation indication * @return this builder - * @since 23 */ default CodeBuilder invoke(Opcode opcode, ClassDesc owner, String name, MethodTypeDesc desc, boolean isInterface) { return invoke(opcode, @@ -485,7 +473,6 @@ default CodeBuilder invoke(Opcode opcode, ClassDesc owner, String name, MethodTy * Generate an instruction to load from an array * @param tk the array element type * @return this builder - * @since 23 */ default CodeBuilder arrayLoad(TypeKind tk) { Opcode opcode = BytecodeHelpers.arrayLoadOpcode(tk); @@ -496,7 +483,6 @@ default CodeBuilder arrayLoad(TypeKind tk) { * Generate an instruction to store into an array * @param tk the array element type * @return this builder - * @since 23 */ default CodeBuilder arrayStore(TypeKind tk) { Opcode opcode = BytecodeHelpers.arrayStoreOpcode(tk); @@ -510,7 +496,6 @@ default CodeBuilder arrayStore(TypeKind tk) { * @return this builder * @throws IllegalArgumentException for conversions of {@link TypeKind#VOID void} or * {@link TypeKind#REFERENCE reference} - * @since 23 */ default CodeBuilder conversion(TypeKind fromType, TypeKind toType) { var computationalFrom = fromType.asLoadable(); @@ -566,7 +551,6 @@ default CodeBuilder conversion(TypeKind fromType, TypeKind toType) { * Generate an instruction pushing a constant onto the operand stack * @param value the constant value * @return this builder - * @since 23 */ default CodeBuilder loadConstant(ConstantDesc value) { //avoid switch expressions here @@ -1740,7 +1724,6 @@ default CodeBuilder ineg() { * * @param target the target type * @return this builder - * @since 23 */ default CodeBuilder instanceOf(ClassEntry target) { return with(TypeCheckInstruction.of(Opcode.INSTANCEOF, target)); @@ -1756,7 +1739,6 @@ default CodeBuilder instanceOf(ClassEntry target) { * @param target the target type * @return this builder * @throws IllegalArgumentException if {@code target} represents a primitive type - * @since 23 */ default CodeBuilder instanceOf(ClassDesc target) { return instanceOf(constantPool().classEntry(target)); diff --git a/src/java.base/share/classes/java/lang/classfile/CodeElement.java b/src/java.base/share/classes/java/lang/classfile/CodeElement.java index 1cec4b8e6045f..63669d41014bd 100644 --- a/src/java.base/share/classes/java/lang/classfile/CodeElement.java +++ b/src/java.base/share/classes/java/lang/classfile/CodeElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -28,8 +28,6 @@ import java.lang.classfile.attribute.RuntimeVisibleTypeAnnotationsAttribute; import java.lang.classfile.attribute.StackMapTableAttribute; -import jdk.internal.javac.PreviewFeature; - /** * A marker interface for elements that can appear when traversing * a {@link CodeModel} or be presented to a {@link CodeBuilder}. Code elements @@ -39,9 +37,8 @@ * exception metadata, label target metadata, etc. * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CodeElement extends ClassFileElement permits Instruction, PseudoInstruction, CustomAttribute, RuntimeVisibleTypeAnnotationsAttribute, RuntimeInvisibleTypeAnnotationsAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/CodeModel.java b/src/java.base/share/classes/java/lang/classfile/CodeModel.java index 759aacc18c94e..644f766056418 100644 --- a/src/java.base/share/classes/java/lang/classfile/CodeModel.java +++ b/src/java.base/share/classes/java/lang/classfile/CodeModel.java @@ -31,15 +31,13 @@ import java.util.Optional; import jdk.internal.classfile.impl.BufferedCodeBuilder; -import jdk.internal.javac.PreviewFeature; /** * Models the body of a method (the {@code Code} attribute). The instructions * of the method body are accessed via a streaming view. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CodeModel extends CompoundElement, AttributedElement, MethodElement permits CodeAttribute, BufferedCodeBuilder.Model { diff --git a/src/java.base/share/classes/java/lang/classfile/CodeTransform.java b/src/java.base/share/classes/java/lang/classfile/CodeTransform.java index 0474e0c9c67f7..b76c02bf5fb53 100644 --- a/src/java.base/share/classes/java/lang/classfile/CodeTransform.java +++ b/src/java.base/share/classes/java/lang/classfile/CodeTransform.java @@ -28,7 +28,6 @@ import java.util.function.Supplier; import jdk.internal.classfile.impl.TransformImpl; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -37,9 +36,8 @@ * * @see ClassFileTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) @FunctionalInterface public non-sealed interface CodeTransform extends ClassFileTransform { diff --git a/src/java.base/share/classes/java/lang/classfile/CompoundElement.java b/src/java.base/share/classes/java/lang/classfile/CompoundElement.java index 5dfeac6f00d33..38d149623e186 100644 --- a/src/java.base/share/classes/java/lang/classfile/CompoundElement.java +++ b/src/java.base/share/classes/java/lang/classfile/CompoundElement.java @@ -34,8 +34,6 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; -import jdk.internal.javac.PreviewFeature; - /** * A {@link ClassFileElement} that has complex structure defined in terms of * other classfile elements, such as a method, field, method body, or entire @@ -46,9 +44,8 @@ * @param the element type * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CompoundElement extends ClassFileElement, Iterable permits ClassModel, CodeModel, FieldModel, MethodModel, jdk.internal.classfile.impl.AbstractUnboundModel { diff --git a/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java b/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java index 9fe492dc22c4c..f47ce9f055bf2 100644 --- a/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java @@ -24,7 +24,8 @@ */ package java.lang.classfile; -import jdk.internal.javac.PreviewFeature; +import java.lang.classfile.constantpool.Utf8Entry; +import jdk.internal.classfile.impl.TemporaryConstantPool; /** * Models a non-standard attribute of a classfile. Clients should extend @@ -33,9 +34,8 @@ * format and the {@linkplain CustomAttribute} representation. * @param the custom attribute type * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public abstract non-sealed class CustomAttribute> implements Attribute, CodeElement, ClassElement, MethodElement, FieldElement { @@ -55,8 +55,8 @@ public final AttributeMapper attributeMapper() { } @Override - public final String attributeName() { - return mapper.name(); + public Utf8Entry attributeName() { + return TemporaryConstantPool.INSTANCE.utf8Entry(mapper.name()); } @Override diff --git a/src/java.base/share/classes/java/lang/classfile/FieldBuilder.java b/src/java.base/share/classes/java/lang/classfile/FieldBuilder.java index d318364465748..c473e09cab722 100644 --- a/src/java.base/share/classes/java/lang/classfile/FieldBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/FieldBuilder.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.AccessFlagsImpl; import jdk.internal.classfile.impl.ChainedFieldBuilder; import jdk.internal.classfile.impl.TerminalFieldBuilder; -import jdk.internal.javac.PreviewFeature; /** * A builder for fields. Builders are not created directly; they are passed @@ -43,9 +42,8 @@ * * @see FieldTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface FieldBuilder extends ClassFileBuilder permits TerminalFieldBuilder, ChainedFieldBuilder { diff --git a/src/java.base/share/classes/java/lang/classfile/FieldElement.java b/src/java.base/share/classes/java/lang/classfile/FieldElement.java index b4af99719818c..a2c1b22751efe 100644 --- a/src/java.base/share/classes/java/lang/classfile/FieldElement.java +++ b/src/java.base/share/classes/java/lang/classfile/FieldElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,16 +26,13 @@ import java.lang.classfile.attribute.*; -import jdk.internal.javac.PreviewFeature; - /** * A marker interface for elements that can appear when traversing * a {@link FieldModel} or be presented to a {@link FieldBuilder}. * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface FieldElement extends ClassFileElement permits AccessFlags, CustomAttribute, ConstantValueAttribute, DeprecatedAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/FieldModel.java b/src/java.base/share/classes/java/lang/classfile/FieldModel.java index c45f3e88d5dcb..89fa1e192b04f 100644 --- a/src/java.base/share/classes/java/lang/classfile/FieldModel.java +++ b/src/java.base/share/classes/java/lang/classfile/FieldModel.java @@ -32,16 +32,14 @@ import jdk.internal.classfile.impl.BufferedFieldBuilder; import jdk.internal.classfile.impl.FieldImpl; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a field. The contents of the field can be traversed via * a streaming view, or via random access (e.g., * {@link #flags()}), or by freely mixing the two. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface FieldModel extends CompoundElement, AttributedElement, ClassElement permits BufferedFieldBuilder.Model, FieldImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/FieldTransform.java b/src/java.base/share/classes/java/lang/classfile/FieldTransform.java index 78a6f5ead2f79..90313ae48f061 100644 --- a/src/java.base/share/classes/java/lang/classfile/FieldTransform.java +++ b/src/java.base/share/classes/java/lang/classfile/FieldTransform.java @@ -29,7 +29,6 @@ import java.util.function.Supplier; import jdk.internal.classfile.impl.TransformImpl; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -38,9 +37,8 @@ * * @see ClassFileTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) @FunctionalInterface public non-sealed interface FieldTransform extends ClassFileTransform { diff --git a/src/java.base/share/classes/java/lang/classfile/Instruction.java b/src/java.base/share/classes/java/lang/classfile/Instruction.java index 210c1e1b0da7b..2fe0ec5a58848 100644 --- a/src/java.base/share/classes/java/lang/classfile/Instruction.java +++ b/src/java.base/share/classes/java/lang/classfile/Instruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -28,14 +28,12 @@ import java.lang.classfile.instruction.*; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models an executable instruction in a method body. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Instruction extends CodeElement permits ArrayLoadInstruction, ArrayStoreInstruction, BranchInstruction, ConstantInstruction, ConvertInstruction, DiscontinuedInstruction, diff --git a/src/java.base/share/classes/java/lang/classfile/Interfaces.java b/src/java.base/share/classes/java/lang/classfile/Interfaces.java index ff1dda17de8cd..2c0e5b2e54b9c 100644 --- a/src/java.base/share/classes/java/lang/classfile/Interfaces.java +++ b/src/java.base/share/classes/java/lang/classfile/Interfaces.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,15 +31,13 @@ import jdk.internal.classfile.impl.InterfacesImpl; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models the interfaces of a class. Delivered as a {@link * java.lang.classfile.ClassElement} when traversing a {@link ClassModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Interfaces extends ClassElement permits InterfacesImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/Label.java b/src/java.base/share/classes/java/lang/classfile/Label.java index 5069b9359357c..e958e116084a0 100644 --- a/src/java.base/share/classes/java/lang/classfile/Label.java +++ b/src/java.base/share/classes/java/lang/classfile/Label.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -25,7 +25,6 @@ package java.lang.classfile; import jdk.internal.classfile.impl.LabelImpl; -import jdk.internal.javac.PreviewFeature; /** * A marker for a position within the instructions of a method body. The @@ -40,9 +39,8 @@ * can be bound to the current position within a {@linkplain CodeBuilder} via * {@link CodeBuilder#labelBinding(Label)} or {@link CodeBuilder#with(ClassFileElement)}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Label permits LabelImpl { } diff --git a/src/java.base/share/classes/java/lang/classfile/MethodBuilder.java b/src/java.base/share/classes/java/lang/classfile/MethodBuilder.java index 6607d19b0acbe..747cbe2e10770 100644 --- a/src/java.base/share/classes/java/lang/classfile/MethodBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/MethodBuilder.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.AccessFlagsImpl; import jdk.internal.classfile.impl.ChainedMethodBuilder; import jdk.internal.classfile.impl.TerminalMethodBuilder; -import jdk.internal.javac.PreviewFeature; /** * A builder for methods. Builders are not created directly; they are passed @@ -43,9 +42,8 @@ * * @see MethodTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodBuilder extends ClassFileBuilder permits ChainedMethodBuilder, TerminalMethodBuilder { diff --git a/src/java.base/share/classes/java/lang/classfile/MethodElement.java b/src/java.base/share/classes/java/lang/classfile/MethodElement.java index dd23548c36022..77254a6a82c43 100644 --- a/src/java.base/share/classes/java/lang/classfile/MethodElement.java +++ b/src/java.base/share/classes/java/lang/classfile/MethodElement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,16 +26,13 @@ import java.lang.classfile.attribute.*; -import jdk.internal.javac.PreviewFeature; - /** * A marker interface for elements that can appear when traversing * a {@link MethodModel} or be presented to a {@link MethodBuilder}. * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodElement extends ClassFileElement permits AccessFlags, CodeModel, CustomAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/MethodModel.java b/src/java.base/share/classes/java/lang/classfile/MethodModel.java index 568036e464d8b..d88051a5eb3f6 100644 --- a/src/java.base/share/classes/java/lang/classfile/MethodModel.java +++ b/src/java.base/share/classes/java/lang/classfile/MethodModel.java @@ -32,16 +32,14 @@ import jdk.internal.classfile.impl.BufferedMethodBuilder; import jdk.internal.classfile.impl.MethodImpl; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a method. The contents of the method can be traversed via * a streaming view, or via random access (e.g., * {@link #flags()}), or by freely mixing the two. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodModel extends CompoundElement, AttributedElement, ClassElement permits BufferedMethodBuilder.Model, MethodImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/MethodSignature.java b/src/java.base/share/classes/java/lang/classfile/MethodSignature.java index 7235c368a4591..e3889395e3241 100644 --- a/src/java.base/share/classes/java/lang/classfile/MethodSignature.java +++ b/src/java.base/share/classes/java/lang/classfile/MethodSignature.java @@ -29,16 +29,14 @@ import jdk.internal.classfile.impl.SignaturesImpl; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; /** * Models the generic signature of a method, as defined by JVMS {@jvms 4.7.9}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodSignature permits SignaturesImpl.MethodSignatureImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/MethodTransform.java b/src/java.base/share/classes/java/lang/classfile/MethodTransform.java index bf5786f3dc74b..865fadbae873b 100644 --- a/src/java.base/share/classes/java/lang/classfile/MethodTransform.java +++ b/src/java.base/share/classes/java/lang/classfile/MethodTransform.java @@ -29,7 +29,6 @@ import java.util.function.Supplier; import jdk.internal.classfile.impl.TransformImpl; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -38,9 +37,8 @@ * * @see ClassFileTransform * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) @FunctionalInterface public non-sealed interface MethodTransform extends ClassFileTransform { diff --git a/src/java.base/share/classes/java/lang/classfile/Opcode.java b/src/java.base/share/classes/java/lang/classfile/Opcode.java index 735510dbcea3b..4d3334000011f 100644 --- a/src/java.base/share/classes/java/lang/classfile/Opcode.java +++ b/src/java.base/share/classes/java/lang/classfile/Opcode.java @@ -25,7 +25,6 @@ package java.lang.classfile; import jdk.internal.classfile.impl.RawBytecodeHelper; -import jdk.internal.javac.PreviewFeature; /** * Describes the opcodes of the JVM instruction set, as described in JVMS {@jvms 6.5}. @@ -35,9 +34,8 @@ * @see Instruction * @see PseudoInstruction * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public enum Opcode { /** Do nothing */ @@ -697,9 +695,8 @@ public enum Opcode { /** * Kinds of opcodes. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public static enum Kind { /** diff --git a/src/java.base/share/classes/java/lang/classfile/PseudoInstruction.java b/src/java.base/share/classes/java/lang/classfile/PseudoInstruction.java index b152756acfd8d..456bce04c8021 100644 --- a/src/java.base/share/classes/java/lang/classfile/PseudoInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/PseudoInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,7 +33,6 @@ import java.lang.classfile.instruction.LocalVariableType; import jdk.internal.classfile.impl.AbstractPseudoInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models metadata about a {@link CodeAttribute}, such as entries in the @@ -43,9 +42,8 @@ * pseudo-instructions can be disabled by modifying the value of classfile * options (e.g., {@link ClassFile.DebugElementsOption}). * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface PseudoInstruction extends CodeElement permits CharacterRange, ExceptionCatch, LabelTarget, LineNumber, LocalVariable, LocalVariableType, AbstractPseudoInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/Signature.java b/src/java.base/share/classes/java/lang/classfile/Signature.java index 7255a41528c01..ad2dca0ad462f 100644 --- a/src/java.base/share/classes/java/lang/classfile/Signature.java +++ b/src/java.base/share/classes/java/lang/classfile/Signature.java @@ -30,7 +30,6 @@ import jdk.internal.classfile.impl.SignaturesImpl; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -38,9 +37,8 @@ * Models generic Java type signatures, as defined in JVMS {@jvms 4.7.9.1}. * * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Signature { /** {@return the raw signature string} */ @@ -71,9 +69,8 @@ public static Signature of(ClassDesc classDesc) { /** * Models the signature of a primitive type or void * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface BaseTypeSig extends Signature permits SignaturesImpl.BaseTypeSigImpl { @@ -108,9 +105,8 @@ public static BaseTypeSig of(char baseType) { * type variable, or array type. * * @sealedGraph - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RefTypeSig extends Signature permits ArrayTypeSig, ClassTypeSig, TypeVarSig { @@ -119,9 +115,8 @@ public sealed interface RefTypeSig /** * Models the signature of a possibly-parameterized class or interface type. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassTypeSig extends RefTypeSig, ThrowableSig permits SignaturesImpl.ClassTypeSigImpl { @@ -187,31 +182,27 @@ public static ClassTypeSig of(ClassTypeSig outerType, String className, TypeArg. * Models the type argument. * * @sealedGraph - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface TypeArg { /** * Models an unbounded type argument {@code *}. - * @since 23 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Unbounded extends TypeArg permits SignaturesImpl.UnboundedTypeArgImpl { } /** * Models a type argument with an explicit bound type. - * @since 23 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Bounded extends TypeArg permits SignaturesImpl.TypeArgImpl { /** * Models a type argument's wildcard indicator. - * @since 23 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public enum WildcardIndicator { /** @@ -243,7 +234,6 @@ public enum WildcardIndicator { /** * {@return a bounded type arg} * @param boundType the bound - * @since 23 */ public static TypeArg.Bounded of(RefTypeSig boundType) { requireNonNull(boundType); @@ -252,7 +242,6 @@ public static TypeArg.Bounded of(RefTypeSig boundType) { /** * {@return an unbounded type arg} - * @since 23 */ public static TypeArg.Unbounded unbounded() { return SignaturesImpl.UnboundedTypeArgImpl.INSTANCE; @@ -261,7 +250,6 @@ public static TypeArg.Unbounded unbounded() { /** * {@return an upper-bounded type arg} * @param boundType the upper bound - * @since 23 */ public static TypeArg.Bounded extendsOf(RefTypeSig boundType) { requireNonNull(boundType); @@ -271,7 +259,6 @@ public static TypeArg.Bounded extendsOf(RefTypeSig boundType) { /** * {@return a lower-bounded type arg} * @param boundType the lower bound - * @since 23 */ public static TypeArg.Bounded superOf(RefTypeSig boundType) { requireNonNull(boundType); @@ -282,7 +269,6 @@ public static TypeArg.Bounded superOf(RefTypeSig boundType) { * {@return a bounded type arg} * @param wildcard the wild card * @param boundType optional bound type - * @since 23 */ public static TypeArg.Bounded bounded(Bounded.WildcardIndicator wildcard, RefTypeSig boundType) { requireNonNull(wildcard); @@ -294,9 +280,8 @@ public static TypeArg.Bounded bounded(Bounded.WildcardIndicator wildcard, RefTyp /** * Models the signature of a type variable. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface TypeVarSig extends RefTypeSig, ThrowableSig permits SignaturesImpl.TypeVarSigImpl { @@ -316,9 +301,8 @@ public static TypeVarSig of(String identifier) { /** * Models the signature of an array type. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ArrayTypeSig extends RefTypeSig permits SignaturesImpl.ArrayTypeSigImpl { @@ -352,9 +336,8 @@ public static ArrayTypeSig of(int dims, Signature componentSignature) { /** * Models a signature for a type parameter of a generic class or method. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface TypeParam permits SignaturesImpl.TypeParamImpl { @@ -398,9 +381,8 @@ public static TypeParam of(String identifier, Optional classBound, R * Models a signature for a throwable type. * * @sealedGraph - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ThrowableSig extends Signature { } } diff --git a/src/java.base/share/classes/java/lang/classfile/Superclass.java b/src/java.base/share/classes/java/lang/classfile/Superclass.java index a69fac6341a11..fe30fe8a8e3f7 100644 --- a/src/java.base/share/classes/java/lang/classfile/Superclass.java +++ b/src/java.base/share/classes/java/lang/classfile/Superclass.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -27,15 +27,13 @@ import java.lang.classfile.constantpool.ClassEntry; import jdk.internal.classfile.impl.SuperclassImpl; -import jdk.internal.javac.PreviewFeature; /** * Models the superclass of a class. Delivered as a {@link * java.lang.classfile.ClassElement} when traversing a {@link ClassModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Superclass extends ClassElement permits SuperclassImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/TypeAnnotation.java b/src/java.base/share/classes/java/lang/classfile/TypeAnnotation.java index 38e5ea09a9328..9353b30a6430e 100644 --- a/src/java.base/share/classes/java/lang/classfile/TypeAnnotation.java +++ b/src/java.base/share/classes/java/lang/classfile/TypeAnnotation.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.TargetInfoImpl; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; import static java.lang.classfile.TypeAnnotation.TargetInfo.*; @@ -52,18 +51,16 @@ * @see RuntimeVisibleTypeAnnotationsAttribute * @see RuntimeInvisibleTypeAnnotationsAttribute * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface TypeAnnotation permits UnboundAttribute.UnboundTypeAnnotation { /** * The kind of target on which the annotation appears, as defined in JVMS {@jvms 4.7.20.1}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public enum TargetType { /** For annotations on a class type parameter declaration. */ CLASS_TYPE_PARAMETER(TARGET_CLASS_TYPE_PARAMETER, 1), @@ -193,9 +190,8 @@ static TypeAnnotation of(TargetInfo targetInfo, List targetPa * Specifies which type in a declaration or expression is being annotated. * * @sealedGraph - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface TargetInfo { /** @@ -611,9 +607,8 @@ static TypeArgumentTarget ofMethodReferenceTypeArgument(Label target, int typeAr * parameter of a generic class, generic interface, generic method, or * generic constructor. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface TypeParameterTarget extends TargetInfo permits TargetInfoImpl.TypeParameterTargetImpl { @@ -630,9 +625,8 @@ sealed interface TypeParameterTarget extends TargetInfo * Indicates that an annotation appears on a type in the extends or implements * clause of a class or interface declaration. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface SupertypeTarget extends TargetInfo permits TargetInfoImpl.SupertypeTargetImpl { @@ -654,9 +648,8 @@ sealed interface SupertypeTarget extends TargetInfo * type parameter declaration of a generic class, interface, method, or * constructor. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface TypeParameterBoundTarget extends TargetInfo permits TargetInfoImpl.TypeParameterBoundTargetImpl { @@ -680,9 +673,8 @@ sealed interface TypeParameterBoundTarget extends TargetInfo * declaration, the return type of a method, the type of a newly constructed * object, or the receiver type of a method or constructor. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface EmptyTarget extends TargetInfo permits TargetInfoImpl.EmptyTargetImpl { } @@ -691,9 +683,8 @@ sealed interface EmptyTarget extends TargetInfo * Indicates that an annotation appears on the type in a formal parameter * declaration of a method, constructor, or lambda expression. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface FormalParameterTarget extends TargetInfo permits TargetInfoImpl.FormalParameterTargetImpl { @@ -710,9 +701,8 @@ sealed interface FormalParameterTarget extends TargetInfo * Indicates that an annotation appears on the i'th type in the throws * clause of a method or constructor declaration. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface ThrowsTarget extends TargetInfo permits TargetInfoImpl.ThrowsTargetImpl { @@ -730,9 +720,8 @@ sealed interface ThrowsTarget extends TargetInfo * Indicates that an annotation appears on the type in a local variable declaration, * including a variable declared as a resource in a try-with-resources statement. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface LocalVarTarget extends TargetInfo permits TargetInfoImpl.LocalVarTargetImpl { @@ -747,9 +736,8 @@ sealed interface LocalVarTarget extends TargetInfo * has a value, and the index into the local variable array of the current * frame at which that local variable can be found. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface LocalVarTargetInfo permits TargetInfoImpl.LocalVarTargetInfoImpl { @@ -794,9 +782,8 @@ static LocalVarTargetInfo of(Label startLabel, Label endLabel, int index) { * Indicates that an annotation appears on the i'th type in an exception parameter * declaration. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface CatchTarget extends TargetInfo permits TargetInfoImpl.CatchTargetImpl { @@ -813,9 +800,8 @@ sealed interface CatchTarget extends TargetInfo * Indicates that an annotation appears on either the type in an instanceof expression * or a new expression, or the type before the :: in a method reference expression. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface OffsetTarget extends TargetInfo permits TargetInfoImpl.OffsetTargetImpl { @@ -835,9 +821,8 @@ sealed interface OffsetTarget extends TargetInfo * expression, an explicit constructor invocation statement, a method invocation expression, or a method reference * expression. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface TypeArgumentTarget extends TargetInfo permits TargetInfoImpl.TypeArgumentTargetImpl { @@ -871,18 +856,16 @@ sealed interface TypeArgumentTarget extends TargetInfo * JVMS: Type_path structure identifies which part of the type is annotated, * as defined in JVMS {@jvms 4.7.20.2} * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface TypePathComponent permits UnboundAttribute.TypePathComponentImpl { /** * Type path kind, as defined in JVMS {@jvms 4.7.20.2} * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public enum Kind { /** Annotation is deeper in an array type */ diff --git a/src/java.base/share/classes/java/lang/classfile/TypeKind.java b/src/java.base/share/classes/java/lang/classfile/TypeKind.java index bdbea7c8c54a3..5a6475aa801c4 100644 --- a/src/java.base/share/classes/java/lang/classfile/TypeKind.java +++ b/src/java.base/share/classes/java/lang/classfile/TypeKind.java @@ -30,7 +30,6 @@ import java.lang.constant.ConstantDescs; import java.lang.invoke.TypeDescriptor; -import jdk.internal.javac.PreviewFeature; import jdk.internal.vm.annotation.Stable; /** @@ -54,9 +53,8 @@ * * @jvms 2.2 Data Types * @jvms 2.11.1 Types and the Java Virtual Machine - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public enum TypeKind { // Elements are grouped so frequently used switch ranges such as // primitives (boolean - double) and computational (int - void) are together. @@ -166,7 +164,6 @@ private ClassDesc fetchUpperBound() { /** * {@return the code used by the {@link Opcode#NEWARRAY newarray} instruction to create an array * of this component type, or {@code -1} if this type is not supported by {@code newarray}} - * @since 23 * @jvms 6.5.newarray newarray */ public int newarrayCode() { @@ -198,7 +195,6 @@ public TypeKind asLoadable() { * newarray}} * @param newarrayCode the operand of the {@code newarray} instruction * @throws IllegalArgumentException if the code is invalid - * @since 23 * @jvms 6.5.newarray newarray */ public static TypeKind fromNewarrayCode(int newarrayCode) { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/AnnotationDefaultAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/AnnotationDefaultAttribute.java index 4f147b0d63a47..206c0a8408770 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/AnnotationDefaultAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/AnnotationDefaultAttribute.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code AnnotationDefault} attribute (JVMS {@jvms 4.7.22}), which can @@ -46,9 +45,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface AnnotationDefaultAttribute extends Attribute, MethodElement permits BoundAttribute.BoundAnnotationDefaultAttr, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/BootstrapMethodsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/BootstrapMethodsAttribute.java index 26ef1d3ddafc8..bbea96dc16236 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/BootstrapMethodsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/BootstrapMethodsAttribute.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code BootstrapMethods} attribute (JVMS {@jvms 4.7.23}), which serves as @@ -45,9 +44,8 @@ *

* The attribute was introduced in the Java SE Platform version 7. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface BootstrapMethodsAttribute extends Attribute permits BoundAttribute.BoundBootstrapMethodsAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeInfo.java index 126ba1037cefb..ab37c372c2971 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeInfo.java @@ -27,14 +27,12 @@ import java.lang.classfile.instruction.CharacterRange; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models a single character range in the {@link CharacterRangeTableAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CharacterRangeInfo permits UnboundAttribute.UnboundCharacterRangeInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeTableAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeTableAttribute.java index a4b79be62f057..42a8443f2f61b 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeTableAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/CharacterRangeTableAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,7 +30,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * The CharacterRangeTable attribute is an optional variable-length attribute in @@ -58,9 +57,8 @@ *

* The attribute permits multiple instances in a given location. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CharacterRangeTableAttribute extends Attribute permits BoundAttribute.BoundCharacterRangeTableAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/CodeAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/CodeAttribute.java index 3342c2648ed93..9bc9e975d120e 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/CodeAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/CodeAttribute.java @@ -30,7 +30,6 @@ import java.lang.classfile.Label; import jdk.internal.classfile.impl.BoundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code Code} attribute (JVMS {@jvms 4.7.3}), appears on non-native, @@ -42,9 +41,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CodeAttribute extends Attribute, CodeModel permits BoundAttribute.BoundCodeAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/CompilationIDAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/CompilationIDAttribute.java index 292b449c628f1..8311a8e045ced 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/CompilationIDAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/CompilationIDAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code CompilationID} attribute (@@@ need reference), which can @@ -44,9 +43,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CompilationIDAttribute extends Attribute, ClassElement permits BoundAttribute.BoundCompilationIDAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ConstantValueAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ConstantValueAttribute.java index cd87464855191..54f4742ab0c77 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ConstantValueAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ConstantValueAttribute.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code ConstantValue} attribute (JVMS {@jvms 4.7.2}), which can appear on @@ -44,9 +43,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ConstantValueAttribute extends Attribute, FieldElement permits BoundAttribute.BoundConstantValueAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/DeprecatedAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/DeprecatedAttribute.java index 47c85c4b6c1d6..9e470711e1f5d 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/DeprecatedAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/DeprecatedAttribute.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code Deprecated} attribute (JVMS {@jvms 4.7.15}), which can appear on @@ -41,9 +40,8 @@ *

* The attribute permits multiple instances in a given location. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface DeprecatedAttribute extends Attribute, ClassElement, MethodElement, FieldElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/EnclosingMethodAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/EnclosingMethodAttribute.java index c760fdee04bbe..06ded8c82a57c 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/EnclosingMethodAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/EnclosingMethodAttribute.java @@ -37,7 +37,6 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code EnclosingMethod} attribute (JVMS {@jvms 4.7.7}), which can appear @@ -51,9 +50,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface EnclosingMethodAttribute extends Attribute, ClassElement permits BoundAttribute.BoundEnclosingMethodAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ExceptionsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ExceptionsAttribute.java index 91f07d94de90e..67732e10e819c 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ExceptionsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ExceptionsAttribute.java @@ -34,7 +34,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code Exceptions} attribute (JVMS {@jvms 4.7.5}), which can appear on @@ -46,9 +45,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ExceptionsAttribute extends Attribute, MethodElement permits BoundAttribute.BoundExceptionsAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassInfo.java index fca8cce7faae2..6965d5fdfd222 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -34,14 +34,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single inner class in the {@link InnerClassesAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface InnerClassInfo permits UnboundAttribute.UnboundInnerClassInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassesAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassesAttribute.java index 3b5d63822c498..463a29f939822 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassesAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/InnerClassesAttribute.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code InnerClasses} attribute (JVMS {@jvms 4.7.6}), which can @@ -43,9 +42,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface InnerClassesAttribute extends Attribute, ClassElement permits BoundAttribute.BoundInnerClassesAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberInfo.java index 6e83284f6b144..7e148cec9c1e0 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -25,14 +25,12 @@ package java.lang.classfile.attribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models a single line number in the {@link LineNumberTableAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LineNumberInfo permits UnboundAttribute.UnboundLineNumberInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberTableAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberTableAttribute.java index bb636a8113f73..1c00745218a3d 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberTableAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/LineNumberTableAttribute.java @@ -29,7 +29,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code LineNumberTable} attribute (JVMS {@jvms 4.7.12}), which can appear @@ -41,9 +40,8 @@ *

* The attribute permits multiple instances in a given location. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LineNumberTableAttribute extends Attribute permits BoundAttribute.BoundLineNumberTableAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableInfo.java index 177fc84248316..2b4030b46a617 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,14 +30,12 @@ import jdk.internal.classfile.impl.BoundLocalVariable; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single local variable in the {@link LocalVariableTableAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LocalVariableInfo permits UnboundAttribute.UnboundLocalVariableInfo, BoundLocalVariable { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTableAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTableAttribute.java index ad4e732073e35..8f44ab2905f27 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTableAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTableAttribute.java @@ -29,7 +29,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code LocalVariableTable} attribute (JVMS {@jvms 4.7.13}), which can appear @@ -41,9 +40,8 @@ *

* The attribute permits multiple instances in a given location. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LocalVariableTableAttribute extends Attribute permits BoundAttribute.BoundLocalVariableTableAttribute, UnboundAttribute.UnboundLocalVariableTableAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeInfo.java index 6ba5b409b5b72..e7a137102aee0 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -28,14 +28,12 @@ import jdk.internal.classfile.impl.BoundLocalVariableType; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models a single local variable in the {@link LocalVariableTypeTableAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LocalVariableTypeInfo permits UnboundAttribute.UnboundLocalVariableTypeInfo, BoundLocalVariableType { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeTableAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeTableAttribute.java index 084b72d68381a..2bf7b7a87b33d 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeTableAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/LocalVariableTypeTableAttribute.java @@ -30,7 +30,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code LocalVariableTypeTable} attribute (JVMS {@jvms 4.7.14}), which can appear @@ -44,9 +43,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LocalVariableTypeTableAttribute extends Attribute permits BoundAttribute.BoundLocalVariableTypeTableAttribute, UnboundAttribute.UnboundLocalVariableTypeTableAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/MethodParameterInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/MethodParameterInfo.java index b0961bf147691..35301a30284a1 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/MethodParameterInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/MethodParameterInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,14 +33,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single method parameter in the {@link MethodParametersAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodParameterInfo permits UnboundAttribute.UnboundMethodParameterInfo { /** diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/MethodParametersAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/MethodParametersAttribute.java index 43a43d25bb733..3b3bacbbca5a3 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/MethodParametersAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/MethodParametersAttribute.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code MethodParameters} attribute (JVMS {@jvms 4.7.24}), which can @@ -45,9 +44,8 @@ *

* The attribute was introduced in the Java SE Platform version 8. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodParametersAttribute extends Attribute, MethodElement permits BoundAttribute.BoundMethodParametersAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java index 7091bbd5c4276..07e0f2baa12c7 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleAttribute.java @@ -43,7 +43,6 @@ import jdk.internal.classfile.impl.ModuleAttributeBuilderImpl; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code Module} attribute (JVMS {@jvms 4.7.25}), which can @@ -57,9 +56,8 @@ *

* The attribute was introduced in the Java SE Platform version 9. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleAttribute extends Attribute, ClassElement permits BoundAttribute.BoundModuleAttribute, UnboundAttribute.UnboundModuleAttribute { @@ -172,9 +170,8 @@ static ModuleAttribute of(ModuleEntry moduleName, /** * A builder for module attributes. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleAttributeBuilder permits ModuleAttributeBuilderImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleExportInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleExportInfo.java index 4a534894e9e16..69290c5599415 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleExportInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleExportInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,14 +37,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single "exports" declaration in the {@link ModuleAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleExportInfo permits UnboundAttribute.UnboundModuleExportInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashInfo.java index 0c85dd14125f9..07616757daac6 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -29,14 +29,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models hash information for a single module in the {@link ModuleHashesAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleHashInfo permits UnboundAttribute.UnboundModuleHashInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashesAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashesAttribute.java index 0d2eb7014841c..918d18bda1e29 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashesAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleHashesAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code ModuleHashes} attribute, which can @@ -68,9 +67,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleHashesAttribute extends Attribute, ClassElement permits BoundAttribute.BoundModuleHashesAttribute, UnboundAttribute.UnboundModuleHashesAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleMainClassAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleMainClassAttribute.java index 67d6e5cc15c71..7f06eb0f95b74 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleMainClassAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleMainClassAttribute.java @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code ModuleMainClass} attribute (JVMS {@jvms 4.7.27}), which can @@ -47,9 +46,8 @@ *

* The attribute was introduced in the Java SE Platform version 9. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleMainClassAttribute extends Attribute, ClassElement permits BoundAttribute.BoundModuleMainClassAttribute, UnboundAttribute.UnboundModuleMainClassAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleOpenInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleOpenInfo.java index 7c5fe948d7807..a16c997362736 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleOpenInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleOpenInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -36,14 +36,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single "opens" declaration in the {@link ModuleAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleOpenInfo permits UnboundAttribute.UnboundModuleOpenInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModulePackagesAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModulePackagesAttribute.java index f2b34ad107dbe..ec0a65742b451 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModulePackagesAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModulePackagesAttribute.java @@ -34,7 +34,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code ModulePackages} attribute (JVMS {@jvms 4.7.26}), which can @@ -48,9 +47,8 @@ *

* The attribute was introduced in the Java SE Platform version 9. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModulePackagesAttribute extends Attribute, ClassElement permits BoundAttribute.BoundModulePackagesAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleProvideInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleProvideInfo.java index 266c73de04f2b..ce68848d4dc2f 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleProvideInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleProvideInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -32,14 +32,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single "provides" declaration in the {@link ModuleAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleProvideInfo permits UnboundAttribute.UnboundModuleProvideInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleRequireInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleRequireInfo.java index d072d0fead885..578a783f277ca 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleRequireInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleRequireInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -35,14 +35,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single "requires" declaration in the {@link ModuleAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleRequireInfo permits UnboundAttribute.UnboundModuleRequiresInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleResolutionAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleResolutionAttribute.java index a6b17fa404152..3457cb8073e5e 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleResolutionAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleResolutionAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,7 +30,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code ModuleResolution} attribute, which can @@ -63,9 +62,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleResolutionAttribute extends Attribute, ClassElement permits BoundAttribute.BoundModuleResolutionAttribute, UnboundAttribute.UnboundModuleResolutionAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleTargetAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleTargetAttribute.java index 226412eccf34c..ac390c3d3910d 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/ModuleTargetAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/ModuleTargetAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code ModuleTarget} attribute, which can @@ -58,9 +57,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleTargetAttribute extends Attribute, ClassElement permits BoundAttribute.BoundModuleTargetAttribute, UnboundAttribute.UnboundModuleTargetAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/NestHostAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/NestHostAttribute.java index 6b69f9cbe080c..ccfb61242cdc3 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/NestHostAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/NestHostAttribute.java @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code NestHost} attribute (JVMS {@jvms 4.7.28}), which can @@ -47,9 +46,8 @@ *

* The attribute was introduced in the Java SE Platform version 11. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NestHostAttribute extends Attribute, ClassElement permits BoundAttribute.BoundNestHostAttribute, UnboundAttribute.UnboundNestHostAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/NestMembersAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/NestMembersAttribute.java index 8826b4953a598..b01c05542de75 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/NestMembersAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/NestMembersAttribute.java @@ -34,7 +34,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code NestMembers} attribute (JVMS {@jvms 4.7.29}), which can @@ -48,9 +47,8 @@ *

* The attribute was introduced in the Java SE Platform version 11. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NestMembersAttribute extends Attribute, ClassElement permits BoundAttribute.BoundNestMembersAttribute, UnboundAttribute.UnboundNestMembersAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/PermittedSubclassesAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/PermittedSubclassesAttribute.java index 1242bc6e04543..dac63c734350b 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/PermittedSubclassesAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/PermittedSubclassesAttribute.java @@ -34,7 +34,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code PermittedSubclasses} attribute (JVMS {@jvms 4.7.31}), which can @@ -48,9 +47,8 @@ *

* The attribute was introduced in the Java SE Platform version 17. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface PermittedSubclassesAttribute extends Attribute, ClassElement permits BoundAttribute.BoundPermittedSubclassesAttribute, UnboundAttribute.UnboundPermittedSubclassesAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RecordAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/RecordAttribute.java index 7ef3b6f41b665..b0c4fa7c61cfb 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RecordAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RecordAttribute.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code Record} attribute (JVMS {@jvms 4.7.30}), which can @@ -45,9 +44,8 @@ *

* The attribute was introduced in the Java SE Platform version 16. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RecordAttribute extends Attribute, ClassElement permits BoundAttribute.BoundRecordAttribute, UnboundAttribute.UnboundRecordAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RecordComponentInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/RecordComponentInfo.java index ef6385653ed53..73e4497915e22 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RecordComponentInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RecordComponentInfo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -34,14 +34,12 @@ import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a single record component in the {@link java.lang.classfile.attribute.RecordAttribute}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RecordComponentInfo extends AttributedElement permits BoundRecordComponentInfo, UnboundAttribute.UnboundRecordComponentInfo { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleAnnotationsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleAnnotationsAttribute.java index 05635af4beb4f..589038594642a 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleAnnotationsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleAnnotationsAttribute.java @@ -34,7 +34,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code RuntimeInvisibleAnnotations} attribute (JVMS {@jvms 4.7.17}), which @@ -48,9 +47,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RuntimeInvisibleAnnotationsAttribute extends Attribute, ClassElement, MethodElement, FieldElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleParameterAnnotationsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleParameterAnnotationsAttribute.java index edb82c49900ff..f1c02b77e1e83 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleParameterAnnotationsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleParameterAnnotationsAttribute.java @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code RuntimeInvisibleParameterAnnotations} attribute @@ -46,9 +45,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RuntimeInvisibleParameterAnnotationsAttribute extends Attribute, MethodElement permits BoundAttribute.BoundRuntimeInvisibleParameterAnnotationsAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleTypeAnnotationsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleTypeAnnotationsAttribute.java index df3a035d62099..7500d39fc19fa 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleTypeAnnotationsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeInvisibleTypeAnnotationsAttribute.java @@ -35,7 +35,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code RuntimeInvisibleTypeAnnotations} attribute (JVMS {@jvms 4.7.21}), which @@ -50,9 +49,8 @@ *

* The attribute was introduced in the Java SE Platform version 8. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RuntimeInvisibleTypeAnnotationsAttribute extends Attribute, ClassElement, MethodElement, FieldElement, CodeElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleAnnotationsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleAnnotationsAttribute.java index 6909518881807..d41fcf3794bdf 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleAnnotationsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleAnnotationsAttribute.java @@ -34,7 +34,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code RuntimeVisibleAnnotations} attribute (JVMS {@jvms 4.7.16}), which @@ -48,9 +47,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RuntimeVisibleAnnotationsAttribute extends Attribute, ClassElement, MethodElement, FieldElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleParameterAnnotationsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleParameterAnnotationsAttribute.java index ef58d21f14ac4..5ed9817eeb90d 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleParameterAnnotationsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleParameterAnnotationsAttribute.java @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code RuntimeVisibleParameterAnnotations} attribute (JVMS {@jvms 4.7.18}), which @@ -46,9 +45,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RuntimeVisibleParameterAnnotationsAttribute extends Attribute, MethodElement permits BoundAttribute.BoundRuntimeVisibleParameterAnnotationsAttribute, diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleTypeAnnotationsAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleTypeAnnotationsAttribute.java index 20dc89d700cdd..a4e780c45365b 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleTypeAnnotationsAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/RuntimeVisibleTypeAnnotationsAttribute.java @@ -35,7 +35,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code RuntimeVisibleTypeAnnotations} attribute (JVMS {@jvms 4.7.20}), which @@ -50,9 +49,8 @@ *

* The attribute was introduced in the Java SE Platform version 8. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface RuntimeVisibleTypeAnnotationsAttribute extends Attribute, ClassElement, MethodElement, FieldElement, CodeElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/SignatureAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/SignatureAttribute.java index ca4cc62852a5f..8f06e16a1b191 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/SignatureAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/SignatureAttribute.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code Signature} attribute (JVMS {@jvms 4.7.9}), which @@ -46,9 +45,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface SignatureAttribute extends Attribute, ClassElement, MethodElement, FieldElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/SourceDebugExtensionAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/SourceDebugExtensionAttribute.java index e181b7fb14a2e..0e6b72672639a 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/SourceDebugExtensionAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/SourceDebugExtensionAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,7 +30,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code SourceDebugExtension} attribute. @@ -43,9 +42,8 @@ *

* The attribute was introduced in the Java SE Platform version 5.0. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface SourceDebugExtensionAttribute extends Attribute, ClassElement permits BoundAttribute.BoundSourceDebugExtensionAttribute, UnboundAttribute.UnboundSourceDebugExtensionAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/SourceFileAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/SourceFileAttribute.java index d6c40058e7b74..70f3d1e72ced9 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/SourceFileAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/SourceFileAttribute.java @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code SourceFile} attribute (JVMS {@jvms 4.7.10}), which @@ -44,9 +43,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface SourceFileAttribute extends Attribute, ClassElement permits BoundAttribute.BoundSourceFileAttribute, UnboundAttribute.UnboundSourceFileAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/SourceIDAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/SourceIDAttribute.java index 69ff3bf57fd44..71fd9d5b059a1 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/SourceIDAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/SourceIDAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code SourceID} attribute, which can @@ -44,9 +43,8 @@ * Subsequent occurrence of the attribute takes precedence during the attributed * element build or transformation. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface SourceIDAttribute extends Attribute, ClassElement permits BoundAttribute.BoundSourceIDAttribute, UnboundAttribute.UnboundSourceIDAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/StackMapFrameInfo.java b/src/java.base/share/classes/java/lang/classfile/attribute/StackMapFrameInfo.java index d041a73c58a1c..920db8ac9d701 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/StackMapFrameInfo.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/StackMapFrameInfo.java @@ -32,14 +32,12 @@ import jdk.internal.classfile.impl.StackMapDecoder; import jdk.internal.classfile.impl.TemporaryConstantPool; -import jdk.internal.javac.PreviewFeature; /** * Models stack map frame of {@code StackMapTable} attribute (JVMS {@jvms 4.7.4}). * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface StackMapFrameInfo permits StackMapDecoder.StackMapFrameImpl { @@ -79,9 +77,8 @@ public static StackMapFrameInfo of(Label target, /** * The type of a stack value. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface VerificationTypeInfo { /** The {@link #tag() tag} for verification type info {@link SimpleVerificationTypeInfo#TOP TOP}. */ @@ -124,9 +121,8 @@ sealed interface VerificationTypeInfo { /** * A simple stack value. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public enum SimpleVerificationTypeInfo implements VerificationTypeInfo { /** verification type top */ @@ -166,9 +162,8 @@ public int tag() { /** * A stack value for an object type. Its {@link #tag() tag} is {@value #ITEM_OBJECT}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface ObjectVerificationTypeInfo extends VerificationTypeInfo permits StackMapDecoder.ObjectVerificationTypeInfoImpl { @@ -205,9 +200,8 @@ default ClassDesc classSymbol() { /** * An uninitialized stack value. Its {@link #tag() tag} is {@value #ITEM_UNINITIALIZED}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface UninitializedVerificationTypeInfo extends VerificationTypeInfo permits StackMapDecoder.UninitializedVerificationTypeInfoImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/StackMapTableAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/StackMapTableAttribute.java index a8aef4795d78d..0d577fb6cd565 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/StackMapTableAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/StackMapTableAttribute.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code StackMapTable} attribute (JVMS {@jvms 4.7.4}), which can appear @@ -43,9 +42,8 @@ *

* The attribute was introduced in the Java SE Platform version 6. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface StackMapTableAttribute extends Attribute, CodeElement permits BoundAttribute.BoundStackMapTableAttribute, UnboundAttribute.UnboundStackMapTableAttribute { diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/SyntheticAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/SyntheticAttribute.java index e5b5da7fbfe2e..1e6b706ec08ad 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/SyntheticAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/SyntheticAttribute.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.BoundAttribute; import jdk.internal.classfile.impl.UnboundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models the {@code Synthetic} attribute (JVMS {@jvms 4.7.8}), which can appear on @@ -42,9 +41,8 @@ *

* The attribute permits multiple instances in a given location. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface SyntheticAttribute extends Attribute, ClassElement, MethodElement, FieldElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java index 5c1369e13080f..ad47f35a85688 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,14 +31,12 @@ import java.lang.classfile.MethodElement; import jdk.internal.classfile.impl.BoundAttribute; -import jdk.internal.javac.PreviewFeature; /** * Models an unknown attribute on a class, method, or field. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface UnknownAttribute extends Attribute, ClassElement, MethodElement, FieldElement diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/package-info.java b/src/java.base/share/classes/java/lang/classfile/attribute/package-info.java index 3047ef659e58e..08bd28cbc589a 100644 --- a/src/java.base/share/classes/java/lang/classfile/attribute/package-info.java +++ b/src/java.base/share/classes/java/lang/classfile/attribute/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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 @@ -28,9 +28,7 @@ * * The {@code java.lang.classfile.attribute} package contains interfaces describing classfile attributes. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) package java.lang.classfile.attribute; -import jdk.internal.javac.PreviewFeature; diff --git a/src/java.base/share/classes/java/lang/classfile/components/ClassPrinter.java b/src/java.base/share/classes/java/lang/classfile/components/ClassPrinter.java index 85768cbe6a457..7237dc54580f9 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/ClassPrinter.java +++ b/src/java.base/share/classes/java/lang/classfile/components/ClassPrinter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -36,7 +36,6 @@ import java.util.stream.Stream; import jdk.internal.classfile.impl.ClassPrinterImpl; -import jdk.internal.javac.PreviewFeature; /** * A printer of classfiles and its elements. @@ -60,9 +59,8 @@ * Another use case for {@link ClassPrinter} is to simplify writing of automated tests: * {@snippet lang="java" class="PackageSnippets" region="printNodesInTest"} * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public final class ClassPrinter { private ClassPrinter() { @@ -71,9 +69,8 @@ private ClassPrinter() { /** * Level of detail to print or export. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public enum Verbosity { /** @@ -106,9 +103,8 @@ public enum Verbosity { /** * Named, traversable, and printable node parent. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Node { /** @@ -151,9 +147,8 @@ default void toYaml(Consumer out) { /** * A leaf node holding single printable value. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LeafNode extends Node permits ClassPrinterImpl.LeafNodeImpl { @@ -167,9 +162,8 @@ public sealed interface LeafNode extends Node /** * A tree node holding {@link List} of nested nodes. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ListNode extends Node, List permits ClassPrinterImpl.ListNodeImpl { } @@ -179,9 +173,8 @@ public sealed interface ListNode extends Node, List *

* Each {@link Map.Entry#getKey()} == {@link Map.Entry#getValue()}.{@link #name()}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MapNode extends Node, Map permits ClassPrinterImpl.MapNodeImpl { } diff --git a/src/java.base/share/classes/java/lang/classfile/components/ClassRemapper.java b/src/java.base/share/classes/java/lang/classfile/components/ClassRemapper.java index 4f7bd3199d59d..4a2808ad4f0be 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/ClassRemapper.java +++ b/src/java.base/share/classes/java/lang/classfile/components/ClassRemapper.java @@ -35,7 +35,6 @@ import java.util.function.Function; import jdk.internal.classfile.impl.ClassRemapperImpl; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -55,9 +54,8 @@ * Arrays of reference types are always decomposed, mapped as the base reference * types and composed back to arrays. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassRemapper extends ClassTransform permits ClassRemapperImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/components/CodeLocalsShifter.java b/src/java.base/share/classes/java/lang/classfile/components/CodeLocalsShifter.java index 4983872246102..9db85f54a45bc 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/CodeLocalsShifter.java +++ b/src/java.base/share/classes/java/lang/classfile/components/CodeLocalsShifter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,7 +31,6 @@ import java.lang.reflect.AccessFlag; import jdk.internal.classfile.impl.CodeLocalsShifterImpl; -import jdk.internal.javac.PreviewFeature; /** * {@link CodeLocalsShifter} is a {@link CodeTransform} shifting locals to @@ -39,9 +38,8 @@ * Locals pointing to the receiver or to method arguments slots are never shifted. * All locals pointing beyond the method arguments are re-indexed in order of appearance. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CodeLocalsShifter extends CodeTransform permits CodeLocalsShifterImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/components/CodeRelabeler.java b/src/java.base/share/classes/java/lang/classfile/components/CodeRelabeler.java index 247d712e4f382..4ef82adfdb9bd 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/CodeRelabeler.java +++ b/src/java.base/share/classes/java/lang/classfile/components/CodeRelabeler.java @@ -32,7 +32,6 @@ import java.util.function.BiFunction; import jdk.internal.classfile.impl.CodeRelabelerImpl; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -46,9 +45,8 @@ * Repeated injection of the same code block must be relabeled, so each instance of * {@link java.lang.classfile.Label} is bound in the target bytecode exactly once. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CodeRelabeler extends CodeTransform permits CodeRelabelerImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/components/CodeStackTracker.java b/src/java.base/share/classes/java/lang/classfile/components/CodeStackTracker.java index 1ee0b0948e112..3761e53ff1945 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/CodeStackTracker.java +++ b/src/java.base/share/classes/java/lang/classfile/components/CodeStackTracker.java @@ -31,7 +31,6 @@ import java.util.Optional; import jdk.internal.classfile.impl.CodeStackTrackerImpl; -import jdk.internal.javac.PreviewFeature; /** * {@link CodeStackTracker} is a {@link CodeTransform} tracking stack content @@ -51,9 +50,8 @@ * }); * } * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CodeStackTracker extends CodeTransform permits CodeStackTrackerImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/components/package-info.java b/src/java.base/share/classes/java/lang/classfile/components/package-info.java index 98a0095587d67..be650f4c77c2f 100644 --- a/src/java.base/share/classes/java/lang/classfile/components/package-info.java +++ b/src/java.base/share/classes/java/lang/classfile/components/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -111,9 +111,7 @@ * instrumenting transformation: * {@snippet lang="java" class="PackageSnippets" region="classInstrumentation"} * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) package java.lang.classfile.components; -import jdk.internal.javac.PreviewFeature; diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/AnnotationConstantValueEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/AnnotationConstantValueEntry.java index 82473f51b3d6c..07a85eac4df34 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/AnnotationConstantValueEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/AnnotationConstantValueEntry.java @@ -27,8 +27,6 @@ import java.lang.classfile.AnnotationValue; import java.lang.constant.ConstantDesc; -import jdk.internal.javac.PreviewFeature; - /** * Marker interface for constant pool entries that can represent constant values * associated with elements of annotations. They are also the only entries that @@ -43,9 +41,8 @@ * @see AnnotationValue.OfConstant * @jvms 4.7.16.1 The {@code element_value} structure * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface AnnotationConstantValueEntry extends PoolEntry permits DoubleEntry, FloatEntry, IntegerEntry, LongEntry, Utf8Entry { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ClassEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ClassEntry.java index c43c8a99c92e6..458888d774766 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ClassEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ClassEntry.java @@ -28,7 +28,6 @@ import java.lang.constant.ConstantDesc; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Class_info} structure, representing a reference @@ -60,9 +59,8 @@ * @see ConstantPoolBuilder#classEntry ConstantPoolBuilder::classEntry * @see ClassDesc * @jvms 4.4.1 The {@code CONSTANT_Class_info} Structure - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ClassEntry extends LoadableConstantEntry permits AbstractPoolEntry.ClassEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantDynamicEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantDynamicEntry.java index 3745ce6680926..582bb732cda8b 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantDynamicEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantDynamicEntry.java @@ -31,7 +31,6 @@ import jdk.internal.classfile.impl.AbstractPoolEntry; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Dynamic_info} structure, representing a {@index @@ -65,9 +64,8 @@ * @see java.lang.invoke##condycon Dynamically-computed constants * @jvms 4.4.10 The {@code CONSTANT_Dynamic_info} and {@code * CONSTANT_InvokeDynamic_info} Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ConstantDynamicEntry extends DynamicConstantPoolEntry, LoadableConstantEntry permits AbstractPoolEntry.ConstantDynamicEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java index a350c660fd1b6..859116d113823 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java @@ -31,8 +31,6 @@ import java.util.Iterator; import java.util.NoSuchElementException; -import jdk.internal.javac.PreviewFeature; - /** * Provides read access to the constant pool and the bootstrap method table of a * {@code class} file. @@ -46,9 +44,8 @@ * @see BootstrapMethodsAttribute * @jvms 4.4 The Constant Pool * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ConstantPool extends Iterable permits ClassReader, ConstantPoolBuilder { @@ -83,7 +80,6 @@ public sealed interface ConstantPool extends Iterable * @throws ConstantPoolException if the index is out of range of the * constant pool or considered unusable, or the entry is not * of the given type - * @since 23 */ T entryByIndex(int index, Class cls); diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolBuilder.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolBuilder.java index 334c07e8f2647..0b97f237b4fd6 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolBuilder.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolBuilder.java @@ -41,7 +41,6 @@ import jdk.internal.classfile.impl.SplitConstantPool; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; import static java.util.Objects.requireNonNull; @@ -77,9 +76,8 @@ * entry can be encoded in such an instruction. * * @see ClassFileBuilder#constantPool() ClassFileBuilder::constantPool - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ConstantPoolBuilder extends ConstantPool permits SplitConstantPool, TemporaryConstantPool { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolException.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolException.java index 3b3d82efe2381..281da4e772699 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolException.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPoolException.java @@ -24,7 +24,6 @@ */ package java.lang.classfile.constantpool; -import jdk.internal.javac.PreviewFeature; /** * Thrown to indicate that requested entry cannot be obtained from the constant @@ -32,9 +31,8 @@ * evaluation of constant pool or bootstrap method table entries encounter * format errors. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public class ConstantPoolException extends IllegalArgumentException { @java.io.Serial diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantValueEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantValueEntry.java index d634563623623..79122cc1ae7ca 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantValueEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantValueEntry.java @@ -27,8 +27,6 @@ import java.lang.classfile.Attributes; import java.lang.constant.ConstantDesc; -import jdk.internal.javac.PreviewFeature; - /** * Marker interface for constant pool entries that can represent constant values * in the {@link Attributes#constantValue() ConstantValue} attribute. @@ -36,9 +34,8 @@ * @see ConstantPoolBuilder#constantValueEntry * ConstantPoolBuilder::constantValueEntry * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ConstantValueEntry extends LoadableConstantEntry permits DoubleEntry, FloatEntry, IntegerEntry, LongEntry, StringEntry { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/DoubleEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/DoubleEntry.java index 5c6df982bf060..dffb2fb54e982 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/DoubleEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/DoubleEntry.java @@ -27,7 +27,6 @@ import java.lang.classfile.TypeKind; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Double_info} structure, representing a {@code @@ -49,9 +48,8 @@ * @see ConstantPoolBuilder#doubleEntry ConstantPoolBuilder::doubleEntry * @jvms 4.4.5 The {@code CONSTANT_Long_info} and {@code CONSTANT_Double_info} * Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface DoubleEntry extends AnnotationConstantValueEntry, ConstantValueEntry permits AbstractPoolEntry.DoubleEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/DynamicConstantPoolEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/DynamicConstantPoolEntry.java index 1aaf2afd68284..8726c6046123c 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/DynamicConstantPoolEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/DynamicConstantPoolEntry.java @@ -26,8 +26,6 @@ import java.lang.classfile.BootstrapMethodEntry; -import jdk.internal.javac.PreviewFeature; - /** * Superinterface modeling dynamically-computed constant pool entries, which * include {@link ConstantDynamicEntry} and {@link InvokeDynamicEntry}, in the @@ -50,9 +48,8 @@ * CONSTANT_InvokeDynamic_info} Structures * @jvms 5.4.3.6 Dynamically-Computed Constant and Call Site Resolution * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface DynamicConstantPoolEntry extends PoolEntry permits ConstantDynamicEntry, InvokeDynamicEntry { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/FieldRefEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/FieldRefEntry.java index 0d94331127044..954d79bc3e7f9 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/FieldRefEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/FieldRefEntry.java @@ -28,7 +28,6 @@ import jdk.internal.classfile.impl.AbstractPoolEntry; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Fieldref_info} structure, or a symbolic reference @@ -59,9 +58,8 @@ * @jvms 4.4.2 The {@code CONSTANT_Fieldref_info}, {@code * CONSTANT_Methodref_info}, and {@code * CONSTANT_InterfaceMethodref_info} Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface FieldRefEntry extends MemberRefEntry permits AbstractPoolEntry.FieldRefEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/FloatEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/FloatEntry.java index c21655ca1c853..1926e2502e79e 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/FloatEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/FloatEntry.java @@ -27,7 +27,6 @@ import java.lang.classfile.TypeKind; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Float_info} structure, or a {@code float} constant, @@ -46,9 +45,8 @@ * @see ConstantPoolBuilder#floatEntry ConstantPoolBuilder::floatEntry * @jvms 4.4.4 The {@code CONSTANT_Integer_info} and {@code CONSTANT_Float_info} * Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface FloatEntry extends AnnotationConstantValueEntry, ConstantValueEntry permits AbstractPoolEntry.FloatEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/IntegerEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/IntegerEntry.java index b67e9aa550204..6efa22864b4e3 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/IntegerEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/IntegerEntry.java @@ -27,7 +27,6 @@ import java.lang.classfile.TypeKind; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Integer_info} structure, or an {@code int} constant, @@ -44,9 +43,8 @@ * @see ConstantPoolBuilder#intEntry ConstantPoolBuilder::intEntry * @jvms 4.4.4 The {@code CONSTANT_Integer_info} and {@code CONSTANT_Float_info} * Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface IntegerEntry extends AnnotationConstantValueEntry, ConstantValueEntry permits AbstractPoolEntry.IntegerEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/InterfaceMethodRefEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/InterfaceMethodRefEntry.java index 49f74be525127..2f48ce752a773 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/InterfaceMethodRefEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/InterfaceMethodRefEntry.java @@ -28,7 +28,6 @@ import jdk.internal.classfile.impl.AbstractPoolEntry; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_InterfaceMethodRef_info} structure, or a symbolic @@ -61,9 +60,8 @@ * @jvms 4.4.2 The {@code CONSTANT_Fieldref_info}, {@code * CONSTANT_Methodref_info}, and {@code * CONSTANT_InterfaceMethodref_info} Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface InterfaceMethodRefEntry extends MemberRefEntry permits AbstractPoolEntry.InterfaceMethodRefEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/InvokeDynamicEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/InvokeDynamicEntry.java index cdea5a4100729..748b4cd59be1f 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/InvokeDynamicEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/InvokeDynamicEntry.java @@ -30,7 +30,6 @@ import jdk.internal.classfile.impl.AbstractPoolEntry; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_InvokeDynamic_info} structure, or the symbolic @@ -62,9 +61,8 @@ * ConstantPoolBuilder::invokeDynamicEntry * @jvms 4.4.10 The {@code CONSTANT_Dynamic_info} and {@code * CONSTANT_InvokeDynamic_info} Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface InvokeDynamicEntry extends DynamicConstantPoolEntry permits AbstractPoolEntry.InvokeDynamicEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/LoadableConstantEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/LoadableConstantEntry.java index 50ede47676323..40855369fee62 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/LoadableConstantEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/LoadableConstantEntry.java @@ -30,8 +30,6 @@ import java.lang.classfile.instruction.ConstantInstruction; import java.lang.constant.ConstantDesc; -import jdk.internal.javac.PreviewFeature; - /** * Marker interface for constant pool entries suitable for loading via the * {@link ConstantInstruction.LoadConstantInstruction ldc} instructions. @@ -42,9 +40,8 @@ * ConstantPoolBuilder::loadableConstantEntry * @jvms 4.4 The Constant Pool * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LoadableConstantEntry extends PoolEntry permits ClassEntry, ConstantDynamicEntry, ConstantValueEntry, MethodHandleEntry, MethodTypeEntry { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/LongEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/LongEntry.java index aec5ee7d60e1a..8e618c95218c2 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/LongEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/LongEntry.java @@ -27,7 +27,6 @@ import java.lang.classfile.TypeKind; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Long_info} structure, or a {@code long} constant, in @@ -47,9 +46,8 @@ * @see ConstantPoolBuilder#longEntry ConstantPoolBuilder::longEntry * @jvms 4.4.5 The {@code CONSTANT_Long_info} and {@code CONSTANT_Double_info} * Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LongEntry extends AnnotationConstantValueEntry, ConstantValueEntry permits AbstractPoolEntry.LongEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/MemberRefEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/MemberRefEntry.java index 5d686f6041893..258831a215a6b 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/MemberRefEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/MemberRefEntry.java @@ -25,7 +25,6 @@ package java.lang.classfile.constantpool; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Superinterface modeling symbolic references to a member of a class or interface @@ -47,9 +46,8 @@ * CONSTANT_Methodref_info}, and {@code * CONSTANT_InterfaceMethodref_info} Structures * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MemberRefEntry extends PoolEntry permits FieldRefEntry, InterfaceMethodRefEntry, MethodRefEntry, AbstractPoolEntry.AbstractMemberRefEntry { /** diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/MethodHandleEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/MethodHandleEntry.java index 7897faeb24504..0bdfe2bbcf862 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/MethodHandleEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/MethodHandleEntry.java @@ -30,7 +30,6 @@ import java.lang.invoke.MethodHandleInfo; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_MethodHandle_info} structure, or a symbolic @@ -56,9 +55,8 @@ * ConstantPoolBuilder::methodHandleEntry * @jvms 4.4.8 The {@code CONSTANT_MethodHandle_info} Structure * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodHandleEntry extends LoadableConstantEntry permits AbstractPoolEntry.MethodHandleEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/MethodRefEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/MethodRefEntry.java index 61231bd9e5283..8d15808b4aef4 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/MethodRefEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/MethodRefEntry.java @@ -28,7 +28,6 @@ import jdk.internal.classfile.impl.AbstractPoolEntry; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_MethodRef_info} structure, or a symbolic reference @@ -59,9 +58,8 @@ * @jvms 4.4.2 The {@code CONSTANT_Fieldref_info}, {@code * CONSTANT_Methodref_info}, and {@code * CONSTANT_InterfaceMethodref_info} Structures - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodRefEntry extends MemberRefEntry permits AbstractPoolEntry.MethodRefEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/MethodTypeEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/MethodTypeEntry.java index a1c86b34c5a79..6b317ff935a74 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/MethodTypeEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/MethodTypeEntry.java @@ -28,7 +28,6 @@ import java.lang.constant.MethodTypeDesc; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_MethodType_info} structure, or a symbolic reference @@ -49,9 +48,8 @@ * string. * * @jvms 4.4.9 The {@code CONSTANT_MethodType_info} Structure - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MethodTypeEntry extends LoadableConstantEntry permits AbstractPoolEntry.MethodTypeEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ModuleEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ModuleEntry.java index 5e5d53393c99d..52e944238d1b7 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ModuleEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ModuleEntry.java @@ -27,7 +27,6 @@ import java.lang.constant.ModuleDesc; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Module_info} structure, denoting a module, in the @@ -47,9 +46,8 @@ * where the {@code Utf8Entry} is a {@linkplain #asSymbol() module name}. * * @jvms 4.4.11 The {@code CONSTANT_Module_info} Structure - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ModuleEntry extends PoolEntry permits AbstractPoolEntry.ModuleEntryImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/NameAndTypeEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/NameAndTypeEntry.java index aaef3c1e88d20..f824b04fb81f2 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/NameAndTypeEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/NameAndTypeEntry.java @@ -27,7 +27,6 @@ import java.lang.invoke.TypeDescriptor; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_NameAndType_info} structure, representing a field or @@ -57,9 +56,8 @@ * type} is a field or method descriptor string. * * @jvms 4.4.6 The {@code CONSTANT_NameAndType_info} Structure - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NameAndTypeEntry extends PoolEntry permits AbstractPoolEntry.NameAndTypeEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/PackageEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/PackageEntry.java index 9d9981734bf1d..749e2aeff4869 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/PackageEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/PackageEntry.java @@ -27,7 +27,6 @@ import java.lang.constant.PackageDesc; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_Package_info}, representing a package, in the @@ -49,9 +48,8 @@ * internal form} of a binary package name and is not empty. * * @jvms 4.4.12 The {@code CONSTANT_Package_info} Structure - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface PackageEntry extends PoolEntry permits AbstractPoolEntry.PackageEntryImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java index d6dec01793267..05dd22c7075ae 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/PoolEntry.java @@ -27,8 +27,6 @@ import java.lang.classfile.Attribute; import java.lang.classfile.ClassFileBuilder; -import jdk.internal.javac.PreviewFeature; - /** * Models an entry in the constant pool of a {@code class} file. * @@ -45,9 +43,8 @@ * * @see ConstantPoolBuilder##adoption Non-directly-writable constant pool entries * @sealedGraph - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface PoolEntry permits AnnotationConstantValueEntry, DynamicConstantPoolEntry, LoadableConstantEntry, MemberRefEntry, ModuleEntry, NameAndTypeEntry, diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/StringEntry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/StringEntry.java index 1a1760930a594..1a40a96a31eca 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/StringEntry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/StringEntry.java @@ -25,7 +25,6 @@ package java.lang.classfile.constantpool; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_String_info} structure, or a string constant, in the @@ -44,9 +43,8 @@ * } * * @jvms 4.4.3 The {@code CONSTANT_String_info} Structure - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface StringEntry extends ConstantValueEntry permits AbstractPoolEntry.StringEntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/Utf8Entry.java b/src/java.base/share/classes/java/lang/classfile/constantpool/Utf8Entry.java index c3b7f52a88d62..9af15332766e8 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/Utf8Entry.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/Utf8Entry.java @@ -27,7 +27,6 @@ import java.io.DataInput; import jdk.internal.classfile.impl.AbstractPoolEntry; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code CONSTANT_UTF8_info} constant, representing strings, in the @@ -48,9 +47,8 @@ * * @jvms 4.4.7 The {@code CONSTANT_Utf8_info} Structure * @see DataInput##modified-utf-8 Modified UTF-8 - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface Utf8Entry extends CharSequence, AnnotationConstantValueEntry permits AbstractPoolEntry.Utf8EntryImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/package-info.java b/src/java.base/share/classes/java/lang/classfile/constantpool/package-info.java index 5c6a04a54b897..2aa3595113c89 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/package-info.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/package-info.java @@ -65,14 +65,11 @@ * references can be copied in batch, speeding up class building. This is especially applicable to class transformations, * and {@link ClassFile.ConstantPoolSharingOption ConstantPoolSharingOption} exists to control this behavior. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) package java.lang.classfile.constantpool; import java.lang.classfile.ClassFile; import java.lang.classfile.ClassFileBuilder; import java.lang.classfile.ClassModel; import java.lang.classfile.MethodModel; - -import jdk.internal.javac.PreviewFeature; diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/ArrayLoadInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/ArrayLoadInstruction.java index b66627ef212a6..cc0e0b89f804e 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/ArrayLoadInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/ArrayLoadInstruction.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models an array load instruction in the {@code code} array of a {@code Code} @@ -40,9 +39,8 @@ * Opcode.Kind#ARRAY_LOAD}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ArrayLoadInstruction extends Instruction permits AbstractInstruction.UnboundArrayLoadInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/ArrayStoreInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/ArrayStoreInstruction.java index f009cfca36129..c350b3a59289c 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/ArrayStoreInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/ArrayStoreInstruction.java @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models an array store instruction in the {@code code} array of a {@code Code} @@ -40,9 +39,8 @@ * Opcode.Kind#ARRAY_STORE}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ArrayStoreInstruction extends Instruction permits AbstractInstruction.UnboundArrayStoreInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/BranchInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/BranchInstruction.java index 6b2142fa0e101..2fdc00fced15b 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/BranchInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/BranchInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a branching instruction (conditional or unconditional) in the {@code @@ -40,9 +39,8 @@ * {@code kind} of {@link Opcode.Kind#BRANCH}. Delivered as a {@link * CodeElement} when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface BranchInstruction extends Instruction permits AbstractInstruction.BoundBranchInstruction, AbstractInstruction.UnboundBranchInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/CharacterRange.java b/src/java.base/share/classes/java/lang/classfile/instruction/CharacterRange.java index 3d04473ab3750..d47639d7dd7e0 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/CharacterRange.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/CharacterRange.java @@ -34,7 +34,6 @@ import jdk.internal.classfile.impl.AbstractPseudoInstruction; import jdk.internal.classfile.impl.BoundCharacterRange; -import jdk.internal.javac.PreviewFeature; /** * A pseudo-instruction which models a single entry in the @@ -42,9 +41,8 @@ * during traversal of the elements of a {@link CodeModel}, according to * the setting of the {@link ClassFile.DebugElementsOption} option. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface CharacterRange extends PseudoInstruction permits AbstractPseudoInstruction.UnboundCharacterRange, BoundCharacterRange { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/ConstantInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/ConstantInstruction.java index c41793c614e7f..312c1868f1964 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/ConstantInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/ConstantInstruction.java @@ -35,7 +35,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a constant-load instruction in the {@code code} array of a {@code @@ -45,9 +44,8 @@ * a {@code kind} of {@link Opcode.Kind#CONSTANT}. Delivered as a {@link * CodeElement} when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ConstantInstruction extends Instruction { /** @@ -64,9 +62,8 @@ public sealed interface ConstantInstruction extends Instruction { * Models an "intrinsic constant" instruction (e.g., {@code * iconst_0}). * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface IntrinsicConstantInstruction extends ConstantInstruction permits AbstractInstruction.UnboundIntrinsicConstantInstruction { @@ -83,9 +80,8 @@ default TypeKind typeKind() { * Models an "argument constant" instruction (e.g., {@code * bipush}). * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface ArgumentConstantInstruction extends ConstantInstruction permits AbstractInstruction.BoundArgumentConstantInstruction, AbstractInstruction.UnboundArgumentConstantInstruction { @@ -106,9 +102,8 @@ default TypeKind typeKind() { * Models a "load constant" instruction (e.g., {@code * ldc}). * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface LoadConstantInstruction extends ConstantInstruction permits AbstractInstruction.BoundLoadConstantInstruction, AbstractInstruction.UnboundLoadConstantInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/ConvertInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/ConvertInstruction.java index ec48c2f46639f..468685779b92d 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/ConvertInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/ConvertInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a primitive conversion instruction in the {@code code} array of a @@ -41,9 +40,8 @@ * a {@code kind} of {@link Opcode.Kind#CONVERT}. Delivered as a {@link * CodeElement} when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ConvertInstruction extends Instruction permits AbstractInstruction.UnboundConvertInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java index 0e4718a1c77c8..4e8ddcef385b4 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/DiscontinuedInstruction.java @@ -33,16 +33,14 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models instruction discontinued from the {@code code} array of a {@code Code} * attribute. Delivered as a {@link CodeElement} when traversing the elements of * a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface DiscontinuedInstruction extends Instruction { /** @@ -52,9 +50,8 @@ public sealed interface DiscontinuedInstruction extends Instruction { * {@link Opcode.Kind#DISCONTINUED_JSR}. Delivered as a {@link CodeElement} * when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface JsrInstruction extends DiscontinuedInstruction permits AbstractInstruction.BoundJsrInstruction, AbstractInstruction.UnboundJsrInstruction { @@ -95,9 +92,8 @@ static JsrInstruction of(Label target) { * {@link Opcode.Kind#DISCONTINUED_RET}. Delivered as a {@link CodeElement} * when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ - @PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) sealed interface RetInstruction extends DiscontinuedInstruction permits AbstractInstruction.BoundRetInstruction, AbstractInstruction.UnboundRetInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/ExceptionCatch.java b/src/java.base/share/classes/java/lang/classfile/instruction/ExceptionCatch.java index 22b6f632abcf3..885f029d10824 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/ExceptionCatch.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/ExceptionCatch.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -32,7 +32,6 @@ import java.util.Optional; import jdk.internal.classfile.impl.AbstractPseudoInstruction; -import jdk.internal.javac.PreviewFeature; /** * A pseudo-instruction modeling an entry in the exception table of a code @@ -42,9 +41,8 @@ * * @see PseudoInstruction * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ExceptionCatch extends PseudoInstruction permits AbstractPseudoInstruction.ExceptionCatchImpl { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/FieldInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/FieldInstruction.java index c8a82fe7dfa89..b547abd18abef 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/FieldInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/FieldInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a field access instruction in the {@code code} array of a {@code Code} @@ -45,9 +44,8 @@ * Opcode.Kind#FIELD_ACCESS}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface FieldInstruction extends Instruction permits AbstractInstruction.BoundFieldInstruction, AbstractInstruction.UnboundFieldInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java index 74fd6a4465a1f..7ea516c7cc529 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/IncrementInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,7 +30,6 @@ import java.lang.classfile.Opcode; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a local variable increment instruction in the {@code code} array of a @@ -38,9 +37,8 @@ * {@link Opcode.Kind#INCREMENT}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface IncrementInstruction extends Instruction permits AbstractInstruction.BoundIncrementInstruction, AbstractInstruction.UnboundIncrementInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/InvokeDynamicInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/InvokeDynamicInstruction.java index 6df960b88fab8..43907b2a51874 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/InvokeDynamicInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/InvokeDynamicInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,14 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models an {@code invokedynamic} instruction in the {@code code} array of a * {@code Code} attribute. Delivered as a {@link CodeElement} when traversing * the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface InvokeDynamicInstruction extends Instruction permits AbstractInstruction.BoundInvokeDynamicInstruction, AbstractInstruction.UnboundInvokeDynamicInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/InvokeInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/InvokeInstruction.java index 41ca5fd1519ef..904a17375ac7e 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/InvokeInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/InvokeInstruction.java @@ -39,7 +39,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a method invocation instruction in the {@code code} array of a {@code @@ -47,9 +46,8 @@ * will have a {@code kind} of {@link Opcode.Kind#INVOKE}. Delivered as a * {@link CodeElement} when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface InvokeInstruction extends Instruction permits AbstractInstruction.BoundInvokeInterfaceInstruction, AbstractInstruction.BoundInvokeInstruction, AbstractInstruction.UnboundInvokeInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LabelTarget.java b/src/java.base/share/classes/java/lang/classfile/instruction/LabelTarget.java index 8682d0ee508e6..bc1deffc98b59 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LabelTarget.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LabelTarget.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,7 +30,6 @@ import java.lang.classfile.PseudoInstruction; import jdk.internal.classfile.impl.LabelImpl; -import jdk.internal.javac.PreviewFeature; /** * A pseudo-instruction which indicates that the specified label corresponds to @@ -39,9 +38,8 @@ * * @see PseudoInstruction * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LabelTarget extends PseudoInstruction permits LabelImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LineNumber.java b/src/java.base/share/classes/java/lang/classfile/instruction/LineNumber.java index a06e7cfcebac2..a9a497708c0bd 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LineNumber.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LineNumber.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,7 +31,6 @@ import java.lang.classfile.attribute.LineNumberTableAttribute; import jdk.internal.classfile.impl.LineNumberImpl; -import jdk.internal.javac.PreviewFeature; /** * A pseudo-instruction which models a single entry in the @@ -41,9 +40,8 @@ * * @see PseudoInstruction * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LineNumber extends PseudoInstruction permits LineNumberImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java index ce6463ef92478..c499dcc99443b 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LoadInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a local variable load instruction in the {@code code} array of a @@ -41,9 +40,8 @@ * {@link Opcode.Kind#LOAD}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LoadInstruction extends Instruction permits AbstractInstruction.BoundLoadInstruction, AbstractInstruction.UnboundLoadInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java index 390034bd6663d..0f8cb672e5188 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariable.java @@ -37,7 +37,6 @@ import jdk.internal.classfile.impl.BoundLocalVariable; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * A pseudo-instruction which models a single entry in the @@ -47,9 +46,8 @@ * * @see PseudoInstruction * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LocalVariable extends PseudoInstruction permits AbstractPseudoInstruction.UnboundLocalVariable, BoundLocalVariable { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java index d0d2cd1581fe0..c9427491733ed 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LocalVariableType.java @@ -36,7 +36,6 @@ import jdk.internal.classfile.impl.AbstractPseudoInstruction; import jdk.internal.classfile.impl.BoundLocalVariableType; import jdk.internal.classfile.impl.TemporaryConstantPool; -import jdk.internal.javac.PreviewFeature; /** * A pseudo-instruction which models a single entry in the {@link @@ -44,9 +43,8 @@ * traversal of the elements of a {@link CodeModel}, according to the setting of * the {@link ClassFile.DebugElementsOption} option. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LocalVariableType extends PseudoInstruction permits AbstractPseudoInstruction.UnboundLocalVariableType, BoundLocalVariableType { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/LookupSwitchInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/LookupSwitchInstruction.java index ce6c0cce10999..7b286e9cfd21e 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/LookupSwitchInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/LookupSwitchInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,16 +31,14 @@ import java.util.List; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code lookupswitch} instruction in the {@code code} array of a * {@code Code} attribute. Delivered as a {@link CodeElement} when traversing * the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface LookupSwitchInstruction extends Instruction permits AbstractInstruction.BoundLookupSwitchInstruction, AbstractInstruction.UnboundLookupSwitchInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/MonitorInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/MonitorInstruction.java index 9bec7805339d2..1c8268cddd65f 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/MonitorInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/MonitorInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,16 +31,14 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code monitorenter} or {@code monitorexit} instruction in the * {@code code} array of a {@code Code} attribute. Delivered as a {@link * CodeElement} when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface MonitorInstruction extends Instruction permits AbstractInstruction.UnboundMonitorInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java index f5e0129205cfb..4a1f6cfd170e7 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/NewMultiArrayInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,16 +31,14 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.BytecodeHelpers; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code multianewarray} invocation instruction in the {@code code} * array of a {@code Code} attribute. Delivered as a {@link CodeElement} * when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NewMultiArrayInstruction extends Instruction permits AbstractInstruction.BoundNewMultidimensionalArrayInstruction, AbstractInstruction.UnboundNewMultidimensionalArrayInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/NewObjectInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/NewObjectInstruction.java index e6e8fc64d1763..f063733b64fe6 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/NewObjectInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/NewObjectInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,16 +30,14 @@ import java.lang.classfile.constantpool.ClassEntry; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code new} instruction in the {@code code} array of a {@code Code} * attribute. Delivered as a {@link CodeElement} when traversing the elements * of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NewObjectInstruction extends Instruction permits AbstractInstruction.BoundNewObjectInstruction, AbstractInstruction.UnboundNewObjectInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/NewPrimitiveArrayInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/NewPrimitiveArrayInstruction.java index 4adc7536c2cfd..411bf7f6b55d2 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/NewPrimitiveArrayInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/NewPrimitiveArrayInstruction.java @@ -30,16 +30,14 @@ import java.lang.classfile.TypeKind; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code newarray} invocation instruction in the {@code code} * array of a {@code Code} attribute. Delivered as a {@link CodeElement} * when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NewPrimitiveArrayInstruction extends Instruction permits AbstractInstruction.BoundNewPrimitiveArrayInstruction, AbstractInstruction.UnboundNewPrimitiveArrayInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/NewReferenceArrayInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/NewReferenceArrayInstruction.java index b622f915c464e..c85ed9dd3d9f9 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/NewReferenceArrayInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/NewReferenceArrayInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -30,16 +30,14 @@ import java.lang.classfile.constantpool.ClassEntry; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code anewarray} invocation instruction in the {@code code} * array of a {@code Code} attribute. Delivered as a {@link CodeElement} * when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NewReferenceArrayInstruction extends Instruction permits AbstractInstruction.BoundNewReferenceArrayInstruction, AbstractInstruction.UnboundNewReferenceArrayInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/NopInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/NopInstruction.java index 3183ad888161e..3c11803109a36 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/NopInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/NopInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -29,16 +29,14 @@ import java.lang.classfile.Instruction; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code nop} invocation instruction in the {@code code} * array of a {@code Code} attribute. Delivered as a {@link CodeElement} * when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface NopInstruction extends Instruction permits AbstractInstruction.UnboundNopInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/OperatorInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/OperatorInstruction.java index 602f34ec03e0b..d1eb8aa1a3db8 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/OperatorInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/OperatorInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -32,7 +32,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models an arithmetic operator instruction in the {@code code} array of a @@ -40,9 +39,8 @@ * {@link Opcode.Kind#OPERATOR}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface OperatorInstruction extends Instruction permits AbstractInstruction.UnboundOperatorInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/ReturnInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/ReturnInstruction.java index 6596404a58282..3bbb96b1cbe7f 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/ReturnInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/ReturnInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a return-from-method instruction in the {@code code} array of a @@ -41,9 +40,8 @@ * {@link Opcode.Kind#RETURN}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ReturnInstruction extends Instruction permits AbstractInstruction.UnboundReturnInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/StackInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/StackInstruction.java index 17e9496652b90..b01b206e3681b 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/StackInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/StackInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,7 +31,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a stack manipulation instruction in the {@code code} array of a @@ -39,9 +38,8 @@ * {@link Opcode.Kind#STACK}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface StackInstruction extends Instruction permits AbstractInstruction.UnboundStackInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java index 68bf54e61c28b..1d7bdce1fdfe9 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/StoreInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -33,7 +33,6 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.BytecodeHelpers; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models a local variable store instruction in the {@code code} array of a @@ -41,9 +40,8 @@ * {@link Opcode.Kind#STORE}. Delivered as a {@link CodeElement} when * traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface StoreInstruction extends Instruction permits AbstractInstruction.BoundStoreInstruction, AbstractInstruction.UnboundStoreInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/SwitchCase.java b/src/java.base/share/classes/java/lang/classfile/instruction/SwitchCase.java index 6149945532bf1..3f5f91031b68e 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/SwitchCase.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/SwitchCase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -27,7 +27,6 @@ import java.lang.classfile.Label; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a single case in a {@code lookupswitch} or {@code tableswitch} @@ -36,9 +35,8 @@ * @see LookupSwitchInstruction * @see TableSwitchInstruction * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface SwitchCase permits AbstractInstruction.SwitchCaseImpl { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/TableSwitchInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/TableSwitchInstruction.java index a8bce119db2f8..bbe7a4d6c0c41 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/TableSwitchInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/TableSwitchInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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,16 +31,14 @@ import java.util.List; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models a {@code tableswitch} instruction in the {@code code} array of a * {@code Code} attribute. Delivered as a {@link CodeElement} when traversing * the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface TableSwitchInstruction extends Instruction permits AbstractInstruction.BoundTableSwitchInstruction, AbstractInstruction.UnboundTableSwitchInstruction { /** diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/ThrowInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/ThrowInstruction.java index 68d861ba06dbe..ec6fdc3862637 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/ThrowInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/ThrowInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -29,16 +29,14 @@ import java.lang.classfile.Instruction; import jdk.internal.classfile.impl.AbstractInstruction; -import jdk.internal.javac.PreviewFeature; /** * Models an {@code athrow} instruction in the {@code code} array of a * {@code Code} attribute. Delivered as a {@link CodeElement} when traversing * the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface ThrowInstruction extends Instruction permits AbstractInstruction.UnboundThrowInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/TypeCheckInstruction.java b/src/java.base/share/classes/java/lang/classfile/instruction/TypeCheckInstruction.java index a4b9818a4bebd..032e7a8462b8a 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/TypeCheckInstruction.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/TypeCheckInstruction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -34,16 +34,14 @@ import jdk.internal.classfile.impl.AbstractInstruction; import jdk.internal.classfile.impl.TemporaryConstantPool; import jdk.internal.classfile.impl.Util; -import jdk.internal.javac.PreviewFeature; /** * Models an {@code instanceof} or {@code checkcast} instruction in the {@code * code} array of a {@code Code} attribute. Delivered as a {@link CodeElement} * when traversing the elements of a {@link CodeModel}. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) public sealed interface TypeCheckInstruction extends Instruction permits AbstractInstruction.BoundTypeCheckInstruction, AbstractInstruction.UnboundTypeCheckInstruction { diff --git a/src/java.base/share/classes/java/lang/classfile/instruction/package-info.java b/src/java.base/share/classes/java/lang/classfile/instruction/package-info.java index 2bb35494da08d..d2a36e1661511 100644 --- a/src/java.base/share/classes/java/lang/classfile/instruction/package-info.java +++ b/src/java.base/share/classes/java/lang/classfile/instruction/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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 @@ -28,9 +28,7 @@ * * The {@code java.lang.classfile.attribute} package contains interfaces describing code instructions. * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) package java.lang.classfile.instruction; -import jdk.internal.javac.PreviewFeature; diff --git a/src/java.base/share/classes/java/lang/classfile/package-info.java b/src/java.base/share/classes/java/lang/classfile/package-info.java index 6e9ecfe4819e6..2d6a8959a2de5 100644 --- a/src/java.base/share/classes/java/lang/classfile/package-info.java +++ b/src/java.base/share/classes/java/lang/classfile/package-info.java @@ -546,9 +546,6 @@ * | CharacterRange(int rangeStart, int rangeEnd, int flags, Label startScope, Label endScope) * } * - * @since 22 + * @since 24 */ -@PreviewFeature(feature = PreviewFeature.Feature.CLASSFILE_API) package java.lang.classfile; - -import jdk.internal.javac.PreviewFeature; diff --git a/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java b/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java index a9bfff152e649..b42a8d39353b8 100644 --- a/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java +++ b/src/java.base/share/classes/java/lang/invoke/AbstractValidatingLambdaMetafactory.java @@ -107,9 +107,6 @@ * implemented by invoking the implementation method * @throws LambdaConversionException If any of the meta-factory protocol * invariants are violated - * @throws SecurityException If a security manager is present, and it - * denies access - * from {@code caller} to the package of {@code implementation}. */ AbstractValidatingLambdaMetafactory(MethodHandles.Lookup caller, MethodType factoryType, @@ -138,7 +135,7 @@ this.implementation = implementation; this.implMethodType = implementation.type(); try { - this.implInfo = caller.revealDirect(implementation); // may throw SecurityException + this.implInfo = caller.revealDirect(implementation); } catch (IllegalArgumentException e) { throw new LambdaConversionException(implementation + " is not direct or cannot be cracked"); } diff --git a/src/java.base/share/classes/java/lang/invoke/InfoFromMemberName.java b/src/java.base/share/classes/java/lang/invoke/InfoFromMemberName.java index f01fc0049862f..0e73a02077ab6 100644 --- a/src/java.base/share/classes/java/lang/invoke/InfoFromMemberName.java +++ b/src/java.base/share/classes/java/lang/invoke/InfoFromMemberName.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -25,7 +25,6 @@ package java.lang.invoke; -import java.security.*; import java.lang.reflect.*; import java.lang.invoke.MethodHandles.Lookup; @@ -85,16 +84,13 @@ public T reflectAs(Class expected, Lookup lookup) { // For more information see comments on {@link MethodHandleNatives#linkMethod}. throw new IllegalArgumentException("cannot reflect signature polymorphic method"); } - @SuppressWarnings("removal") - Member mem = AccessController.doPrivileged(new PrivilegedAction<>() { - public Member run() { - try { - return reflectUnchecked(); - } catch (ReflectiveOperationException ex) { - throw new IllegalArgumentException(ex); - } - } - }); + + Member mem; + try { + mem = reflectUnchecked(); + } catch (ReflectiveOperationException ex) { + throw new IllegalArgumentException(ex); + } try { Class defc = getDeclaringClass(); byte refKind = (byte) getReferenceKind(); diff --git a/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java b/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java index 937840049943c..4dac59771e861 100644 --- a/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java +++ b/src/java.base/share/classes/java/lang/invoke/InnerClassLambdaMetafactory.java @@ -29,7 +29,6 @@ import jdk.internal.misc.CDS; import jdk.internal.util.ClassFileDumper; import sun.invoke.util.VerifyAccess; -import sun.security.action.GetBooleanAction; import java.io.Serializable; import java.lang.classfile.ClassBuilder; @@ -83,7 +82,7 @@ lambdaProxyClassFileDumper = ClassFileDumper.getInstance(dumpProxyClassesKey, "DUMP_LAMBDA_PROXY_CLASS_FILES"); final String disableEagerInitializationKey = "jdk.internal.lambda.disableEagerInitialization"; - disableEagerInitialization = GetBooleanAction.privilegedGetProperty(disableEagerInitializationKey); + disableEagerInitialization = Boolean.getBoolean(disableEagerInitializationKey); } // See context values in AbstractValidatingLambdaMetafactory @@ -134,9 +133,6 @@ * implemented by invoking the implementation method * @throws LambdaConversionException If any of the meta-factory protocol * invariants are violated - * @throws SecurityException If a security manager is present, and it - * denies access - * from {@code caller} to the package of {@code implementation}. */ public InnerClassLambdaMetafactory(MethodHandles.Lookup caller, MethodType factoryType, @@ -189,13 +185,17 @@ private static String argName(int i) { return i < ARG_NAME_CACHE.length ? ARG_NAME_CACHE[i] : "arg$" + (i + 1); } - private static String lambdaClassName(Class targetClass) { + private static String sanitizedTargetClassName(Class targetClass) { String name = targetClass.getName(); if (targetClass.isHidden()) { // use the original class name name = name.replace('/', '_'); } - return name.replace('.', '/').concat("$$Lambda"); + return name.replace('.', '/'); + } + + private static String lambdaClassName(Class targetClass) { + return sanitizedTargetClassName(targetClass).concat("$$Lambda"); } /** @@ -434,7 +434,7 @@ private void generateSerializationFriendlyMethods(ClassBuilder clb) { public void accept(CodeBuilder cob) { cob.new_(SerializationSupport.CD_SerializedLambda) .dup() - .ldc(classDesc(targetClass)) + .ldc(ClassDesc.ofInternalName(sanitizedTargetClassName(targetClass))) .ldc(factoryType.returnType().getName().replace('.', '/')) .ldc(interfaceMethodName) .ldc(interfaceMethodType.toMethodDescriptorString()) diff --git a/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java b/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java index 0cc6f62754351..d6099861cee20 100644 --- a/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java +++ b/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java @@ -229,6 +229,22 @@ * used, but this is not compatible with some implementation techniques and * would complicate the work implementations must do. * + *

Uses besides evaluation of lambda expressions and method references are + * unintended. These linkage methods may change their unspecified behaviors at + * any time to better suit the Java language features they were designed to + * support, and such changes may impact unintended uses. Unintended uses of + * these linkage methods may lead to resource leaks, or other unspecified + * negative effects. + * + * @implNote In the reference implementation, the classes implementing the created + * function objects are strongly reachable from the defining class loader of the + * caller, like classes and interfaces in Java source code. This technique + * reduces heap memory use, but as a consequence, the implementation classes can + * be unloaded only if the caller class can be unloaded. In particular, if the + * caller is a {@linkplain MethodHandles.Lookup.ClassOption#STRONG weak hidden + * class}, the implementation class, a strong hidden class, may not be unloaded + * even if the caller may be unloaded. + * * @since 1.8 */ public final class LambdaMetafactory { diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java index fd3e20a524e1b..e94b1dc40f28c 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleImpl.java @@ -1208,11 +1208,7 @@ private static MethodHandle restoreToType(MethodHandle vamh, private static boolean checkInjectedInvoker(Class hostClass, Class invokerClass) { assert (hostClass.getClassLoader() == invokerClass.getClassLoader()) : hostClass.getName()+" (CL)"; - try { - assert (hostClass.getProtectionDomain() == invokerClass.getProtectionDomain()) : hostClass.getName()+" (PD)"; - } catch (SecurityException ex) { - // Self-check was blocked by security manager. This is OK. - } + assert (hostClass.getProtectionDomain() == invokerClass.getProtectionDomain()) : hostClass.getName()+" (PD)"; try { // Test the invoker to ensure that it really injects into the right place. MethodHandle invoker = IMPL_LOOKUP.findStatic(invokerClass, "invoke_V", INVOKER_MT); diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java b/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java index dcfa671a17ff9..0ab2dbfdae935 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleProxies.java @@ -33,8 +33,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.UndeclaredThrowableException; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -56,10 +54,7 @@ import jdk.internal.constant.ConstantUtils; import jdk.internal.loader.ClassLoaders; import jdk.internal.module.Modules; -import jdk.internal.reflect.CallerSensitive; -import jdk.internal.reflect.Reflection; import jdk.internal.util.ClassFileDumper; -import sun.reflect.misc.ReflectUtil; import static java.lang.constant.ConstantDescs.*; import static java.lang.invoke.MethodHandleStatics.*; @@ -159,7 +154,6 @@ private MethodHandleProxies() { } // do not instantiate * be converted to the type required by the requested interface */ @SuppressWarnings("doclint:reference") // cross-module links - @CallerSensitive public static T asInterfaceInstance(final Class intfc, final MethodHandle target) { if (!intfc.isInterface() || !Modifier.isPublic(intfc.getModifiers())) throw newIllegalArgumentException("not a public interface", intfc.getName()); @@ -168,17 +162,7 @@ public static T asInterfaceInstance(final Class intfc, final MethodHandle if (intfc.isHidden()) throw newIllegalArgumentException("a hidden interface", intfc.getName()); Objects.requireNonNull(target); - final MethodHandle mh; - @SuppressWarnings("removal") - var sm = System.getSecurityManager(); - if (sm != null) { - final Class caller = Reflection.getCallerClass(); - final ClassLoader ccl = caller != null ? caller.getClassLoader() : null; - ReflectUtil.checkProxyPackageAccess(ccl, intfc); - mh = ccl != null ? bindCaller(target, caller) : target; - } else { - mh = target; - } + final MethodHandle mh = target; // Define one hidden class for each interface. Create an instance of // the hidden class for a given target method handle which will be @@ -283,17 +267,7 @@ private static Class newProxyClass(Class intfc) { // define the dynamic module to the class loader of the interface var definer = new Lookup(intfc).makeHiddenClassDefiner(className, template, DUMPER); - @SuppressWarnings("removal") - var sm = System.getSecurityManager(); - Lookup lookup; - if (sm != null) { - @SuppressWarnings("removal") - var l = AccessController.doPrivileged((PrivilegedAction) () -> - definer.defineClassAsLookup(true)); - lookup = l; - } else { - lookup = definer.defineClassAsLookup(true); - } + Lookup lookup = definer.defineClassAsLookup(true); // cache the wrapper type var ret = lookup.lookupClass(); WRAPPER_TYPES.add(ret); diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java b/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java index 7d87d4f79a873..f50edd5626a17 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandleStatics.java @@ -28,7 +28,6 @@ import jdk.internal.misc.CDS; import jdk.internal.misc.Unsafe; import jdk.internal.util.ClassFileDumper; -import sun.security.action.GetPropertyAction; import java.lang.reflect.ClassFileFormatVersion; import java.util.Properties; @@ -66,7 +65,7 @@ private MethodHandleStatics() { } // do not instantiate static final ClassFileDumper DUMP_CLASS_FILES; static { - Properties props = GetPropertyAction.privilegedGetProperties(); + Properties props = System.getProperties(); DEBUG_METHOD_HANDLE_NAMES = Boolean.parseBoolean( props.getProperty("java.lang.invoke.MethodHandle.DEBUG_NAMES")); diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java index b077c7304408e..7542b0e513ae1 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java @@ -36,8 +36,6 @@ import sun.invoke.util.ValueConversions; import sun.invoke.util.VerifyAccess; import sun.invoke.util.Wrapper; -import sun.reflect.misc.ReflectUtil; -import sun.security.util.SecurityConstants; import java.lang.classfile.ClassFile; import java.lang.classfile.ClassModel; @@ -243,9 +241,6 @@ public static Lookup privateLookupIn(Class targetClass, Lookup caller) throws return new Lookup(targetClass); } - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) sm.checkPermission(SecurityConstants.ACCESS_PERMISSION); if (targetClass.isPrimitive()) throw new IllegalArgumentException(targetClass + " is a primitive class"); if (targetClass.isArray()) @@ -463,9 +458,6 @@ public static T classDataAt(Lookup caller, String name, Class type, int i * @since 1.8 */ public static T reflectAs(Class expected, MethodHandle target) { - @SuppressWarnings("removal") - SecurityManager smgr = System.getSecurityManager(); - if (smgr != null) smgr.checkPermission(SecurityConstants.ACCESS_PERMISSION); Lookup lookup = Lookup.IMPL_LOOKUP; // use maximally privileged lookup return lookup.revealDirect(target).reflectAs(expected, lookup); } @@ -741,8 +733,6 @@ public static T reflectAs(Class expected, MethodHandle tar *

    *
  • access private fields, methods, and constructors of the lookup class and its nestmates *
  • create method handles which {@link Lookup#findSpecial emulate invokespecial} instructions - *
  • avoid package access checks - * for classes accessible to the lookup class *
  • create {@link Lookup#in delegated lookup objects} which have private access to other classes * within the same package member *
@@ -1759,23 +1749,11 @@ public Lookup dropLookupMode(int modeToDrop) { * @see ClassLoader#defineClass(String,byte[],int,int,ProtectionDomain) */ public Class defineClass(byte[] bytes) throws IllegalAccessException { - ensureDefineClassPermission(); if ((lookupModes() & PACKAGE) == 0) throw new IllegalAccessException("Lookup does not have PACKAGE access"); return makeClassDefiner(bytes.clone()).defineClass(false); } - private void ensureDefineClassPermission() { - if (allowedModes == TRUSTED) return; - - if (!hasFullPrivilegeAccess()) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkPermission(new RuntimePermission("defineClass")); - } - } - /** * The set of class options that specify whether a hidden class created by * {@link Lookup#defineHiddenClass(byte[], boolean, ClassOption...) @@ -2042,7 +2020,6 @@ public Lookup defineHiddenClass(byte[] bytes, boolean initialize, ClassOption... { Objects.requireNonNull(bytes); int flags = ClassOption.optionsToFlag(options); - ensureDefineClassPermission(); if (!hasFullPrivilegeAccess()) { throw new IllegalAccessException(this + " does not have full privilege access"); } @@ -2128,7 +2105,6 @@ public Lookup defineHiddenClassWithClassData(byte[] bytes, Object classData, boo int flags = ClassOption.optionsToFlag(options); - ensureDefineClassPermission(); if (!hasFullPrivilegeAccess()) { throw new IllegalAccessException(this + " does not have full privilege access"); } @@ -2768,7 +2744,6 @@ public Class ensureInitialized(Class targetClass) throws IllegalAccess if (!VerifyAccess.isClassAccessible(targetClass, lookupClass, prevLookupClass, allowedModes)) { throw makeAccessException(targetClass); } - checkSecurityManager(targetClass); // ensure class initialization Unsafe.getUnsafe().ensureClassInitialized(targetClass); @@ -2872,7 +2847,6 @@ public Class accessClass(Class targetClass) throws IllegalAccessExcept if (!isClassAccessible(targetClass)) { throw makeAccessException(targetClass); } - checkSecurityManager(targetClass); return targetClass; } @@ -3292,7 +3266,7 @@ public MethodHandle unreflect(Method m) throws IllegalAccessException { assert(method.isMethod()); @SuppressWarnings("deprecation") Lookup lookup = m.isAccessible() ? IMPL_LOOKUP : this; - return lookup.getDirectMethodNoSecurityManager(refKind, method.getDeclaringClass(), method, findBoundCallerLookup(method)); + return lookup.getDirectMethod(refKind, method.getDeclaringClass(), method, findBoundCallerLookup(method)); } private MethodHandle unreflectForMH(Method m) { // these names require special lookups because they throw UnsupportedOperationException @@ -3343,7 +3317,7 @@ public MethodHandle unreflectSpecial(Method m, Class specialCaller) throws Il MemberName method = new MemberName(m, true); assert(method.isMethod()); // ignore m.isAccessible: this is a new kind of access - return specialLookup.getDirectMethodNoSecurityManager(REF_invokeSpecial, method.getDeclaringClass(), method, findBoundCallerLookup(method)); + return specialLookup.getDirectMethod(REF_invokeSpecial, method.getDeclaringClass(), method, findBoundCallerLookup(method)); } /** @@ -3375,12 +3349,12 @@ public MethodHandle unreflectConstructor(Constructor c) throws IllegalAccessE assert(ctor.isConstructor()); @SuppressWarnings("deprecation") Lookup lookup = c.isAccessible() ? IMPL_LOOKUP : this; - return lookup.getDirectConstructorNoSecurityManager(ctor.getDeclaringClass(), ctor); + return lookup.getDirectConstructor(ctor.getDeclaringClass(), ctor); } /* * Produces a method handle that is capable of creating instances of the given class - * and instantiated by the given constructor. No security manager check. + * and instantiated by the given constructor. * * This method should only be used by ReflectionFactory::newConstructorForSerialization. */ @@ -3473,7 +3447,7 @@ private MethodHandle unreflectField(Field f, boolean isSetter) throws IllegalAcc : MethodHandleNatives.refKindIsGetter(field.getReferenceKind())); @SuppressWarnings("deprecation") Lookup lookup = f.isAccessible() ? IMPL_LOOKUP : this; - return lookup.getDirectFieldNoSecurityManager(field.getReferenceKind(), f.getDeclaringClass(), field); + return lookup.getDirectField(field.getReferenceKind(), f.getDeclaringClass(), field); } /** @@ -3550,8 +3524,8 @@ private MethodHandle unreflectField(Field f, boolean isSetter) throws IllegalAcc public VarHandle unreflectVarHandle(Field f) throws IllegalAccessException { MemberName getField = new MemberName(f, false); MemberName putField = new MemberName(f, true); - return getFieldVarHandleNoSecurityManager(getField.getReferenceKind(), putField.getReferenceKind(), - f.getDeclaringClass(), getField, putField); + return getFieldVarHandle(getField.getReferenceKind(), putField.getReferenceKind(), + f.getDeclaringClass(), getField, putField); } /** @@ -3586,10 +3560,9 @@ public MethodHandleInfo revealDirect(MethodHandle target) { if (refKind == REF_invokeVirtual && defc.isInterface()) // Symbolic reference is through interface but resolves to Object method (toString, etc.) refKind = REF_invokeInterface; - // Check SM permissions and member access before cracking. + // Check member access before cracking. try { checkAccess(refKind, defc, member); - checkSecurityManager(defc, member); } catch (IllegalAccessException ex) { throw new IllegalArgumentException(ex); } @@ -3716,69 +3689,6 @@ public boolean hasFullPrivilegeAccess() { return (allowedModes & (PRIVATE|MODULE)) == (PRIVATE|MODULE); } - /** - * Perform steps 1 and 2b access checks - * for ensureInitialized, findClass or accessClass. - */ - void checkSecurityManager(Class refc) { - if (allowedModes == TRUSTED) return; - - @SuppressWarnings("removal") - SecurityManager smgr = System.getSecurityManager(); - if (smgr == null) return; - - // Step 1: - boolean fullPrivilegeLookup = hasFullPrivilegeAccess(); - if (!fullPrivilegeLookup || - !VerifyAccess.classLoaderIsAncestor(lookupClass, refc)) { - ReflectUtil.checkPackageAccess(refc); - } - - // Step 2b: - if (!fullPrivilegeLookup) { - smgr.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); - } - } - - /** - * Perform steps 1, 2a and 3 access checks. - * Determines a trustable caller class to compare with refc, the symbolic reference class. - * If this lookup object has full privilege access except original access, - * then the caller class is the lookupClass. - * - * Lookup object created by {@link MethodHandles#privateLookupIn(Class, Lookup)} - * from the same module skips the security permission check. - */ - void checkSecurityManager(Class refc, MemberName m) { - Objects.requireNonNull(refc); - Objects.requireNonNull(m); - - if (allowedModes == TRUSTED) return; - - @SuppressWarnings("removal") - SecurityManager smgr = System.getSecurityManager(); - if (smgr == null) return; - - // Step 1: - boolean fullPrivilegeLookup = hasFullPrivilegeAccess(); - if (!fullPrivilegeLookup || - !VerifyAccess.classLoaderIsAncestor(lookupClass, refc)) { - ReflectUtil.checkPackageAccess(refc); - } - - // Step 2a: - if (m.isPublic()) return; - if (!fullPrivilegeLookup) { - smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); - } - - // Step 3: - Class defc = m.getDeclaringClass(); - if (!fullPrivilegeLookup && defc != refc) { - ReflectUtil.checkPackageAccess(defc); - } - } - void checkMethod(byte refKind, Class refc, MemberName m) throws IllegalAccessException { boolean wantStatic = (refKind == REF_invokeStatic); String message; @@ -3918,30 +3828,18 @@ private MethodHandle restrictReceiver(MemberName method, DirectMethodHandle mh, /** Check access and get the requested method. */ private MethodHandle getDirectMethod(byte refKind, Class refc, MemberName method, Lookup callerLookup) throws IllegalAccessException { final boolean doRestrict = true; - final boolean checkSecurity = true; - return getDirectMethodCommon(refKind, refc, method, checkSecurity, doRestrict, callerLookup); + return getDirectMethodCommon(refKind, refc, method, doRestrict, callerLookup); } /** Check access and get the requested method, for invokespecial with no restriction on the application of narrowing rules. */ private MethodHandle getDirectMethodNoRestrictInvokeSpecial(Class refc, MemberName method, Lookup callerLookup) throws IllegalAccessException { final boolean doRestrict = false; - final boolean checkSecurity = true; - return getDirectMethodCommon(REF_invokeSpecial, refc, method, checkSecurity, doRestrict, callerLookup); - } - /** Check access and get the requested method, eliding security manager checks. */ - private MethodHandle getDirectMethodNoSecurityManager(byte refKind, Class refc, MemberName method, Lookup callerLookup) throws IllegalAccessException { - final boolean doRestrict = true; - final boolean checkSecurity = false; // not needed for reflection or for linking CONSTANT_MH constants - return getDirectMethodCommon(refKind, refc, method, checkSecurity, doRestrict, callerLookup); + return getDirectMethodCommon(REF_invokeSpecial, refc, method, doRestrict, callerLookup); } /** Common code for all methods; do not call directly except from immediately above. */ private MethodHandle getDirectMethodCommon(byte refKind, Class refc, MemberName method, - boolean checkSecurity, boolean doRestrict, Lookup boundCaller) throws IllegalAccessException { checkMethod(refKind, refc, method); - // Optionally check with the security manager; this isn't needed for unreflect* calls. - if (checkSecurity) - checkSecurityManager(refc, method); assert(!method.isMethodHandleInvoke()); if (refKind == REF_invokeSpecial && @@ -4010,21 +3908,11 @@ private MethodHandle maybeBindCaller(MemberName method, MethodHandle mh, Lookup /** Check access and get the requested field. */ private MethodHandle getDirectField(byte refKind, Class refc, MemberName field) throws IllegalAccessException { - final boolean checkSecurity = true; - return getDirectFieldCommon(refKind, refc, field, checkSecurity); - } - /** Check access and get the requested field, eliding security manager checks. */ - private MethodHandle getDirectFieldNoSecurityManager(byte refKind, Class refc, MemberName field) throws IllegalAccessException { - final boolean checkSecurity = false; // not needed for reflection or for linking CONSTANT_MH constants - return getDirectFieldCommon(refKind, refc, field, checkSecurity); + return getDirectFieldCommon(refKind, refc, field); } /** Common code for all fields; do not call directly except from immediately above. */ - private MethodHandle getDirectFieldCommon(byte refKind, Class refc, MemberName field, - boolean checkSecurity) throws IllegalAccessException { + private MethodHandle getDirectFieldCommon(byte refKind, Class refc, MemberName field) throws IllegalAccessException { checkField(refKind, refc, field); - // Optionally check with the security manager; this isn't needed for unreflect* calls. - if (checkSecurity) - checkSecurityManager(refc, field); DirectMethodHandle dmh = DirectMethodHandle.make(refc, field); boolean doRestrict = (MethodHandleNatives.refKindHasReceiver(refKind) && restrictProtectedReceiver(field)); @@ -4035,26 +3923,17 @@ private MethodHandle getDirectFieldCommon(byte refKind, Class refc, MemberNam private VarHandle getFieldVarHandle(byte getRefKind, byte putRefKind, Class refc, MemberName getField, MemberName putField) throws IllegalAccessException { - final boolean checkSecurity = true; - return getFieldVarHandleCommon(getRefKind, putRefKind, refc, getField, putField, checkSecurity); - } - private VarHandle getFieldVarHandleNoSecurityManager(byte getRefKind, byte putRefKind, - Class refc, MemberName getField, MemberName putField) - throws IllegalAccessException { - final boolean checkSecurity = false; - return getFieldVarHandleCommon(getRefKind, putRefKind, refc, getField, putField, checkSecurity); + return getFieldVarHandleCommon(getRefKind, putRefKind, refc, getField, putField); } private VarHandle getFieldVarHandleCommon(byte getRefKind, byte putRefKind, - Class refc, MemberName getField, MemberName putField, - boolean checkSecurity) throws IllegalAccessException { + Class refc, MemberName getField, + MemberName putField) throws IllegalAccessException { assert getField.isStatic() == putField.isStatic(); assert getField.isGetter() && putField.isSetter(); assert MethodHandleNatives.refKindIsStatic(getRefKind) == MethodHandleNatives.refKindIsStatic(putRefKind); assert MethodHandleNatives.refKindIsGetter(getRefKind) && MethodHandleNatives.refKindIsSetter(putRefKind); checkField(getRefKind, refc, getField); - if (checkSecurity) - checkSecurityManager(refc, getField); if (!putField.isFinal()) { // A VarHandle does not support updates to final fields, any @@ -4062,8 +3941,6 @@ private VarHandle getFieldVarHandleCommon(byte getRefKind, byte putRefKind, // therefore the following write-based accessibility checks are // only required for non-final fields checkField(putRefKind, refc, putField); - if (checkSecurity) - checkSecurityManager(refc, putField); } boolean doRestrict = (MethodHandleNatives.refKindHasReceiver(getRefKind) && @@ -4081,22 +3958,12 @@ private VarHandle getFieldVarHandleCommon(byte getRefKind, byte putRefKind, } /** Check access and get the requested constructor. */ private MethodHandle getDirectConstructor(Class refc, MemberName ctor) throws IllegalAccessException { - final boolean checkSecurity = true; - return getDirectConstructorCommon(refc, ctor, checkSecurity); - } - /** Check access and get the requested constructor, eliding security manager checks. */ - private MethodHandle getDirectConstructorNoSecurityManager(Class refc, MemberName ctor) throws IllegalAccessException { - final boolean checkSecurity = false; // not needed for reflection or for linking CONSTANT_MH constants - return getDirectConstructorCommon(refc, ctor, checkSecurity); + return getDirectConstructorCommon(refc, ctor); } /** Common code for all constructors; do not call directly except from immediately above. */ - private MethodHandle getDirectConstructorCommon(Class refc, MemberName ctor, - boolean checkSecurity) throws IllegalAccessException { + private MethodHandle getDirectConstructorCommon(Class refc, MemberName ctor) throws IllegalAccessException { assert(ctor.isConstructor()); checkAccess(REF_newInvokeSpecial, refc, ctor); - // Optionally check with the security manager; this isn't needed for unreflect* calls. - if (checkSecurity) - checkSecurityManager(refc, ctor); assert(!MethodHandleNatives.isCallerSensitive(ctor)); // maybeBindCaller not relevant here return DirectMethodHandle.make(ctor).setVarargs(ctor); } @@ -4163,14 +4030,9 @@ private boolean canBeCached(byte refKind, Class defc, MemberName member) { return false; } } - try { - MemberName resolved2 = publicLookup().resolveOrNull(refKind, + MemberName resolved2 = publicLookup().resolveOrNull(refKind, new MemberName(refKind, defc, member.getName(), member.getType())); - if (resolved2 == null) { - return false; - } - checkSecurityManager(defc, resolved2); - } catch (SecurityException ex) { + if (resolved2 == null) { return false; } return true; @@ -4178,11 +4040,11 @@ private boolean canBeCached(byte refKind, Class defc, MemberName member) { private MethodHandle getDirectMethodForConstant(byte refKind, Class defc, MemberName member) throws ReflectiveOperationException { if (MethodHandleNatives.refKindIsField(refKind)) { - return getDirectFieldNoSecurityManager(refKind, defc, member); + return getDirectField(refKind, defc, member); } else if (MethodHandleNatives.refKindIsMethod(refKind)) { - return getDirectMethodNoSecurityManager(refKind, defc, member, findBoundCallerLookup(member)); + return getDirectMethod(refKind, defc, member, findBoundCallerLookup(member)); } else if (refKind == REF_newInvokeSpecial) { - return getDirectConstructorNoSecurityManager(defc, member); + return getDirectConstructor(defc, member); } // oops throw newIllegalArgumentException("bad MethodHandle constant #"+member); diff --git a/src/java.base/share/classes/java/lang/invoke/MethodType.java b/src/java.base/share/classes/java/lang/invoke/MethodType.java index a7afea7c93958..2b3843b09e335 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodType.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodType.java @@ -28,21 +28,15 @@ import java.lang.constant.ClassDesc; import java.lang.constant.Constable; import java.lang.constant.MethodTypeDesc; -import java.lang.ref.Reference; -import java.lang.ref.ReferenceQueue; -import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.Collections; import java.util.function.Supplier; import java.util.List; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Objects; import java.util.Optional; import java.util.StringJoiner; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.stream.Stream; import jdk.internal.util.ReferencedKeySet; import jdk.internal.util.ReferenceKey; @@ -50,7 +44,6 @@ import sun.invoke.util.BytecodeDescriptor; import sun.invoke.util.VerifyType; import sun.invoke.util.Wrapper; -import sun.security.util.SecurityConstants; import static java.lang.invoke.MethodHandleStatics.UNSAFE; import static java.lang.invoke.MethodHandleStatics.newIllegalArgumentException; @@ -1183,13 +1176,6 @@ Invokers invokers() { public static MethodType fromMethodDescriptorString(String descriptor, ClassLoader loader) throws IllegalArgumentException, TypeNotPresentException { - if (loader == null) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); - } - } return fromDescriptor(descriptor, (loader == null) ? ClassLoader.getSystemClassLoader() : loader); } diff --git a/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java b/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java index 41aec5c47a12f..3767bf2338855 100644 --- a/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java +++ b/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -28,9 +28,6 @@ import java.io.InvalidObjectException; import java.io.ObjectStreamException; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.Objects; /** @@ -265,25 +262,11 @@ public Object getCapturedArg(int i) { @java.io.Serial private Object readResolve() throws ObjectStreamException { try { - @SuppressWarnings("removal") - Method deserialize = AccessController.doPrivileged(new PrivilegedExceptionAction<>() { - @Override - public Method run() throws Exception { - Method m = capturingClass.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class); - m.setAccessible(true); - return m; - } - }); - + Method deserialize = capturingClass.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class); + deserialize.setAccessible(true); return deserialize.invoke(null, this); } catch (ReflectiveOperationException roe) { throw new InvalidObjectException("ReflectiveOperationException during deserialization", roe); - } catch (PrivilegedActionException e) { - Exception cause = e.getException(); - if (cause instanceof RuntimeException re) - throw re; - else - throw new RuntimeException("Exception in SerializedLambda.readResolve", e); } } diff --git a/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java b/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java index 8ed4485666f71..a045f9c196a0b 100644 --- a/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java +++ b/src/java.base/share/classes/java/lang/reflect/AccessibleObject.java @@ -28,15 +28,12 @@ import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandle; import java.lang.ref.WeakReference; -import java.security.AccessController; import jdk.internal.access.SharedSecrets; import jdk.internal.misc.VM; import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; import jdk.internal.reflect.ReflectionFactory; -import sun.security.action.GetPropertyAction; -import sun.security.util.SecurityConstants; /** * The {@code AccessibleObject} class is the base class for {@code Field}, @@ -81,17 +78,6 @@ public class AccessibleObject implements AnnotatedElement { SharedSecrets.setJavaLangReflectAccess(new ReflectAccess()); } - static void checkPermission() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - // SecurityConstants.ACCESS_PERMISSION is used to check - // whether a client has sufficient privilege to defeat Java - // language access control checks. - sm.checkPermission(SecurityConstants.ACCESS_PERMISSION); - } - } - /** * Convenience method to set the {@code accessible} flag for an * array of reflected objects. @@ -114,7 +100,6 @@ static void checkPermission() { */ @CallerSensitive public static void setAccessible(AccessibleObject[] array, boolean flag) { - checkPermission(); if (flag) { Class caller = Reflection.getCallerClass(); array = array.clone(); @@ -196,7 +181,6 @@ public static void setAccessible(AccessibleObject[] array, boolean flag) { */ @CallerSensitive // overrides in Method/Field/Constructor are @CS public void setAccessible(boolean flag) { - AccessibleObject.checkPermission(); setAccessible0(flag); } @@ -257,8 +241,6 @@ boolean setAccessible0(boolean flag) { */ @CallerSensitive public final boolean trySetAccessible() { - AccessibleObject.checkPermission(); - if (override == true) return true; // if it's not a Constructor, Method, Field then no access check @@ -502,10 +484,7 @@ protected AccessibleObject() {} // Reflection factory used by subclasses for creating field, // method, and constructor accessors. Note that this is called // very early in the bootstrapping process. - @SuppressWarnings("removal") - static final ReflectionFactory reflectionFactory = - AccessController.doPrivileged( - new ReflectionFactory.GetReflectionFactoryAction()); + static final ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory(); /** * {@inheritDoc} @@ -623,8 +602,7 @@ public Annotation[] getDeclaredAnnotations() { // For non-public members or members in package-private classes, // it is necessary to perform somewhat expensive access checks. // If the access check succeeds for a given class, it will - // always succeed (it is not affected by the granting or revoking - // of permissions); we speed up the check in the common case by + // always succeed; we speed up the check in the common case by // remembering the last Class for which the check succeeded. // // The simple access check for Constructor is to see if @@ -756,8 +734,7 @@ private boolean slowVerifyAccess(Class caller, Class memberClass, */ private static boolean printStackTraceWhenAccessFails() { if (!printStackPropertiesSet && VM.initLevel() >= 1) { - String s = GetPropertyAction.privilegedGetProperty( - "sun.reflect.debugModuleAccessChecks"); + String s = System.getProperty("sun.reflect.debugModuleAccessChecks"); if (s != null) { printStackWhenAccessFails = !s.equalsIgnoreCase("false"); } diff --git a/src/java.base/share/classes/java/lang/reflect/Constructor.java b/src/java.base/share/classes/java/lang/reflect/Constructor.java index 5eeceb6892052..3044530736963 100644 --- a/src/java.base/share/classes/java/lang/reflect/Constructor.java +++ b/src/java.base/share/classes/java/lang/reflect/Constructor.java @@ -181,7 +181,6 @@ Constructor newWithAccessor(ConstructorAccessor accessor) { @Override @CallerSensitive public void setAccessible(boolean flag) { - AccessibleObject.checkPermission(); if (flag) { checkCanSetAccessible(Reflection.getCallerClass()); } diff --git a/src/java.base/share/classes/java/lang/reflect/Field.java b/src/java.base/share/classes/java/lang/reflect/Field.java index f13893310a92b..bffa211fe1215 100644 --- a/src/java.base/share/classes/java/lang/reflect/Field.java +++ b/src/java.base/share/classes/java/lang/reflect/Field.java @@ -170,7 +170,6 @@ Field copy() { @Override @CallerSensitive public void setAccessible(boolean flag) { - AccessibleObject.checkPermission(); if (flag) checkCanSetAccessible(Reflection.getCallerClass()); setAccessible0(flag); } @@ -1155,7 +1154,6 @@ private void checkAccess(Class caller, Object obj) modifiers); } - // security check is done before calling this method private FieldAccessor getFieldAccessor() { FieldAccessor a = fieldAccessor; return (a != null) ? a : acquireFieldAccessor(); diff --git a/src/java.base/share/classes/java/lang/reflect/Method.java b/src/java.base/share/classes/java/lang/reflect/Method.java index e60d83de0c8af..f1d5ee63919ce 100644 --- a/src/java.base/share/classes/java/lang/reflect/Method.java +++ b/src/java.base/share/classes/java/lang/reflect/Method.java @@ -173,7 +173,6 @@ Method copy() { @Override @CallerSensitive public void setAccessible(boolean flag) { - AccessibleObject.checkPermission(); if (flag) checkCanSetAccessible(Reflection.getCallerClass()); setAccessible0(flag); } diff --git a/src/java.base/share/classes/java/lang/reflect/Proxy.java b/src/java.base/share/classes/java/lang/reflect/Proxy.java index fade83c0b3884..77f3d3e1e7120 100644 --- a/src/java.base/share/classes/java/lang/reflect/Proxy.java +++ b/src/java.base/share/classes/java/lang/reflect/Proxy.java @@ -30,8 +30,6 @@ import java.lang.invoke.MethodType; import java.lang.invoke.WrongMethodTypeException; import java.lang.module.ModuleDescriptor; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayDeque; import java.util.Arrays; import java.util.Collections; @@ -52,13 +50,9 @@ import jdk.internal.access.SharedSecrets; import jdk.internal.module.Modules; import jdk.internal.misc.VM; -import jdk.internal.reflect.CallerSensitive; -import jdk.internal.reflect.Reflection; import jdk.internal.loader.ClassLoaderValue; import jdk.internal.vm.annotation.Stable; import sun.reflect.misc.ReflectUtil; -import sun.security.action.GetPropertyAction; -import sun.security.util.SecurityConstants; import static java.lang.invoke.MethodType.methodType; import static java.lang.module.ModuleDescriptor.Modifier.SYNTHETIC; @@ -366,17 +360,11 @@ protected Proxy(InvocationHandler h) { * @see Package and Module Membership of Proxy Class */ @Deprecated - @CallerSensitive public static Class getProxyClass(ClassLoader loader, Class... interfaces) throws IllegalArgumentException { - @SuppressWarnings("removal") - Class caller = System.getSecurityManager() == null - ? null - : Reflection.getCallerClass(); - - return getProxyConstructor(caller, loader, interfaces) + return getProxyConstructor(loader, interfaces) .getDeclaringClass(); } @@ -386,25 +374,18 @@ public static Class getProxyClass(ClassLoader loader, * and an array of interfaces. The returned constructor will have the * {@link Constructor#setAccessible(boolean) accessible} flag already set. * - * @param caller passed from a public-facing @CallerSensitive method if - * SecurityManager is set or {@code null} if there's no - * SecurityManager * @param loader the class loader to define the proxy class * @param interfaces the list of interfaces for the proxy class * to implement * @return a Constructor of the proxy class taking single * {@code InvocationHandler} parameter */ - private static Constructor getProxyConstructor(Class caller, - ClassLoader loader, + private static Constructor getProxyConstructor(ClassLoader loader, Class... interfaces) { // optimization for single interface if (interfaces.length == 1) { Class intf = interfaces[0]; - if (caller != null) { - checkProxyAccess(caller, loader, intf); - } return proxyCache.sub(intf).computeIfAbsent( loader, (ld, clv) -> new ProxyBuilder(ld, clv.key()).build() @@ -412,9 +393,6 @@ private static Constructor getProxyConstructor(Class caller, } else { // interfaces cloned final Class[] intfsArray = interfaces.clone(); - if (caller != null) { - checkProxyAccess(caller, loader, intfsArray); - } final List> intfs = Arrays.asList(intfsArray); return proxyCache.sub(intfs).computeIfAbsent( loader, @@ -423,39 +401,6 @@ private static Constructor getProxyConstructor(Class caller, } } - /* - * Check permissions required to create a Proxy class. - * - * To define a proxy class, it performs the access checks as in - * Class.forName (VM will invoke ClassLoader.checkPackageAccess): - * 1. "getClassLoader" permission check if loader == null - * 2. checkPackageAccess on the interfaces it implements - * - * To get a constructor and new instance of a proxy class, it performs - * the package access check on the interfaces it implements - * as in Class.getConstructor. - * - * If an interface is non-public, the proxy class must be defined by - * the defining loader of the interface. If the caller's class loader - * is not the same as the defining loader of the interface, the VM - * will throw IllegalAccessError when the generated proxy class is - * being defined. - */ - private static void checkProxyAccess(Class caller, - ClassLoader loader, - Class ... interfaces) - { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - ClassLoader ccl = caller.getClassLoader(); - if (loader == null && ccl != null) { - sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION); - } - ReflectUtil.checkProxyPackageAccess(ccl, interfaces); - } - } - /** * Builder for a proxy class. * @@ -516,7 +461,7 @@ private static Class defineProxyClass(ProxyClassContext context, List intf) { @@ -630,11 +574,7 @@ private static boolean isDebug(String flag) { * accessible flag already set. If the target module does not have access * to any interface types, IllegalAccessError will be thrown by the VM * at defineClass time. - * - * Must call the checkProxyAccess method to perform permission checks - * before calling this. */ - @SuppressWarnings("removal") Constructor build() { Class proxyClass = defineProxyClass(context, interfaces); @@ -644,12 +584,7 @@ Constructor build() { } catch (NoSuchMethodException e) { throw new InternalError(e.toString(), e); } - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - cons.setAccessible(true); - return null; - } - }); + cons.setAccessible(true); return cons; } @@ -788,7 +723,7 @@ private static ProxyClassContext proxyClassContext(ClassLoader loader, throw new IllegalArgumentException( "cannot have non-public interfaces in different packages"); } - if (getLoader(m) != loader) { + if (m.getClassLoader() != loader) { // the specified loader is not the same class loader // of the non-public interface throw new IllegalArgumentException( @@ -979,36 +914,24 @@ private static Module getDynamicModule(ClassLoader loader) { * * @see Package and Module Membership of Proxy Class */ - @CallerSensitive public static Object newProxyInstance(ClassLoader loader, Class[] interfaces, InvocationHandler h) { Objects.requireNonNull(h); - @SuppressWarnings("removal") - final Class caller = System.getSecurityManager() == null - ? null - : Reflection.getCallerClass(); - /* * Look up or generate the designated proxy class and its constructor. */ - Constructor cons = getProxyConstructor(caller, loader, interfaces); + Constructor cons = getProxyConstructor(loader, interfaces); - return newProxyInstance(caller, cons, h); + return newProxyInstance(cons, h); } - private static Object newProxyInstance(Class caller, // null if no SecurityManager - Constructor cons, - InvocationHandler h) { + private static Object newProxyInstance(Constructor cons, InvocationHandler h) { /* * Invoke its constructor with the designated invocation handler. */ try { - if (caller != null) { - checkNewProxyPermission(caller, cons.getDeclaringClass()); - } - return cons.newInstance(new Object[]{h}); } catch (IllegalAccessException | InstantiationException e) { throw new InternalError(e.toString(), e); @@ -1022,35 +945,6 @@ private static Object newProxyInstance(Class caller, // null if no SecurityMa } } - private static void checkNewProxyPermission(Class caller, Class proxyClass) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - if (ReflectUtil.isNonPublicProxyClass(proxyClass)) { - ClassLoader ccl = caller.getClassLoader(); - ClassLoader pcl = proxyClass.getClassLoader(); - - // do permission check if the caller is in a different runtime package - // of the proxy class - String pkg = proxyClass.getPackageName(); - String callerPkg = caller.getPackageName(); - - if (pcl != ccl || !pkg.equals(callerPkg)) { - sm.checkPermission(new ReflectPermission("newProxyInPackage." + pkg)); - } - } - } - } - - /** - * Returns the class loader for the given module. - */ - @SuppressWarnings("removal") - private static ClassLoader getLoader(Module m) { - PrivilegedAction pa = m::getClassLoader; - return AccessController.doPrivileged(pa); - } - /** * Returns true if the given class is a proxy class. * @@ -1075,8 +969,6 @@ public static boolean isProxyClass(Class cl) { * @throws IllegalArgumentException if the argument is not a * proxy instance */ - @SuppressWarnings("removal") - @CallerSensitive public static InvocationHandler getInvocationHandler(Object proxy) throws IllegalArgumentException { @@ -1089,16 +981,6 @@ public static InvocationHandler getInvocationHandler(Object proxy) final Proxy p = (Proxy) proxy; final InvocationHandler ih = p.h; - if (System.getSecurityManager() != null) { - Class ihClass = ih.getClass(); - Class caller = Reflection.getCallerClass(); - if (ReflectUtil.needsPackageAccessCheck(caller.getClassLoader(), - ihClass.getClassLoader())) - { - ReflectUtil.checkPackageAccess(ihClass); - } - } - return ih; } @@ -1249,20 +1131,14 @@ private static Class findProxyInterfaceOrElseThrow(Class proxyClass, Metho * * @return a lookup for proxy class of this proxy instance */ - @SuppressWarnings("removal") private static MethodHandles.Lookup proxyClassLookup(MethodHandles.Lookup caller, Class proxyClass) { - return AccessController.doPrivileged(new PrivilegedAction<>() { - @Override - public MethodHandles.Lookup run() { - try { - Method m = proxyClass.getDeclaredMethod("proxyClassLookup", MethodHandles.Lookup.class); - m.setAccessible(true); - return (MethodHandles.Lookup) m.invoke(null, caller); - } catch (ReflectiveOperationException e) { - throw new InternalError(e); - } - } - }); + try { + Method m = proxyClass.getDeclaredMethod("proxyClassLookup", MethodHandles.Lookup.class); + m.setAccessible(true); + return (MethodHandles.Lookup) m.invoke(null, caller); + } catch (ReflectiveOperationException e) { + throw new InternalError(e); + } } /* diff --git a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java index efbb3919ef542..96e0a7e729f0c 100644 --- a/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java +++ b/src/java.base/share/classes/java/lang/reflect/ProxyGenerator.java @@ -43,7 +43,6 @@ import jdk.internal.constant.ClassOrInterfaceDescImpl; import jdk.internal.constant.ConstantUtils; import jdk.internal.constant.MethodTypeDescImpl; -import sun.security.action.GetBooleanAction; import static java.lang.classfile.ClassFile.*; import java.lang.classfile.attribute.StackMapFrameInfo; @@ -106,9 +105,8 @@ final class ProxyGenerator { */ @SuppressWarnings("removal") private static final boolean SAVE_GENERATED_FILES = - java.security.AccessController.doPrivileged( - new GetBooleanAction( - "jdk.proxy.ProxyGenerator.saveGeneratedFiles")); + Boolean.getBoolean("jdk.proxy.ProxyGenerator.saveGeneratedFiles"); + /* Preloaded ProxyMethod objects for methods in java.lang.Object */ private static final Method OBJECT_HASH_CODE_METHOD; @@ -215,27 +213,21 @@ static byte[] generateProxyClass(ClassLoader loader, final byte[] classFile = gen.generateClassFile(); if (SAVE_GENERATED_FILES) { - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - try { - int i = name.lastIndexOf('.'); - Path path; - if (i > 0) { - Path dir = Path.of(name.substring(0, i).replace('.', '/')); - Files.createDirectories(dir); - path = dir.resolve(name.substring(i + 1) + ".class"); - } else { - path = Path.of(name + ".class"); - } - Files.write(path, classFile); - return null; - } catch (IOException e) { - throw new InternalError( - "I/O exception saving generated file: " + e); - } - } - }); + try { + int i = name.lastIndexOf('.'); + Path path; + if (i > 0) { + Path dir = Path.of(name.substring(0, i).replace('.', '/')); + Files.createDirectories(dir); + path = dir.resolve(name.substring(i + 1) + ".class"); + } else { + path = Path.of(name + ".class"); + } + Files.write(path, classFile); + return null; + } catch (IOException e) { + throw new InternalError("I/O exception saving generated file: " + e); + } } return classFile; @@ -565,11 +557,6 @@ private void generateConstructor(ClassBuilder clb) { /** * Generate the class initializer. - * Discussion: Currently, for Proxy to work with SecurityManager, - * we rely on the parameter classes of the methods to be computed - * from Proxy instead of via user code paths like bootstrap method - * lazy evaluation. That might change if we can pass in the live - * Method objects directly.. */ private void generateStaticInitializer(ClassBuilder clb) { clb.withMethodBody(CLASS_INIT_NAME, MTD_void, ACC_STATIC, cob -> { @@ -786,9 +773,6 @@ private void codeUnwrapReturnValue(CodeBuilder cob, Class type) { * Generate code for initializing the static field that stores * the Method object for this proxy method. A class loader is * anticipated at local variable index 0. - * The generated code must be run in an AccessController.doPrivileged - * block if a SecurityManager is present, as otherwise the code - * cannot pass {@code null} ClassLoader to forName. */ private void codeFieldInitialization(CodeBuilder cob) { var cp = cob.constantPool(); diff --git a/src/java.base/share/classes/java/time/chrono/HijrahChronology.java b/src/java.base/share/classes/java/time/chrono/HijrahChronology.java index 681333dfa9ff1..881dfb15fc7e3 100644 --- a/src/java.base/share/classes/java/time/chrono/HijrahChronology.java +++ b/src/java.base/share/classes/java/time/chrono/HijrahChronology.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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 @@ -59,18 +59,14 @@ import static java.time.temporal.ChronoField.EPOCH_DAY; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.Serializable; -import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.time.Clock; import java.time.DateTimeException; import java.time.Instant; @@ -88,6 +84,7 @@ import java.util.Properties; import java.util.stream.Stream; +import jdk.internal.util.StaticProperty; import sun.util.logging.PlatformLogger; /** @@ -291,10 +288,7 @@ public final class HijrahChronology extends AbstractChronology implements Serial AbstractChronology.registerChrono(INSTANCE, "islamic"); // custom config chronologies - @SuppressWarnings("removal") - String javaHome = AccessController.doPrivileged((PrivilegedAction) - () -> System.getProperty("java.home")); - CONF_PATH = Path.of(javaHome, "conf", "chronology"); + CONF_PATH = Path.of(StaticProperty.javaHome(), "conf", "chronology"); registerCustomChrono(); } @@ -824,19 +818,9 @@ private int epochMonthLength(int epochMonth) { */ private static Properties readConfigProperties(final String chronologyId, final String calendarType) throws Exception { String resourceName = RESOURCE_PREFIX + chronologyId + "_" + calendarType + RESOURCE_SUFFIX; - PrivilegedAction getResourceAction = calendarType.equals("islamic-umalqura") ? - () -> HijrahChronology.class.getResourceAsStream(resourceName) : - () -> { - try { - return Files.newInputStream(CONF_PATH.resolve(resourceName), - StandardOpenOption.READ); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - }; - FilePermission perm1 = new FilePermission("<>", "read"); - RuntimePermission perm2 = new RuntimePermission("accessSystemModules"); - try (@SuppressWarnings("removal") InputStream is = AccessController.doPrivileged(getResourceAction, null, perm1, perm2)) { + try (InputStream is = calendarType.equals("islamic-umalqura") + ? HijrahChronology.class.getResourceAsStream(resourceName) + : Files.newInputStream(CONF_PATH.resolve(resourceName), StandardOpenOption.READ)) { if (is == null) { throw new RuntimeException("Hijrah calendar resource not found: " + resourceName); } @@ -1031,38 +1015,32 @@ private int[] parseYMD(String string) { * Look for Hijrah chronology variant properties files in * /conf/chronology directory. Then register its chronology, if any. */ - @SuppressWarnings("removal") private static void registerCustomChrono() { - AccessController.doPrivileged( - (PrivilegedAction)() -> { - if (Files.isDirectory(CONF_PATH)) { - try (Stream stream = Files.list(CONF_PATH)) { - stream.map(p -> p.getFileName().toString()) - .filter(fn -> fn.matches("hijrah-config-[^\\.]+\\.properties")) - .map(fn -> fn.replaceAll("(hijrah-config-|\\.properties)", "")) - .forEach(idtype -> { - int delimiterPos = idtype.indexOf('_'); - // '_' should be somewhere in the middle of idtype - if (delimiterPos > 1 && delimiterPos < idtype.length() - 1) { - AbstractChronology.registerChrono( - new HijrahChronology( - idtype.substring(0, delimiterPos), - idtype.substring(delimiterPos + 1))); - } else { - PlatformLogger.getLogger("java.time.chrono") - .warning("Hijrah custom config init failed." + - "'_' name convention not followed: " + idtype); - } - }); - } catch (IOException e) { - PlatformLogger.getLogger("java.time.chrono") - .warning("Hijrah custom config init failed.", e); - } - } - return null; - }, - null, - new FilePermission("<>", "read")); + + if (Files.isDirectory(CONF_PATH)) { + try (Stream stream = Files.list(CONF_PATH)) { + stream.map(p -> p.getFileName().toString()) + .filter(fn -> fn.matches("hijrah-config-[^\\.]+\\.properties")) + .map(fn -> fn.replaceAll("(hijrah-config-|\\.properties)", "")) + .forEach(idtype -> { + int delimiterPos = idtype.indexOf('_'); + // '_' should be somewhere in the middle of idtype + if (delimiterPos > 1 && delimiterPos < idtype.length() - 1) { + AbstractChronology.registerChrono( + new HijrahChronology( + idtype.substring(0, delimiterPos), + idtype.substring(delimiterPos + 1))); + } else { + PlatformLogger.getLogger("java.time.chrono") + .warning("Hijrah custom config init failed." + + "'_' name convention not followed: " + idtype); + } + }); + } catch (IOException e) { + PlatformLogger.getLogger("java.time.chrono") + .warning("Hijrah custom config init failed.", e); + } + } } //----------------------------------------------------------------------- diff --git a/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java b/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java index 375be682c0cf7..c79b6355595ec 100644 --- a/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java +++ b/src/java.base/share/classes/java/time/zone/ZoneRulesProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024, 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,8 +61,6 @@ */ package java.time.zone; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -146,28 +144,21 @@ public abstract class ZoneRulesProvider { static { // if the property java.time.zone.DefaultZoneRulesProvider is // set then its value is the class name of the default provider - @SuppressWarnings("removal") - final List loaded = - AccessController.doPrivileged(new PrivilegedAction>() { - public List run() { - List result = new ArrayList<>(); - String prop = System.getProperty("java.time.zone.DefaultZoneRulesProvider"); - if (prop != null) { - try { - Class c = Class.forName(prop, true, ClassLoader.getSystemClassLoader()); - @SuppressWarnings("deprecation") - ZoneRulesProvider provider = ZoneRulesProvider.class.cast(c.newInstance()); - registerProvider(provider); - result.add(provider); - } catch (Exception x) { - throw new Error(x); - } - } else { - registerProvider(new TzdbZoneRulesProvider()); - } - return result; - } - }); + final List loaded = new ArrayList<>(); + String prop = System.getProperty("java.time.zone.DefaultZoneRulesProvider"); + if (prop != null) { + try { + Class c = Class.forName(prop, true, ClassLoader.getSystemClassLoader()); + @SuppressWarnings("deprecation") + ZoneRulesProvider provider = ZoneRulesProvider.class.cast(c.newInstance()); + registerProvider(provider); + loaded.add(provider); + } catch (Exception x) { + throw new Error(x); + } + } else { + registerProvider(new TzdbZoneRulesProvider()); + } ServiceLoader sl = ServiceLoader.load(ZoneRulesProvider.class, ClassLoader.getSystemClassLoader()); Iterator it = sl.iterator(); diff --git a/src/java.base/share/classes/java/util/ServiceLoader.java b/src/java.base/share/classes/java/util/ServiceLoader.java index 07ed1875190ae..c634d6321c068 100644 --- a/src/java.base/share/classes/java/util/ServiceLoader.java +++ b/src/java.base/share/classes/java/util/ServiceLoader.java @@ -35,11 +35,6 @@ import java.lang.reflect.Modifier; import java.net.URL; import java.net.URLConnection; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Stream; @@ -396,10 +391,6 @@ public final class ServiceLoader // null when locating provider using a module layer private final ClassLoader loader; - // The access control context taken when the ServiceLoader is created - @SuppressWarnings("removal") - private final AccessControlContext acc; - // The lazy-lookup iterator for iterator operations private Iterator> lookupIterator1; private final List instantiatedProviders = new ArrayList<>(); @@ -462,7 +453,6 @@ public static interface Provider extends Supplier { * If {@code svc} is not accessible to {@code caller} or the caller * module does not use the service type. */ - @SuppressWarnings("removal") private ServiceLoader(Class caller, ModuleLayer layer, Class svc) { Objects.requireNonNull(caller); Objects.requireNonNull(layer); @@ -473,9 +463,6 @@ private ServiceLoader(Class caller, ModuleLayer layer, Class svc) { this.serviceName = svc.getName(); this.layer = layer; this.loader = null; - this.acc = (System.getSecurityManager() != null) - ? AccessController.getContext() - : null; } /** @@ -486,7 +473,6 @@ private ServiceLoader(Class caller, ModuleLayer layer, Class svc) { * If {@code svc} is not accessible to {@code caller} or the caller * module does not use the service type. */ - @SuppressWarnings("removal") private ServiceLoader(Class caller, Class svc, ClassLoader cl) { Objects.requireNonNull(svc); @@ -515,9 +501,6 @@ private ServiceLoader(Class caller, Class svc, ClassLoader cl) { this.serviceName = svc.getName(); this.layer = null; this.loader = cl; - this.acc = (System.getSecurityManager() != null) - ? AccessController.getContext() - : null; } /** @@ -529,7 +512,6 @@ private ServiceLoader(Class caller, Class svc, ClassLoader cl) { * @throws ServiceConfigurationError * If the caller module does not use the service type. */ - @SuppressWarnings("removal") private ServiceLoader(Module callerModule, Class svc, ClassLoader cl) { if (!callerModule.canUse(svc)) { fail(svc, callerModule + " does not declare `uses`"); @@ -539,9 +521,6 @@ private ServiceLoader(Module callerModule, Class svc, ClassLoader cl) { this.serviceName = svc.getName(); this.layer = null; this.loader = cl; - this.acc = (System.getSecurityManager() != null) - ? AccessController.getContext() - : null; } /** @@ -601,7 +580,6 @@ private boolean inExplicitModule(Class clazz) { * provider method or there is more than one public static * provider method */ - @SuppressWarnings("removal") private Method findStaticProviderMethod(Class clazz) { List methods = null; try { @@ -628,12 +606,7 @@ private Method findStaticProviderMethod(Class clazz) { } } if (result != null) { - Method m = result; - PrivilegedAction pa = () -> { - m.setAccessible(true); - return null; - }; - AccessController.doPrivileged(pa); + result.setAccessible(true); } return result; } @@ -644,27 +617,16 @@ private Method findStaticProviderMethod(Class clazz) { * @throws ServiceConfigurationError if the class does not have * public no-arg constructor */ - @SuppressWarnings("removal") private Constructor getConstructor(Class clazz) { - PrivilegedExceptionAction> pa - = new PrivilegedExceptionAction<>() { - @Override - public Constructor run() throws Exception { - Constructor ctor = clazz.getConstructor(); - if (inExplicitModule(clazz)) - ctor.setAccessible(true); - return ctor; - } - }; Constructor ctor = null; try { - ctor = AccessController.doPrivileged(pa); - } catch (Throwable x) { - if (x instanceof PrivilegedActionException) - x = x.getCause(); + ctor = clazz.getConstructor(); + } catch (NoSuchMethodException ex) { String cn = clazz.getName(); - fail(service, cn + " Unable to get public no-arg constructor", x); + fail(service, cn + " Unable to get public no-arg constructor", ex); } + if (inExplicitModule(clazz)) + ctor.setAccessible(true); return ctor; } @@ -678,29 +640,23 @@ private static class ProviderImpl implements Provider { final Class type; final Method factoryMethod; // factory method or null final Constructor ctor; // public no-args constructor or null - @SuppressWarnings("removal") - final AccessControlContext acc; ProviderImpl(Class service, Class type, - Method factoryMethod, - @SuppressWarnings("removal") AccessControlContext acc) { + Method factoryMethod) { this.service = service; this.type = type; this.factoryMethod = factoryMethod; this.ctor = null; - this.acc = acc; } ProviderImpl(Class service, Class type, - Constructor ctor, - @SuppressWarnings("removal") AccessControlContext acc) { + Constructor ctor) { this.service = service; this.type = type; this.factoryMethod = null; this.ctor = ctor; - this.acc = acc; } @Override @@ -723,36 +679,14 @@ public S get() { * permissions that are restricted by the security context of whatever * created this loader. */ - @SuppressWarnings("removal") private S invokeFactoryMethod() { Object result = null; - Throwable exc = null; - if (acc == null) { - try { - result = factoryMethod.invoke(null); - } catch (Throwable x) { - exc = x; - } - } else { - PrivilegedExceptionAction pa = new PrivilegedExceptionAction<>() { - @Override - public Object run() throws Exception { - return factoryMethod.invoke(null); - } - }; - // invoke factory method with permissions restricted by acc - try { - result = AccessController.doPrivileged(pa, acc); - } catch (Throwable x) { - if (x instanceof PrivilegedActionException) - x = x.getCause(); - exc = x; - } - } - if (exc != null) { - if (exc instanceof InvocationTargetException) - exc = exc.getCause(); - fail(service, factoryMethod + " failed", exc); + try { + result = factoryMethod.invoke(null); + } catch (Throwable ex) { + if (ex instanceof InvocationTargetException) + ex = ex.getCause(); + fail(service, factoryMethod + " failed", ex); } if (result == null) { fail(service, factoryMethod + " returned null"); @@ -767,38 +701,16 @@ public Object run() throws Exception { * with a security manager then the constructor runs with permissions that * are restricted by the security context of whatever created this loader. */ - @SuppressWarnings("removal") private S newInstance() { S p = null; - Throwable exc = null; - if (acc == null) { - try { - p = ctor.newInstance(); - } catch (Throwable x) { - exc = x; - } - } else { - PrivilegedExceptionAction pa = new PrivilegedExceptionAction<>() { - @Override - public S run() throws Exception { - return ctor.newInstance(); - } - }; - // invoke constructor with permissions restricted by acc - try { - p = AccessController.doPrivileged(pa, acc); - } catch (Throwable x) { - if (x instanceof PrivilegedActionException) - x = x.getCause(); - exc = x; - } - } - if (exc != null) { - if (exc instanceof InvocationTargetException) - exc = exc.getCause(); + try { + p = ctor.newInstance(); + } catch (Throwable ex) { + if (ex instanceof InvocationTargetException) + ex = ex.getCause(); String cn = ctor.getDeclaringClass().getName(); fail(service, - "Provider " + cn + " could not be instantiated", exc); + "Provider " + cn + " could not be instantiated", ex); } return p; } @@ -809,15 +721,14 @@ public S run() throws Exception { @Override public int hashCode() { - return Objects.hash(service, type, acc); + return Objects.hash(service, type); } @Override public boolean equals(Object ob) { return ob instanceof @SuppressWarnings("unchecked")ProviderImpl that && this.service == that.service - && this.type == that.type - && Objects.equals(this.acc, that.acc); + && this.type == that.type; } } @@ -831,7 +742,6 @@ public boolean equals(Object ob) { * isn't the expected sub-type (or doesn't define a provider * factory method that returns the expected type) */ - @SuppressWarnings("removal") private Provider loadProvider(ServiceProvider provider) { Module module = provider.module(); if (!module.canRead(service.getModule())) { @@ -841,22 +751,10 @@ private Provider loadProvider(ServiceProvider provider) { String cn = provider.providerName(); Class clazz = null; - if (acc == null) { - try { - clazz = Class.forName(module, cn); - } catch (LinkageError e) { - fail(service, "Unable to load " + cn, e); - } - } else { - PrivilegedExceptionAction> pa = () -> Class.forName(module, cn); - try { - clazz = AccessController.doPrivileged(pa); - } catch (Throwable x) { - if (x instanceof PrivilegedActionException) - x = x.getCause(); - fail(service, "Unable to load " + cn, x); - return null; - } + try { + clazz = Class.forName(module, cn); + } catch (LinkageError e) { + fail(service, "Unable to load " + cn, e); } if (clazz == null) { fail(service, "Provider " + cn + " not found"); @@ -878,7 +776,7 @@ private Provider loadProvider(ServiceProvider provider) { @SuppressWarnings("unchecked") Class type = (Class) returnType; - return new ProviderImpl(service, type, factoryMethod, acc); + return new ProviderImpl(service, type, factoryMethod); } } @@ -891,7 +789,7 @@ private Provider loadProvider(ServiceProvider provider) { Class type = (Class) clazz; @SuppressWarnings("unchecked") Constructor ctor = (Constructor ) getConstructor(clazz); - return new ProviderImpl(service, type, ctor, acc); + return new ProviderImpl(service, type, ctor); } /** @@ -997,20 +895,6 @@ private List providers(ModuleLayer layer) { return catalog.findServices(serviceName); } - /** - * Returns the class loader that a module is defined to - */ - @SuppressWarnings("removal") - private ClassLoader loaderFor(Module module) { - SecurityManager sm = System.getSecurityManager(); - if (sm == null) { - return module.getClassLoader(); - } else { - PrivilegedAction pa = module::getClassLoader; - return AccessController.doPrivileged(pa); - } - } - /** * Returns an iterator to iterate over the implementations of {@code * service} in modules defined to the given class loader or in custom @@ -1041,7 +925,7 @@ private Iterator iteratorFor(ClassLoader loader) { while (iterator.hasNext()) { ModuleLayer layer = iterator.next(); for (ServiceProvider sp : providers(layer)) { - ClassLoader l = loaderFor(sp.module()); + ClassLoader l = sp.module().getClassLoader(); if (l != null && l != platformClassLoader) { allProviders.add(sp); } @@ -1225,7 +1109,7 @@ private boolean hasNextService() { Class type = (Class) clazz; Constructor ctor = (Constructor)getConstructor(clazz); - ProviderImpl p = new ProviderImpl(service, type, ctor, acc); + ProviderImpl p = new ProviderImpl(service, type, ctor); nextProvider = (ProviderImpl) p; } else { fail(service, clazz.getName() + " not a subtype"); @@ -1253,30 +1137,14 @@ private Provider nextService() { } } - @SuppressWarnings("removal") @Override public boolean hasNext() { - if (acc == null) { - return hasNextService(); - } else { - PrivilegedAction action = new PrivilegedAction<>() { - public Boolean run() { return hasNextService(); } - }; - return AccessController.doPrivileged(action, acc); - } + return hasNextService(); } - @SuppressWarnings("removal") @Override public Provider next() { - if (acc == null) { - return nextService(); - } else { - PrivilegedAction> action = new PrivilegedAction<>() { - public Provider run() { return nextService(); } - }; - return AccessController.doPrivileged(action, acc); - } + return nextService(); } } diff --git a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java index e8dafaa0ac463..2460bf79a832b 100644 --- a/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java +++ b/src/java.base/share/classes/java/util/concurrent/ConcurrentSkipListMap.java @@ -3221,14 +3221,14 @@ public final Comparator getComparator() { } // factory method for KeySpliterator final KeySpliterator keySpliterator() { - Index h; Node n; long est; + Index h; Node hn, n; long est; VarHandle.acquireFence(); - if ((h = head) == null) { + if ((h = head) == null || (hn = h.node) == null) { n = null; est = 0L; } else { - n = h.node; + n = hn.next; est = getAdderCount(); } return new KeySpliterator(comparator, h, n, null, est); @@ -3307,14 +3307,14 @@ public int characteristics() { // Almost the same as keySpliterator() final ValueSpliterator valueSpliterator() { - Index h; Node n; long est; + Index h; Node hn, n; long est; VarHandle.acquireFence(); - if ((h = head) == null) { + if ((h = head) == null || (hn = h.node) == null) { n = null; est = 0L; } else { - n = h.node; + n = hn.next; est = getAdderCount(); } return new ValueSpliterator(comparator, h, n, null, est); @@ -3411,14 +3411,14 @@ public final Comparator> getComparator() { // Almost the same as keySpliterator() final EntrySpliterator entrySpliterator() { - Index h; Node n; long est; + Index h; Node hn, n; long est; VarHandle.acquireFence(); - if ((h = head) == null) { + if ((h = head) == null || (hn = h.node) == null) { n = null; est = 0L; } else { - n = h.node; + n = hn.next; est = getAdderCount(); } return new EntrySpliterator(comparator, h, n, null, est); diff --git a/src/java.base/share/classes/java/util/jar/JarFile.java b/src/java.base/share/classes/java/util/jar/JarFile.java index a14821d80461b..7b64e3cdd04d7 100644 --- a/src/java.base/share/classes/java/util/jar/JarFile.java +++ b/src/java.base/share/classes/java/util/jar/JarFile.java @@ -28,7 +28,6 @@ import jdk.internal.access.SharedSecrets; import jdk.internal.access.JavaUtilZipFileAccess; import jdk.internal.misc.ThreadTracker; -import sun.security.action.GetPropertyAction; import sun.security.util.ManifestEntryVerifier; import sun.security.util.SignatureFileVerifier; @@ -171,7 +170,7 @@ public class JarFile extends ZipFile { // multi-release jar file versions >= 9 BASE_VERSION = Runtime.Version.parse(Integer.toString(8)); BASE_VERSION_FEATURE = BASE_VERSION.feature(); - String jarVersion = GetPropertyAction.privilegedGetProperty("jdk.util.jar.version"); + String jarVersion = System.getProperty("jdk.util.jar.version"); int runtimeVersion = Runtime.version().feature(); if (jarVersion != null) { int jarVer = Integer.parseInt(jarVersion); @@ -180,8 +179,8 @@ public class JarFile extends ZipFile { : Math.max(jarVer, BASE_VERSION_FEATURE); } RUNTIME_VERSION = Runtime.Version.parse(Integer.toString(runtimeVersion)); - String enableMultiRelease = GetPropertyAction - .privilegedGetProperty("jdk.util.jar.enableMultiRelease", "true"); + String enableMultiRelease = System. + getProperty("jdk.util.jar.enableMultiRelease", "true"); switch (enableMultiRelease) { case "false" -> { MULTI_RELEASE_ENABLED = false; diff --git a/src/java.base/share/classes/java/util/zip/ZipFile.java b/src/java.base/share/classes/java/util/zip/ZipFile.java index a08d3bc7a1bb6..f736a092099e1 100644 --- a/src/java.base/share/classes/java/util/zip/ZipFile.java +++ b/src/java.base/share/classes/java/util/zip/ZipFile.java @@ -55,7 +55,6 @@ import jdk.internal.vm.annotation.Stable; import sun.nio.cs.UTF_8; import sun.nio.fs.DefaultFileSystemProvider; -import sun.security.action.GetPropertyAction; import sun.security.util.SignatureFileVerifier; import static java.util.zip.ZipConstants64.*; @@ -193,14 +192,6 @@ public ZipFile(File file, int mode, Charset charset) throws IOException } String name = file.getPath(); file = new File(name); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkRead(name); - if ((mode & OPEN_DELETE) != 0) { - sm.checkDelete(name); - } - } Objects.requireNonNull(charset, "charset"); this.filePath = name; @@ -1059,8 +1050,7 @@ private BitSet getMetaInfVersions(String name) { */ static boolean getDisableZip64ExtraFieldValidation() { boolean result; - String value = GetPropertyAction.privilegedGetProperty( - "jdk.util.zip.disableZip64ExtraFieldValidation"); + String value = System.getProperty("jdk.util.zip.disableZip64ExtraFieldValidation"); if (value == null) { result = false; } else { diff --git a/src/java.base/share/classes/java/util/zip/ZipOutputStream.java b/src/java.base/share/classes/java/util/zip/ZipOutputStream.java index 3fe992ab440d3..47499858a371f 100644 --- a/src/java.base/share/classes/java/util/zip/ZipOutputStream.java +++ b/src/java.base/share/classes/java/util/zip/ZipOutputStream.java @@ -35,7 +35,6 @@ import static java.util.zip.ZipEntry.isCENHeaderValid; import static java.util.zip.ZipUtils.*; import sun.nio.cs.UTF_8; -import sun.security.action.GetBooleanAction; /** * This class implements an output stream filter for writing files in the @@ -58,7 +57,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements ZipConstant * some in jdk7. */ private static final boolean inhibitZip64 = - GetBooleanAction.privilegedGetProperty("jdk.util.zip.inhibitZip64"); + Boolean.getBoolean("jdk.util.zip.inhibitZip64"); private static class XEntry { final ZipEntry entry; diff --git a/src/java.base/share/classes/java/util/zip/ZipUtils.java b/src/java.base/share/classes/java/util/zip/ZipUtils.java index 5b1d896f4208e..a2eb9c50d4aea 100644 --- a/src/java.base/share/classes/java/util/zip/ZipUtils.java +++ b/src/java.base/share/classes/java/util/zip/ZipUtils.java @@ -174,7 +174,7 @@ public static final int get16(byte[] b, int off) { Preconditions.checkIndex(off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkIndex(off + 1, b.length, Preconditions.AIOOBE_FORMATTER); return Short.toUnsignedInt( - UNSAFE.getShortUnaligned(b, off + Unsafe.ARRAY_BYTE_BASE_OFFSET, false)); + UNSAFE.getShortUnaligned(b, off + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET, false)); } /** @@ -185,7 +185,7 @@ public static final long get32(byte[] b, int off) { Preconditions.checkIndex(off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkIndex(off + 3, b.length, Preconditions.AIOOBE_FORMATTER); return Integer.toUnsignedLong( - UNSAFE.getIntUnaligned(b, off + Unsafe.ARRAY_BYTE_BASE_OFFSET, false)); + UNSAFE.getIntUnaligned(b, off + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET, false)); } /** @@ -195,7 +195,7 @@ public static final long get32(byte[] b, int off) { public static final long get64S(byte[] b, int off) { Preconditions.checkIndex(off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkIndex(off + 7, b.length, Preconditions.AIOOBE_FORMATTER); - return UNSAFE.getLongUnaligned(b, off + Unsafe.ARRAY_BYTE_BASE_OFFSET, false); + return UNSAFE.getLongUnaligned(b, off + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET, false); } /** @@ -206,7 +206,7 @@ public static final long get64S(byte[] b, int off) { public static final int get32S(byte[] b, int off) { Preconditions.checkIndex(off, b.length, Preconditions.AIOOBE_FORMATTER); Preconditions.checkIndex(off + 3, b.length, Preconditions.AIOOBE_FORMATTER); - return UNSAFE.getIntUnaligned(b, off + Unsafe.ARRAY_BYTE_BASE_OFFSET, false); + return UNSAFE.getIntUnaligned(b, off + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET, false); } /* diff --git a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java index 84647cc5b90e1..80f4dfdf2aa97 100644 --- a/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java +++ b/src/java.base/share/classes/jdk/internal/access/JavaLangAccess.java @@ -144,12 +144,6 @@ public interface JavaLangAccess { */ void registerShutdownHook(int slot, boolean registerShutdownInProgress, Runnable hook); - /** - * Returns a new Thread with the given Runnable and an - * inherited AccessControlContext. - */ - Thread newThreadWithAcc(Runnable target, @SuppressWarnings("removal") AccessControlContext acc); - /** * Invokes the finalize method of the given object. */ diff --git a/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java b/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java index 5acafe01a8908..c29d0dd01a59d 100644 --- a/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java +++ b/src/java.base/share/classes/jdk/internal/access/SharedSecrets.java @@ -71,8 +71,6 @@ public class SharedSecrets { private static JavaLangRefAccess javaLangRefAccess; private static JavaLangReflectAccess javaLangReflectAccess; private static JavaIOAccess javaIOAccess; - private static JavaIOPrintStreamAccess javaIOPrintStreamAccess; - private static JavaIOPrintWriterAccess javaIOPrintWriterAccess; private static JavaIOFileDescriptorAccess javaIOFileDescriptorAccess; private static JavaIOFilePermissionAccess javaIOFilePermissionAccess; private static JavaIORandomAccessFileAccess javaIORandomAccessFileAccess; @@ -288,32 +286,6 @@ public static JavaIOAccess getJavaIOAccess() { return access; } - public static void setJavaIOCPrintWriterAccess(JavaIOPrintWriterAccess a) { - javaIOPrintWriterAccess = a; - } - - public static JavaIOPrintWriterAccess getJavaIOPrintWriterAccess() { - var access = javaIOPrintWriterAccess; - if (access == null) { - ensureClassInitialized(PrintWriter.class); - access = javaIOPrintWriterAccess; - } - return access; - } - - public static void setJavaIOCPrintStreamAccess(JavaIOPrintStreamAccess a) { - javaIOPrintStreamAccess = a; - } - - public static JavaIOPrintStreamAccess getJavaIOPrintStreamAccess() { - var access = javaIOPrintStreamAccess; - if (access == null) { - ensureClassInitialized(PrintStream.class); - access = javaIOPrintStreamAccess; - } - return access; - } - public static void setJavaIOFileDescriptorAccess(JavaIOFileDescriptorAccess jiofda) { javaIOFileDescriptorAccess = jiofda; } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java index b29b9f6f9551e..648582b8a7d77 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/AbstractAttributeMapper.java @@ -64,7 +64,7 @@ public final String name() { @Override public final void writeAttribute(BufWriter writer, T attr) { BufWriterImpl buf = (BufWriterImpl) writer; - buf.writeIndex(buf.constantPool().utf8Entry(name)); + buf.writeIndex(attr.attributeName()); int lengthIndex = buf.skip(4); writeBody(buf, attr); int written = buf.size() - lengthIndex - 4; diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java index 59a2b03c91ed1..114101b02e5c5 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/BoundAttribute.java @@ -47,6 +47,7 @@ public abstract sealed class BoundAttribute> private final AttributeMapper mapper; final ClassReaderImpl classReader; final int payloadStart; + Utf8Entry name; BoundAttribute(ClassReader classReader, AttributeMapper mapper, int payloadStart) { this.mapper = mapper; @@ -59,8 +60,11 @@ public int payloadLen() { } @Override - public String attributeName() { - return mapper.name(); + public Utf8Entry attributeName() { + if (name == null) { + name = classReader.readEntry(payloadStart - 6, Utf8Entry.class); + } + return name; } @Override diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java index b8fce2fd288c8..1ded017f2a293 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/ClassPrinterImpl.java @@ -574,7 +574,7 @@ private static MapNode classToTree(ClassModel clm, Verbosity verbosity) { list("flags", "flag", clm.flags().flags().stream().map(AccessFlag::name)), leaf("superclass", clm.superclass().map(ClassEntry::asInternalName).orElse("")), list("interfaces", "interface", clm.interfaces().stream().map(ClassEntry::asInternalName)), - list("attributes", "attribute", clm.attributes().stream().map(Attribute::attributeName))) + list("attributes", "attribute", clm.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(constantPoolToTree(clm.constantPool(), verbosity)) .with(attributesToTree(clm.attributes(), verbosity)) .with(new ListNodeImpl(BLOCK, "fields", clm.fields().stream().map(f -> @@ -672,7 +672,7 @@ private static MapNode fieldToTree(FieldModel f, Verbosity verbosity) { "flag", f.flags().flags().stream().map(AccessFlag::name)), leaf("field type", f.fieldType().stringValue()), list("attributes", - "attribute", f.attributes().stream().map(Attribute::attributeName))) + "attribute", f.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(attributesToTree(f.attributes(), verbosity)); } @@ -683,7 +683,7 @@ public static MapNode methodToTree(MethodModel m, Verbosity verbosity) { "flag", m.flags().flags().stream().map(AccessFlag::name)), leaf("method type", m.methodType().stringValue()), list("attributes", - "attribute", m.attributes().stream().map(Attribute::attributeName))) + "attribute", m.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(attributesToTree(m.attributes(), verbosity)) .with(codeToTree((CodeAttribute)m.code().orElse(null), verbosity)); } @@ -694,7 +694,7 @@ private static MapNode codeToTree(CodeAttribute com, Verbosity verbosity) { codeNode.with(leaf("max stack", com.maxStack())); codeNode.with(leaf("max locals", com.maxLocals())); codeNode.with(list("attributes", - "attribute", com.attributes().stream().map(Attribute::attributeName))); + "attribute", com.attributes().stream().map(Attribute::attributeName).map(Utf8Entry::stringValue))); var stackMap = new MapNodeImpl(BLOCK, "stack map frames"); var visibleTypeAnnos = new LinkedHashMap>(); var invisibleTypeAnnos = new LinkedHashMap>(); @@ -996,7 +996,7 @@ private static Node[] attributesToTree(List> attributes, Verbosity "name", rc.name().stringValue(), "type", rc.descriptor().stringValue())) .with(list("attributes", "attribute", rc.attributes().stream() - .map(Attribute::attributeName))) + .map(Attribute::attributeName).map(Utf8Entry::stringValue))) .with(attributesToTree(rc.attributes(), verbosity))))); case AnnotationDefaultAttribute ada -> nodes.add(new MapNodeImpl(FLOW, "annotation default").with(elementValueToTree(ada.defaultValue()))); diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java index 7d554a35974a2..5093f6408c8b9 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/DirectCodeBuilder.java @@ -241,6 +241,11 @@ public void writeBody(BufWriterImpl b) { if (crSize < characterRangesCount) b.patchU2(pos, crSize); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_CHARACTER_RANGE_TABLE); + } }; attributes.withAttribute(a); } @@ -265,6 +270,11 @@ public void writeBody(BufWriterImpl b) { if (lvSize < localVariablesCount) b.patchU2(pos, lvSize); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + } }; attributes.withAttribute(a); } @@ -289,6 +299,11 @@ public void writeBody(BufWriterImpl b) { if (lvtSize < localVariableTypesCount) b.patchU2(pos, lvtSize); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TYPE_TABLE); + } }; attributes.withAttribute(a); } @@ -371,6 +386,11 @@ public void writeBody(BufWriterImpl buf) { dcb.attributes.writeTo(buf); buf.setLabelContext(null); } + + @Override + public Utf8Entry attributeName() { + return constantPool.utf8Entry(Attributes.NAME_CODE); + } }; } @@ -416,6 +436,11 @@ public void writeTo(BufWriterImpl b) { b.writeU2(buf.size() / 4); b.writeBytes(buf); } + + @Override + public Utf8Entry attributeName() { + return buf.constantPool().utf8Entry(Attributes.NAME_LINE_NUMBER_TABLE); + } } private boolean codeAndExceptionsMatch(int codeLength) { diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java b/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java index 0e26a8941e0a1..5ba81fc292750 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/SplitConstantPool.java @@ -146,6 +146,11 @@ public void writeBody(BufWriterImpl b) { for (int i = 0; i < bsmSize; i++) bootstrapMethodEntry(i).writeTo(buf); } + + @Override + public Utf8Entry attributeName() { + return utf8Entry(Attributes.NAME_BOOTSTRAP_METHODS); + } }; a.writeTo(buf); } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java index a83c32dc05ad0..7e16aea5a5221 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/StackMapGenerator.java @@ -35,6 +35,7 @@ import java.lang.classfile.constantpool.ConstantPoolBuilder; import java.lang.classfile.constantpool.InvokeDynamicEntry; import java.lang.classfile.constantpool.MemberRefEntry; +import java.lang.classfile.constantpool.Utf8Entry; import java.lang.constant.ClassDesc; import java.lang.constant.MethodTypeDesc; import java.util.ArrayList; @@ -401,6 +402,11 @@ public void writeBody(BufWriterImpl b) { prevFrame = fr; } } + + @Override + public Utf8Entry attributeName() { + return cp.utf8Entry(Attributes.NAME_STACK_MAP_TABLE); + } }; } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java b/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java index dfad66a897c27..0b0f1836f66c2 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/UnboundAttribute.java @@ -54,11 +54,6 @@ public AttributeMapper attributeMapper() { return mapper; } - @Override - public String attributeName() { - return mapper.name(); - } - @Override @SuppressWarnings("unchecked") public void writeTo(BufWriterImpl buf) { @@ -93,6 +88,8 @@ public static final class UnboundConstantValueAttribute extends UnboundAttribute implements ConstantValueAttribute { + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_CONSTANT_VALUE); + private final ConstantValueEntry entry; public UnboundConstantValueAttribute(ConstantValueEntry entry) { @@ -105,27 +102,50 @@ public ConstantValueEntry constant() { return entry; } + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundDeprecatedAttribute extends UnboundAttribute implements DeprecatedAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_DEPRECATED); + public UnboundDeprecatedAttribute() { super(Attributes.deprecated()); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSyntheticAttribute extends UnboundAttribute implements SyntheticAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SYNTHETIC); + public UnboundSyntheticAttribute() { super(Attributes.synthetic()); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSignatureAttribute extends UnboundAttribute implements SignatureAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SIGNATURE); + private final Utf8Entry signature; public UnboundSignatureAttribute(Utf8Entry signature) { @@ -137,11 +157,19 @@ public UnboundSignatureAttribute(Utf8Entry signature) { public Utf8Entry signature() { return signature; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundExceptionsAttribute extends UnboundAttribute implements ExceptionsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_EXCEPTIONS); + private final List exceptions; public UnboundExceptionsAttribute(List exceptions) { @@ -153,11 +181,19 @@ public UnboundExceptionsAttribute(List exceptions) { public List exceptions() { return exceptions; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundAnnotationDefaultAttribute extends UnboundAttribute implements AnnotationDefaultAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_ANNOTATION_DEFAULT); + private final AnnotationValue annotationDefault; public UnboundAnnotationDefaultAttribute(AnnotationValue annotationDefault) { @@ -169,10 +205,18 @@ public UnboundAnnotationDefaultAttribute(AnnotationValue annotationDefault) { public AnnotationValue defaultValue() { return annotationDefault; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSourceFileAttribute extends UnboundAttribute implements SourceFileAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SOURCE_FILE); + private final Utf8Entry sourceFile; public UnboundSourceFileAttribute(Utf8Entry sourceFile) { @@ -185,10 +229,17 @@ public Utf8Entry sourceFile() { return sourceFile; } + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundStackMapTableAttribute extends UnboundAttribute implements StackMapTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_STACK_MAP_TABLE); + private final List entries; public UnboundStackMapTableAttribute(List entries) { @@ -200,11 +251,19 @@ public UnboundStackMapTableAttribute(List entries) { public List entries() { return entries; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundInnerClassesAttribute extends UnboundAttribute implements InnerClassesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_INNER_CLASSES); + private final List innerClasses; public UnboundInnerClassesAttribute(List innerClasses) { @@ -216,11 +275,19 @@ public UnboundInnerClassesAttribute(List innerClasses) { public List classes() { return innerClasses; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRecordAttribute extends UnboundAttribute implements RecordAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RECORD); + private final List components; public UnboundRecordAttribute(List components) { @@ -232,11 +299,19 @@ public UnboundRecordAttribute(List components) { public List components() { return components; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundEnclosingMethodAttribute extends UnboundAttribute implements EnclosingMethodAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_ENCLOSING_METHOD); + private final ClassEntry classEntry; private final NameAndTypeEntry method; @@ -255,11 +330,19 @@ public ClassEntry enclosingClass() { public Optional enclosingMethod() { return Optional.ofNullable(method); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundMethodParametersAttribute extends UnboundAttribute implements MethodParametersAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_METHOD_PARAMETERS); + private final List parameters; public UnboundMethodParametersAttribute(List parameters) { @@ -271,11 +354,19 @@ public UnboundMethodParametersAttribute(List parameters) { public List parameters() { return parameters; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleTargetAttribute extends UnboundAttribute implements ModuleTargetAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_TARGET); + final Utf8Entry moduleTarget; public UnboundModuleTargetAttribute(Utf8Entry moduleTarget) { @@ -287,11 +378,19 @@ public UnboundModuleTargetAttribute(Utf8Entry moduleTarget) { public Utf8Entry targetPlatform() { return moduleTarget; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleMainClassAttribute extends UnboundAttribute implements ModuleMainClassAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_MAIN_CLASS); + final ClassEntry mainClass; public UnboundModuleMainClassAttribute(ClassEntry mainClass) { @@ -303,11 +402,19 @@ public UnboundModuleMainClassAttribute(ClassEntry mainClass) { public ClassEntry mainClass() { return mainClass; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleHashesAttribute extends UnboundAttribute implements ModuleHashesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_HASHES); + private final Utf8Entry algorithm; private final List hashes; @@ -326,11 +433,19 @@ public Utf8Entry algorithm() { public List hashes() { return hashes; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModulePackagesAttribute extends UnboundAttribute implements ModulePackagesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_PACKAGES); + private final Collection packages; public UnboundModulePackagesAttribute(Collection packages) { @@ -342,11 +457,19 @@ public UnboundModulePackagesAttribute(Collection packages) { public List packages() { return List.copyOf(packages); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundModuleResolutionAttribute extends UnboundAttribute implements ModuleResolutionAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE_RESOLUTION); + private final int resolutionFlags; public UnboundModuleResolutionAttribute(int flags) { @@ -358,11 +481,19 @@ public UnboundModuleResolutionAttribute(int flags) { public int resolutionFlags() { return resolutionFlags; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundPermittedSubclassesAttribute extends UnboundAttribute implements PermittedSubclassesAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_PERMITTED_SUBCLASSES); + private final List permittedSubclasses; public UnboundPermittedSubclassesAttribute(List permittedSubclasses) { @@ -374,11 +505,19 @@ public UnboundPermittedSubclassesAttribute(List permittedSubclasses) public List permittedSubclasses() { return permittedSubclasses; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundNestMembersAttribute extends UnboundAttribute implements NestMembersAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_NEST_MEMBERS); + private final List memberEntries; public UnboundNestMembersAttribute(List memberEntries) { @@ -390,11 +529,19 @@ public UnboundNestMembersAttribute(List memberEntries) { public List nestMembers() { return memberEntries; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundNestHostAttribute extends UnboundAttribute implements NestHostAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_NEST_HOST); + private final ClassEntry hostEntry; public UnboundNestHostAttribute(ClassEntry hostEntry) { @@ -406,11 +553,19 @@ public UnboundNestHostAttribute(ClassEntry hostEntry) { public ClassEntry nestHost() { return hostEntry; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundCompilationIDAttribute extends UnboundAttribute implements CompilationIDAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_COMPILATION_ID); + private final Utf8Entry idEntry; public UnboundCompilationIDAttribute(Utf8Entry idEntry) { @@ -422,11 +577,19 @@ public UnboundCompilationIDAttribute(Utf8Entry idEntry) { public Utf8Entry compilationId() { return idEntry; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSourceIDAttribute extends UnboundAttribute implements SourceIDAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SOURCE_ID); + private final Utf8Entry idEntry; public UnboundSourceIDAttribute(Utf8Entry idEntry) { @@ -438,11 +601,19 @@ public UnboundSourceIDAttribute(Utf8Entry idEntry) { public Utf8Entry sourceId() { return idEntry; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundSourceDebugExtensionAttribute extends UnboundAttribute implements SourceDebugExtensionAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_SOURCE_DEBUG_EXTENSION); + private final byte[] contents; public UnboundSourceDebugExtensionAttribute(byte[] contents) { @@ -454,11 +625,19 @@ public UnboundSourceDebugExtensionAttribute(byte[] contents) { public byte[] contents() { return contents; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundCharacterRangeTableAttribute extends UnboundAttribute implements CharacterRangeTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_CHARACTER_RANGE_TABLE); + private final List ranges; public UnboundCharacterRangeTableAttribute(List ranges) { @@ -470,11 +649,19 @@ public UnboundCharacterRangeTableAttribute(List ranges) { public List characterRangeTable() { return ranges; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundLineNumberTableAttribute extends UnboundAttribute implements LineNumberTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_LINE_NUMBER_TABLE); + private final List lines; public UnboundLineNumberTableAttribute(List lines) { @@ -486,11 +673,19 @@ public UnboundLineNumberTableAttribute(List lines) { public List lineNumbers() { return lines; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundLocalVariableTableAttribute extends UnboundAttribute implements LocalVariableTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + private final List locals; public UnboundLocalVariableTableAttribute(List locals) { @@ -502,11 +697,19 @@ public UnboundLocalVariableTableAttribute(List locals) { public List localVariables() { return locals; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundLocalVariableTypeTableAttribute extends UnboundAttribute implements LocalVariableTypeTableAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TYPE_TABLE); + private final List locals; public UnboundLocalVariableTypeTableAttribute(List locals) { @@ -518,11 +721,19 @@ public UnboundLocalVariableTypeTableAttribute(List locals public List localVariableTypes() { return locals; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeVisibleAnnotationsAttribute extends UnboundAttribute implements RuntimeVisibleAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_VISIBLE_ANNOTATIONS); + private final List elements; public UnboundRuntimeVisibleAnnotationsAttribute(List elements) { @@ -534,11 +745,19 @@ public UnboundRuntimeVisibleAnnotationsAttribute(List elements) { public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeInvisibleAnnotationsAttribute extends UnboundAttribute implements RuntimeInvisibleAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_INVISIBLE_ANNOTATIONS); + private final List elements; public UnboundRuntimeInvisibleAnnotationsAttribute(List elements) { @@ -550,11 +769,19 @@ public UnboundRuntimeInvisibleAnnotationsAttribute(List elements) { public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeVisibleParameterAnnotationsAttribute extends UnboundAttribute implements RuntimeVisibleParameterAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS); + private final List> elements; public UnboundRuntimeVisibleParameterAnnotationsAttribute(List> elements) { @@ -572,11 +799,19 @@ public UnboundRuntimeVisibleParameterAnnotationsAttribute(List> public List> parameterAnnotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeInvisibleParameterAnnotationsAttribute extends UnboundAttribute implements RuntimeInvisibleParameterAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS); + private final List> elements; public UnboundRuntimeInvisibleParameterAnnotationsAttribute(List> elements) { @@ -594,11 +829,19 @@ public UnboundRuntimeInvisibleParameterAnnotationsAttribute(List> parameterAnnotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeVisibleTypeAnnotationsAttribute extends UnboundAttribute implements RuntimeVisibleTypeAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_VISIBLE_TYPE_ANNOTATIONS); + private final List elements; public UnboundRuntimeVisibleTypeAnnotationsAttribute(List elements) { @@ -610,11 +853,19 @@ public UnboundRuntimeVisibleTypeAnnotationsAttribute(List elemen public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public static final class UnboundRuntimeInvisibleTypeAnnotationsAttribute extends UnboundAttribute implements RuntimeInvisibleTypeAnnotationsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_RUNTIME_INVISIBLE_TYPE_ANNOTATIONS); + private final List elements; public UnboundRuntimeInvisibleTypeAnnotationsAttribute(List elements) { @@ -626,6 +877,11 @@ public UnboundRuntimeInvisibleTypeAnnotationsAttribute(List elem public List annotations() { return elements; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public record UnboundCharacterRangeInfo(int startPc, int endPc, @@ -749,6 +1005,9 @@ public record TypePathComponentImpl(TypeAnnotation.TypePathComponent.Kind typePa implements TypeAnnotation.TypePathComponent {} public static final class UnboundModuleAttribute extends UnboundAttribute implements ModuleAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_MODULE); + private final ModuleEntry moduleName; private final int moduleFlags; private final Utf8Entry moduleVersion; @@ -817,6 +1076,11 @@ public List uses() { public List provides() { return provides; } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } public abstract static non-sealed class AdHocAttribute> @@ -841,6 +1105,9 @@ public void writeTo(BufWriterImpl b) { public static final class EmptyBootstrapAttribute extends UnboundAttribute implements BootstrapMethodsAttribute { + + private static final Utf8Entry NAME = TemporaryConstantPool.INSTANCE.utf8Entry(Attributes.NAME_BOOTSTRAP_METHODS); + public EmptyBootstrapAttribute() { super(Attributes.bootstrapMethods()); } @@ -854,5 +1121,10 @@ public int bootstrapMethodsSize() { public List bootstrapMethods() { return List.of(); } + + @Override + public Utf8Entry attributeName() { + return NAME; + } } } diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java index 1088724d8b4a3..fc6099f3e5b1f 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/Util.java @@ -281,6 +281,11 @@ public void writeBody(BufWriterImpl b) { b.writeBytes(bytecode.array(), 0, bytecode.length()); b.writeU2U2(0, 0);//exception handlers & attributes } + + @Override + public Utf8Entry attributeName() { + return cp.utf8Entry(Attributes.NAME_CODE); + } })))); ClassPrinter.toYaml(clm.methods().get(0).code().get(), ClassPrinter.Verbosity.TRACE_ALL, dump); } catch (Error | Exception _) { diff --git a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java index 521d74ae1332f..b7ddaace116d9 100644 --- a/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java +++ b/src/java.base/share/classes/jdk/internal/classfile/impl/verifier/ParserVerifier.java @@ -176,8 +176,8 @@ private void verifyAttributes(ClassFileElement cfe, List errors) { if (cfe instanceof AttributedElement ae) { var attrNames = new HashSet(); for (var a : ae.attributes()) { - if (!a.attributeMapper().allowMultiple() && !attrNames.add(a.attributeName())) { - errors.add(new VerifyError("Multiple %s attributes in %s".formatted(a.attributeName(), toString(ae)))); + if (!a.attributeMapper().allowMultiple() && !attrNames.add(a.attributeName().stringValue())) { + errors.add(new VerifyError("Multiple %s attributes in %s".formatted(a.attributeName().stringValue(), toString(ae)))); } verifyAttribute(ae, a, errors); } @@ -331,7 +331,7 @@ private void verifyAttribute(AttributedElement ae, Attribute a, List= 0 && size != ((BoundAttribute)a).payloadLen()) { - errors.add(new VerifyError("Wrong %s attribute length in %s".formatted(a.attributeName(), toString(ae)))); + errors.add(new VerifyError("Wrong %s attribute length in %s".formatted(a.attributeName().stringValue(), toString(ae)))); } } diff --git a/src/java.base/share/classes/jdk/internal/constant/MethodTypeDescImpl.java b/src/java.base/share/classes/jdk/internal/constant/MethodTypeDescImpl.java index 826fc095bbd28..fcbf60648535a 100644 --- a/src/java.base/share/classes/jdk/internal/constant/MethodTypeDescImpl.java +++ b/src/java.base/share/classes/jdk/internal/constant/MethodTypeDescImpl.java @@ -32,8 +32,6 @@ import java.lang.constant.MethodTypeDesc; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -320,15 +318,8 @@ private String buildDescriptorString() { public MethodType resolveConstantDesc(MethodHandles.Lookup lookup) throws ReflectiveOperationException { MethodType mtype; try { - @SuppressWarnings("removal") - MethodType mt = AccessController.doPrivileged(new PrivilegedAction<>() { - @Override - public MethodType run() { - return MethodType.fromMethodDescriptorString(descriptorString(), - lookup.lookupClass().getClassLoader()); - } - }); - mtype = mt; + mtype = MethodType.fromMethodDescriptorString(descriptorString(), + lookup.lookupClass().getClassLoader()); } catch (TypeNotPresentException ex) { throw (ClassNotFoundException) ex.getCause(); } diff --git a/src/java.base/share/classes/jdk/internal/io/JdkConsole.java b/src/java.base/share/classes/jdk/internal/io/JdkConsole.java index 6c911ed6fed88..08bd840de37f2 100644 --- a/src/java.base/share/classes/jdk/internal/io/JdkConsole.java +++ b/src/java.base/share/classes/jdk/internal/io/JdkConsole.java @@ -41,6 +41,7 @@ public interface JdkConsole { JdkConsole println(Object obj); JdkConsole print(Object obj); String readln(String prompt); + String readln(); JdkConsole format(Locale locale, String format, Object ... args); String readLine(Locale locale, String format, Object ... args); String readLine(); diff --git a/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java b/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java index a1086b245d1b6..3c0afd2005cb1 100644 --- a/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java +++ b/src/java.base/share/classes/jdk/internal/io/JdkConsoleImpl.java @@ -90,6 +90,21 @@ public String readln(String prompt) { return line; } + @Override + public String readln() { + String line = null; + synchronized(readLock) { + try { + char[] ca = readline(false); + if (ca != null) + line = new String(ca); + } catch (IOException x) { + throw new IOError(x); + } + } + return line; + } + @Override public JdkConsole format(Locale locale, String format, Object ... args) { formatter.format(locale, format, args).flush(); diff --git a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java index 4b2a0629706c1..b8db00998c06a 100644 --- a/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java +++ b/src/java.base/share/classes/jdk/internal/javac/PreviewFeature.java @@ -68,16 +68,15 @@ public enum Feature { // keeping the constant of a feature that has been integrated or dropped, serves the purpose of muting such warnings. //--- - @JEP(number=477, title="Implicitly Declared Classes and Instance Main Methods", status="Third Preview") + @JEP(number=495, title="Simple Source Files and Instance Main Methods", status="Fourth Preview") IMPLICIT_CLASSES, @JEP(number=487, title="Scoped Values", status="Fourth Preview") SCOPED_VALUES, @JEP(number=480, title="Structured Concurrency", status="Third Preview") STRUCTURED_CONCURRENCY, - @JEP(number=466, title="ClassFile API", status="Second Preview") CLASSFILE_API, STREAM_GATHERERS, - @JEP(number=476, title="Module Import Declarations", status="Preview") + @JEP(number=494, title="Module Import Declarations", status="Second Preview") MODULE_IMPORTS, @JEP(number=478, title="Key Derivation Function API", status="Preview") KEY_DERIVATION, diff --git a/src/java.base/share/classes/jdk/internal/loader/BootLoader.java b/src/java.base/share/classes/jdk/internal/loader/BootLoader.java index 98ff60a73095a..c845146a838de 100644 --- a/src/java.base/share/classes/jdk/internal/loader/BootLoader.java +++ b/src/java.base/share/classes/jdk/internal/loader/BootLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -32,8 +32,6 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Arrays; import java.util.Enumeration; import java.util.concurrent.ConcurrentHashMap; @@ -143,18 +141,8 @@ public static Class loadClass(Module module, String name) { /** * Loads a native library from the system library path. */ - @SuppressWarnings("removal") public static void loadLibrary(String name) { - if (System.getSecurityManager() == null) { - BootLoader.getNativeLibraries().loadLibrary(name); - } else { - AccessController.doPrivileged(new java.security.PrivilegedAction<>() { - public Void run() { - BootLoader.getNativeLibraries().loadLibrary(name); - return null; - } - }); - } + getNativeLibraries().loadLibrary(name); } /** @@ -294,38 +282,28 @@ private static Module findModule(String location) { /** * Returns URL if the given location is a regular file path. */ - @SuppressWarnings("removal") private static URL toFileURL(String location) { - return AccessController.doPrivileged(new PrivilegedAction<>() { - public URL run() { - Path path = Path.of(location); - if (Files.isRegularFile(path)) { - try { - return path.toUri().toURL(); - } catch (MalformedURLException e) {} - } - return null; - } - }); + Path path = Path.of(location); + if (Files.isRegularFile(path)) { + try { + return path.toUri().toURL(); + } catch (MalformedURLException e) {} + } + return null; } /** * Returns the Manifest if the given location is a JAR file * containing a manifest. */ - @SuppressWarnings("removal") private static Manifest getManifest(String location) { - return AccessController.doPrivileged(new PrivilegedAction<>() { - public Manifest run() { - Path jar = Path.of(location); - try (InputStream in = Files.newInputStream(jar); - JarInputStream jis = new JarInputStream(in, false)) { - return jis.getManifest(); - } catch (IOException e) { - return null; - } - } - }); + Path jar = Path.of(location); + try (InputStream in = Files.newInputStream(jar); + JarInputStream jis = new JarInputStream(in, false)) { + return jis.getManifest(); + } catch (IOException e) { + return null; + } } } diff --git a/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java b/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java index 84e5c50672d81..ddf35a88d0ab0 100644 --- a/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java +++ b/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -35,13 +35,8 @@ import java.net.URI; import java.net.URL; import java.nio.ByteBuffer; -import java.security.AccessController; import java.security.CodeSigner; import java.security.CodeSource; -import java.security.PermissionCollection; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.security.SecureClassLoader; import java.util.ArrayList; import java.util.Collections; @@ -62,7 +57,6 @@ import jdk.internal.module.ModulePatcher.PatchedModuleReader; import jdk.internal.module.Resources; import jdk.internal.vm.annotation.Stable; -import sun.security.util.LazyCodeSourcePermissionCollection; /** @@ -281,31 +275,30 @@ public URL findResource(String mn, String name) throws IOException { url = findResourceOnClassPath(name); } - return checkURL(url); // check access before returning + return url; } /** * Returns an input stream to a resource of the given name in a module * defined to this class loader. */ - @SuppressWarnings("removal") public InputStream findResourceAsStream(String mn, String name) throws IOException { - // Need URL to resource when running with a security manager so that - // the right permission check is done. - if (System.getSecurityManager() != null || mn == null) { - URL url = findResource(mn, name); - return (url != null) ? url.openStream() : null; - } - - // find in module defined to this loader, no security manager - ModuleReference mref = nameToModule.get(mn); - if (mref != null) { - return moduleReaderFor(mref).open(name).orElse(null); + InputStream in = null; + if (mn != null) { + // find in module defined to this loader + ModuleReference mref = nameToModule.get(mn); + if (mref != null) { + in = moduleReaderFor(mref).open(name).orElse(null); + } } else { - return null; + URL url = findResourceOnClassPath(name); + if (url != null) { + in = url.openStream(); + } } + return in; } /** @@ -342,7 +335,7 @@ public URL findResource(String name) { if (!urls.isEmpty()) { URL url = urls.get(0); if (url != null) { - return checkURL(url); // check access before returning + return url; } } } catch (IOException ioe) { @@ -352,8 +345,7 @@ public URL findResource(String name) { } // search class path - URL url = findResourceOnClassPath(name); - return checkURL(url); + return findResourceOnClassPath(name); } /** @@ -383,7 +375,6 @@ public Enumeration findResources(String name) throws IOException { } else { // not in a package of a module defined to this loader for (URL url : findMiscResource(name)) { - url = checkURL(url); if (url != null) { checked.add(url); } @@ -406,7 +397,7 @@ private boolean hasNext() { } else { // need to check each URL while (e.hasMoreElements() && next == null) { - next = checkURL(e.nextElement()); + next = e.nextElement(); } return next != null; } @@ -436,7 +427,6 @@ public URL nextElement() { * * The cache used by this method avoids repeated searching of all modules. */ - @SuppressWarnings("removal") private List findMiscResource(String name) throws IOException { SoftReference>> ref = this.resourceCache; Map> map = (ref != null) ? ref.get() : null; @@ -453,30 +443,20 @@ private List findMiscResource(String name) throws IOException { } // search all modules for the resource - List urls; - try { - urls = AccessController.doPrivileged( - new PrivilegedExceptionAction<>() { - @Override - public List run() throws IOException { - List result = null; - for (ModuleReference mref : nameToModule.values()) { - URI u = moduleReaderFor(mref).find(name).orElse(null); - if (u != null) { - try { - if (result == null) - result = new ArrayList<>(); - result.add(u.toURL()); - } catch (MalformedURLException | - IllegalArgumentException e) { - } - } - } - return (result != null) ? result : Collections.emptyList(); - } - }); - } catch (PrivilegedActionException pae) { - throw (IOException) pae.getCause(); + List urls = null; + for (ModuleReference mref : nameToModule.values()) { + URI u = moduleReaderFor(mref).find(name).orElse(null); + if (u != null) { + try { + if (urls == null) + urls = new ArrayList<>(); + urls.add(u.toURL()); + } catch (MalformedURLException | IllegalArgumentException e) { + } + } + } + if (urls == null) { + urls = List.of(); } // only cache resources after VM is fully initialized @@ -490,23 +470,8 @@ public List run() throws IOException { /** * Returns the URL to a resource in a module or {@code null} if not found. */ - @SuppressWarnings("removal") private URL findResource(ModuleReference mref, String name) throws IOException { - URI u; - if (System.getSecurityManager() == null) { - u = moduleReaderFor(mref).find(name).orElse(null); - } else { - try { - u = AccessController.doPrivileged(new PrivilegedExceptionAction<> () { - @Override - public URI run() throws IOException { - return moduleReaderFor(mref).find(name).orElse(null); - } - }); - } catch (PrivilegedActionException pae) { - throw (IOException) pae.getCause(); - } - } + URI u = moduleReaderFor(mref).find(name).orElse(null); if (u != null) { try { return u.toURL(); @@ -515,30 +480,12 @@ public URI run() throws IOException { return null; } - /** - * Returns the URL to a resource in a module. Returns {@code null} if not found - * or an I/O error occurs. - */ - private URL findResourceOrNull(ModuleReference mref, String name) { - try { - return findResource(mref, name); - } catch (IOException ignore) { - return null; - } - } - /** * Returns a URL to a resource on the class path. */ - @SuppressWarnings("removal") private URL findResourceOnClassPath(String name) { if (hasClassPath()) { - if (System.getSecurityManager() == null) { - return ucp.findResource(name, false); - } else { - PrivilegedAction pa = () -> ucp.findResource(name, false); - return AccessController.doPrivileged(pa); - } + return ucp.findResource(name, false); } else { // no class path return null; @@ -548,16 +495,9 @@ private URL findResourceOnClassPath(String name) { /** * Returns the URLs of all resources of the given name on the class path. */ - @SuppressWarnings("removal") private Enumeration findResourcesOnClassPath(String name) { if (hasClassPath()) { - if (System.getSecurityManager() == null) { - return ucp.findResources(name, false); - } else { - PrivilegedAction> pa; - pa = () -> ucp.findResources(name, false); - return AccessController.doPrivileged(pa); - } + return ucp.findResources(name, false); } else { // no class path return Collections.emptyEnumeration(); @@ -735,14 +675,8 @@ private LoadedModule findLoadedModule(String mn, String cn) { * * @return the resulting Class or {@code null} if not found */ - @SuppressWarnings("removal") private Class findClassInModuleOrNull(LoadedModule loadedModule, String cn) { - if (System.getSecurityManager() == null) { - return defineClass(cn, loadedModule); - } else { - PrivilegedAction> pa = () -> defineClass(cn, loadedModule); - return AccessController.doPrivileged(pa); - } + return defineClass(cn, loadedModule); } /** @@ -750,36 +684,17 @@ private Class findClassInModuleOrNull(LoadedModule loadedModule, String cn) { * * @return the resulting Class or {@code null} if not found */ - @SuppressWarnings("removal") private Class findClassOnClassPathOrNull(String cn) { String path = cn.replace('.', '/').concat(".class"); - if (System.getSecurityManager() == null) { - Resource res = ucp.getResource(path, false); - if (res != null) { - try { - return defineClass(cn, res); - } catch (IOException ioe) { - // TBD on how I/O errors should be propagated - } + Resource res = ucp.getResource(path, false); + if (res != null) { + try { + return defineClass(cn, res); + } catch (IOException ioe) { + // TBD on how I/O errors should be propagated } - return null; - } else { - // avoid use of lambda here - PrivilegedAction> pa = new PrivilegedAction<>() { - public Class run() { - Resource res = ucp.getResource(path, false); - if (res != null) { - try { - return defineClass(cn, res); - } catch (IOException ioe) { - // TBD on how I/O errors should be propagated - } - } - return null; - } - }; - return AccessController.doPrivileged(pa); } + return null; } /** @@ -998,16 +913,6 @@ private boolean isSealed(String pn, Manifest man) { return "true".equalsIgnoreCase(sealed); } - // -- permissions - - /** - * Returns the permissions for the given CodeSource. - */ - @Override - protected PermissionCollection getPermissions(CodeSource cs) { - return new LazyCodeSourcePermissionCollection(super.getPermissions(cs), cs); - } - // -- miscellaneous supporting methods /** @@ -1072,14 +977,6 @@ private boolean isOpen(ModuleReference mref, String pn) { return false; } - /** - * Checks access to the given URL. We use URLClassPath for consistent - * checking with java.net.URLClassLoader. - */ - private static URL checkURL(URL url) { - return URLClassPath.checkURL(url); - } - // Called from VM only, during -Xshare:dump private void resetArchivedStates() { ucp = null; diff --git a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java index ab4aa3fb90734..1a61d4b15224c 100644 --- a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java +++ b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -29,8 +29,6 @@ import java.net.URL; import java.nio.file.InvalidPathException; import java.nio.file.Path; -import java.security.CodeSource; -import java.security.PermissionCollection; import java.util.jar.Manifest; import jdk.internal.access.JavaLangAccess; @@ -170,31 +168,6 @@ private static class AppClassLoader extends BuiltinClassLoader { super("app", parent, ucp); } - @Override - protected Class loadClass(String cn, boolean resolve) - throws ClassNotFoundException - { - // for compatibility reasons, say where restricted package list has - // been updated to list API packages in the unnamed module. - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - int i = cn.lastIndexOf('.'); - if (i != -1) { - sm.checkPackageAccess(cn.substring(0, i)); - } - } - - return super.loadClass(cn, resolve); - } - - @Override - protected PermissionCollection getPermissions(CodeSource cs) { - PermissionCollection perms = super.getPermissions(cs); - perms.add(new RuntimePermission("exitVM")); - return perms; - } - /** * Called by the VM to support dynamic additions to the class path * @@ -207,6 +180,7 @@ void appendToClassPathForInstrumentation(String path) { /** * Called by the VM to support define package for AppCDS */ + @Override protected Package defineOrCheckPackage(String pn, Manifest man, URL url) { return super.defineOrCheckPackage(pn, man, url); } diff --git a/src/java.base/share/classes/jdk/internal/loader/Loader.java b/src/java.base/share/classes/jdk/internal/loader/Loader.java index fbd16467da766..c4f9023482dc6 100644 --- a/src/java.base/share/classes/jdk/internal/loader/Loader.java +++ b/src/java.base/share/classes/jdk/internal/loader/Loader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -25,8 +25,6 @@ package jdk.internal.loader; -import java.io.File; -import java.io.FilePermission; import java.io.IOException; import java.lang.module.Configuration; import java.lang.module.ModuleDescriptor; @@ -37,15 +35,8 @@ import java.net.URI; import java.net.URL; import java.nio.ByteBuffer; -import java.security.AccessControlContext; -import java.security.AccessController; import java.security.CodeSigner; import java.security.CodeSource; -import java.security.Permission; -import java.security.PermissionCollection; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.security.SecureClassLoader; import java.util.ArrayList; import java.util.Collection; @@ -110,16 +101,11 @@ public final class Loader extends SecureClassLoader { private final Map moduleToReader = new ConcurrentHashMap<>(); - // ACC used when loading classes and resources - @SuppressWarnings("removal") - private final AccessControlContext acc; - /** * A module defined/loaded to a {@code Loader}. */ private static class LoadedModule { private final ModuleReference mref; - private final URL url; // may be null private final CodeSource cs; LoadedModule(ModuleReference mref) { @@ -130,13 +116,11 @@ private static class LoadedModule { } catch (MalformedURLException | IllegalArgumentException e) { } } this.mref = mref; - this.url = url; this.cs = new CodeSource(url, (CodeSigner[]) null); } ModuleReference mref() { return mref; } String name() { return mref.descriptor().name(); } - URL location() { return url; } CodeSource codeSource() { return cs; } } @@ -145,7 +129,6 @@ private static class LoadedModule { * Creates a {@code Loader} in a loader pool that loads classes/resources * from one module. */ - @SuppressWarnings("removal") public Loader(ResolvedModule resolvedModule, LoaderPool pool, ClassLoader parent) @@ -164,8 +147,6 @@ public Loader(ResolvedModule resolvedModule, LoadedModule lm = new LoadedModule(mref); descriptor.packages().forEach(pn -> localPackageToModule.put(pn, lm)); this.localPackageToModule = localPackageToModule; - - this.acc = AccessController.getContext(); } /** @@ -175,7 +156,6 @@ public Loader(ResolvedModule resolvedModule, * @throws IllegalArgumentException * If two or more modules have the same package */ - @SuppressWarnings("removal") public Loader(Collection modules, ClassLoader parent) { super(parent); @@ -197,8 +177,6 @@ public Loader(Collection modules, ClassLoader parent) { } this.nameToModule = nameToModule; this.localPackageToModule = localPackageToModule; - - this.acc = AccessController.getContext(); } /** @@ -326,7 +304,6 @@ public LoaderPool pool() { * Returns a URL to a resource of the given name in a module defined to * this class loader. */ - @SuppressWarnings("removal") @Override protected URL findResource(String mn, String name) throws IOException { ModuleReference mref = (mn != null) ? nameToModule.get(mn) : null; @@ -335,41 +312,12 @@ protected URL findResource(String mn, String name) throws IOException { // locate resource URL url = null; - try { - url = AccessController.doPrivileged( - new PrivilegedExceptionAction() { - @Override - public URL run() throws IOException { - Optional ouri = moduleReaderFor(mref).find(name); - if (ouri.isPresent()) { - try { - return ouri.get().toURL(); - } catch (MalformedURLException | - IllegalArgumentException e) { } - } - return null; - } - }); - } catch (PrivilegedActionException pae) { - throw (IOException) pae.getCause(); - } - - // check access with permissions restricted by ACC - if (url != null && System.getSecurityManager() != null) { + Optional ouri = moduleReaderFor(mref).find(name); + if (ouri.isPresent()) { try { - URL urlToCheck = url; - url = AccessController.doPrivileged( - new PrivilegedExceptionAction() { - @Override - public URL run() throws IOException { - return URLClassPath.checkURL(urlToCheck); - } - }, acc); - } catch (PrivilegedActionException pae) { - url = null; - } + url = ouri.get().toURL(); + } catch (MalformedURLException | IllegalArgumentException e) { } } - return url; } @@ -525,15 +473,6 @@ protected Class findClass(String mn, String cn) { protected Class loadClass(String cn, boolean resolve) throws ClassNotFoundException { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - String pn = packageName(cn); - if (!pn.isEmpty()) { - sm.checkPackageAccess(pn); - } - } - synchronized (getClassLoadingLock(cn)) { // check if already loaded Class c = findLoadedClass(cn); @@ -584,19 +523,7 @@ protected Class loadClass(String cn, boolean resolve) * * @return the resulting Class or {@code null} if not found */ - @SuppressWarnings("removal") private Class findClassInModuleOrNull(LoadedModule loadedModule, String cn) { - PrivilegedAction> pa = () -> defineClass(cn, loadedModule); - return AccessController.doPrivileged(pa, acc); - } - - /** - * Defines the given binary class name to the VM, loading the class - * bytes from the given module. - * - * @return the resulting Class or {@code null} if an I/O error occurs - */ - private Class defineClass(String cn, LoadedModule loadedModule) { ModuleReader reader = moduleReaderFor(loadedModule.mref()); try { @@ -620,40 +547,6 @@ private Class defineClass(String cn, LoadedModule loadedModule) { } } - - // -- permissions - - /** - * Returns the permissions for the given CodeSource. - */ - @Override - protected PermissionCollection getPermissions(CodeSource cs) { - PermissionCollection perms = super.getPermissions(cs); - - URL url = cs.getLocation(); - if (url == null) - return perms; - - // add the permission to access the resource - try { - Permission p = url.openConnection().getPermission(); - if (p != null) { - // for directories then need recursive access - if (p instanceof FilePermission) { - String path = p.getName(); - if (path.endsWith(File.separator)) { - path += "-"; - p = new FilePermission(path, "read"); - } - } - perms.add(p); - } - } catch (IOException ioe) { } - - return perms; - } - - // -- miscellaneous supporting methods /** diff --git a/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java b/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java index 64a3813a91450..02dc79f028884 100644 --- a/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java +++ b/src/java.base/share/classes/jdk/internal/loader/NativeLibraries.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -114,25 +114,17 @@ public long find(String name) { * @param file the path of the native library * @throws UnsatisfiedLinkError if any error in loading the native library */ - @SuppressWarnings("removal") public NativeLibrary loadLibrary(Class fromClass, File file) { // Check to see if we're attempting to access a static library String name = findBuiltinLib(file.getName()); boolean isBuiltin = (name != null); if (!isBuiltin) { - name = AccessController.doPrivileged(new PrivilegedAction<>() { - public String run() { - try { - if (loadLibraryOnlyIfPresent && !file.exists()) { - return null; - } - return file.getCanonicalPath(); - } catch (IOException e) { - return null; - } - } - }); - if (name == null) { + try { + if (loadLibraryOnlyIfPresent && !file.exists()) { + return null; + } + name = file.getCanonicalPath(); + } catch (IOException e) { return null; } } diff --git a/src/java.base/share/classes/jdk/internal/loader/RawNativeLibraries.java b/src/java.base/share/classes/jdk/internal/loader/RawNativeLibraries.java index 35ed4701c9902..fa4c1390c1ab2 100644 --- a/src/java.base/share/classes/jdk/internal/loader/RawNativeLibraries.java +++ b/src/java.base/share/classes/jdk/internal/loader/RawNativeLibraries.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -29,8 +29,6 @@ import java.io.IOException; import java.lang.invoke.MethodHandles; import java.nio.file.Path; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -78,18 +76,11 @@ public static RawNativeLibraries newInstance(MethodHandles.Lookup trustedCaller) * * @param path the path of the native library */ - @SuppressWarnings("removal") public NativeLibrary load(Path path) { - String name = AccessController.doPrivileged(new PrivilegedAction<>() { - public String run() { - try { - return path.toRealPath().toString(); - } catch (IOException e) { - return null; - } - } - }); - if (name == null) { + String name; + try { + name = path.toRealPath().toString(); + } catch (IOException e) { return null; } return load(name); diff --git a/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java b/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java index f6d868dfcc281..90113a4a27163 100644 --- a/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java +++ b/src/java.base/share/classes/jdk/internal/math/FDBigInteger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -217,7 +217,7 @@ private FDBigInteger(int[] data, int offset) { @ requires (\forall int i; 0 <= i && i < nDigits; '0' <= digits[i] && digits[i] <= '9'); @ ensures this.value() == \old(lValue * pow10(nDigits - kDigits) + (\sum int i; kDigits <= i && i < nDigits; (digits[i] - '0') * pow10(nDigits - i - 1))); @*/ - public FDBigInteger(long lValue, char[] digits, int kDigits, int nDigits) { + public FDBigInteger(long lValue, byte[] digits, int kDigits, int nDigits) { int n = Math.max((nDigits + 8) / 9, 2); // estimate size needed. data = new int[n]; // allocate enough space data[0] = (int) lValue; // starting value diff --git a/src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java b/src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java index 408b98ac55a75..dcfa9e88da298 100644 --- a/src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java +++ b/src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2024, 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 @@ -1034,10 +1034,10 @@ public float floatValue() { static class ASCIIToBinaryBuffer implements ASCIIToBinaryConverter { boolean isNegative; int decExponent; - char digits[]; + byte[] digits; int nDigits; - ASCIIToBinaryBuffer( boolean negSign, int decExponent, char[] digits, int n) + ASCIIToBinaryBuffer( boolean negSign, int decExponent, byte[] digits, int n) { this.isNegative = negSign; this.decExponent = decExponent; @@ -1872,7 +1872,7 @@ static ASCIIToBinaryConverter readJavaFormatString( String in ) throws NumberFor } } // look for and process decimal floating-point string - char[] digits = new char[ len ]; + byte[] digits = new byte[ len ]; boolean decSeen = false; int nDigits = 0; int decPt = 0; @@ -1903,10 +1903,10 @@ static ASCIIToBinaryConverter readJavaFormatString( String in ) throws NumberFor while (i < len) { c = in.charAt(i); if (c >= '1' && c <= '9') { - digits[nDigits++] = c; + digits[nDigits++] = (byte) c; nTrailZero = 0; } else if (c == '0') { - digits[nDigits++] = c; + digits[nDigits++] = (byte) c; nTrailZero++; } else if (c == '.') { if (decSeen) { diff --git a/src/java.base/share/classes/jdk/internal/misc/CarrierThread.java b/src/java.base/share/classes/jdk/internal/misc/CarrierThread.java index 9a479b0e61ecf..b314b1823a56d 100644 --- a/src/java.base/share/classes/jdk/internal/misc/CarrierThread.java +++ b/src/java.base/share/classes/jdk/internal/misc/CarrierThread.java @@ -25,8 +25,6 @@ package jdk.internal.misc; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinWorkerThread; import jdk.internal.access.JavaLangAccess; @@ -114,17 +112,12 @@ public void setContextClassLoader(ClassLoader cl) { /** * The thread group for the carrier threads. */ - @SuppressWarnings("removal") private static ThreadGroup carrierThreadGroup() { - return AccessController.doPrivileged(new PrivilegedAction() { - public ThreadGroup run() { - ThreadGroup group = JLA.currentCarrierThread().getThreadGroup(); - for (ThreadGroup p; (p = group.getParent()) != null; ) - group = p; - var carrierThreadsGroup = new ThreadGroup(group, "CarrierThreads"); - return carrierThreadsGroup; - } - }); + ThreadGroup group = JLA.currentCarrierThread().getThreadGroup(); + for (ThreadGroup p; (p = group.getParent()) != null; ) + group = p; + var carrierThreadsGroup = new ThreadGroup(group, "CarrierThreads"); + return carrierThreadsGroup; } /** diff --git a/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java b/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java index f2b1b85e2a112..ca2fcf11e993f 100644 --- a/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java +++ b/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java @@ -25,10 +25,6 @@ package jdk.internal.misc; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.ProtectionDomain; -import java.security.PrivilegedAction; import java.util.concurrent.atomic.AtomicInteger; /** @@ -69,18 +65,8 @@ public static Thread newThread(String name, Runnable target) { * set to the given priority. */ public static Thread newThread(String name, Runnable target, int priority) { - if (System.getSecurityManager() == null) { - return createThread(name, target, 0L, - ClassLoader.getSystemClassLoader(), priority); - } - return AccessController.doPrivileged( - new PrivilegedAction() { - @Override - public Thread run() { - return createThread(name, target, 0L, - ClassLoader.getSystemClassLoader(), priority); - } - }); + return createThread(name, target, 0L, + ClassLoader.getSystemClassLoader(), priority); } /** @@ -103,17 +89,7 @@ public static Thread newSystemThread(String name, Runnable target) { * Thread priority is set to the given priority. */ public static Thread newSystemThread(String name, Runnable target, int priority) { - if (System.getSecurityManager() == null) { - return createThread(name, target, 0L, null, priority); - } - return AccessController.doPrivileged( - new PrivilegedAction() { - @Override - public Thread run() { - return createThread(name, target, 0L, - null, priority); - } - }); + return createThread(name, target, 0L, null, priority); } /** @@ -122,17 +98,7 @@ public Thread run() { */ public static Thread newSystemThread(String name, Runnable target, long stackSize, int priority) { - if (System.getSecurityManager() == null) { - return createThread(name, target, stackSize, null, priority); - } - return AccessController.doPrivileged( - new PrivilegedAction() { - @Override - public Thread run() { - return createThread(name, target, 0L, - null, priority); - } - }); + return createThread(name, target, stackSize, null, priority); } private static Thread createThread(String name, Runnable target, long stackSize, @@ -207,18 +173,7 @@ public void run() { break; group = parent; } - final ThreadGroup root = group; - if (System.getSecurityManager() == null) { - INNOCUOUSTHREADGROUP = new ThreadGroup(root, "InnocuousThreadGroup"); - } else { - INNOCUOUSTHREADGROUP = AccessController.doPrivileged( - new PrivilegedAction() { - @Override - public ThreadGroup run() { - return new ThreadGroup(root, "InnocuousThreadGroup"); - } - }); - } + INNOCUOUSTHREADGROUP = new ThreadGroup(group, "InnocuousThreadGroup"); } catch (Exception e) { throw new Error(e); } diff --git a/src/java.base/share/classes/jdk/internal/misc/InternalLock.java b/src/java.base/share/classes/jdk/internal/misc/InternalLock.java deleted file mode 100644 index 822b64f74ca6a..0000000000000 --- a/src/java.base/share/classes/jdk/internal/misc/InternalLock.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2021, 2024, 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. - */ - -package jdk.internal.misc; - -import java.util.concurrent.locks.ReentrantLock; - -/** - * A reentrant mutual exclusion lock for internal use. The lock does not - * implement {@link java.util.concurrent.locks.Lock} or extend {@link - * java.util.concurrent.locks.ReentrantLock} so that it can be distinguished - * from lock objects accessible to subclasses of {@link java.io.Reader} and - * {@link java.io.Writer} (it is possible to create a Reader that uses a - * lock object of type ReentrantLock for example). - */ -public class InternalLock { - private static final boolean CAN_USE_INTERNAL_LOCK; - static { - String s = System.getProperty("jdk.io.useMonitors"); - if (s != null && s.equals("false")) { - CAN_USE_INTERNAL_LOCK = true; - } else { - CAN_USE_INTERNAL_LOCK = false; - } - } - - private final ReentrantLock lock; - - private InternalLock() { - this.lock = new ReentrantLock(); - } - - /** - * Returns a new InternalLock or null. - */ - public static InternalLock newLockOrNull() { - return (CAN_USE_INTERNAL_LOCK) ? new InternalLock() : null; - } - - /** - * Returns a new InternalLock or the given object. - */ - public static Object newLockOr(Object obj) { - return (CAN_USE_INTERNAL_LOCK) ? new InternalLock() : obj; - } - - public boolean tryLock() { - return lock.tryLock(); - } - - public void lock() { - lock.lock(); - } - - public void unlock() { - lock.unlock(); - } - - public boolean isHeldByCurrentThread() { - return lock.isHeldByCurrentThread(); - } -} diff --git a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java index 26cb12f484a5f..75b3b8fc9938a 100644 --- a/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java +++ b/src/java.base/share/classes/jdk/internal/module/ModuleInfo.java @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; +import java.lang.classfile.ClassFile; import java.lang.module.InvalidModuleDescriptorException; import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor.Builder; @@ -189,6 +190,7 @@ private Attributes doRead(DataInput input) throws IOException { int minor_version = in.readUnsignedShort(); int major_version = in.readUnsignedShort(); + boolean isPreview = minor_version == ClassFile.PREVIEW_MINOR_VERSION; if (!VM.isSupportedModuleDescriptorVersion(major_version, minor_version)) { throw invalidModuleDescriptor("Unsupported major.minor version " + major_version + "." + minor_version); @@ -248,7 +250,7 @@ private Attributes doRead(DataInput input) throws IOException { switch (attribute_name) { case MODULE : - builder = readModuleAttribute(in, cpool, major_version); + builder = readModuleAttribute(in, cpool, major_version, isPreview); break; case MODULE_PACKAGES : @@ -344,7 +346,8 @@ private Attributes doRead(DataInput input) throws IOException { * Reads the Module attribute, returning the ModuleDescriptor.Builder to * build the corresponding ModuleDescriptor. */ - private Builder readModuleAttribute(DataInput in, ConstantPool cpool, int major) + private Builder readModuleAttribute(DataInput in, ConstantPool cpool, int major, + boolean isPreview) throws IOException { // module_name @@ -405,14 +408,23 @@ private Builder readModuleAttribute(DataInput in, ConstantPool cpool, int major) throw invalidModuleDescriptor("The requires entry for java.base" + " has ACC_SYNTHETIC set"); } + // requires transitive java.base is illegal unless: + // - the major version is 53 (JDK 9), or: + // - the classfile is a preview classfile, or: + // - the module is deemed to be participating in preview + // (i.e. the module is a java.* module) + // requires static java.base is illegal unless: + // - the major version is 53 (JDK 9), or: if (major >= 54 - && (mods.contains(Requires.Modifier.TRANSITIVE) + && ((mods.contains(Requires.Modifier.TRANSITIVE) + && !isPreview + && !"java.se".equals(mn)) || mods.contains(Requires.Modifier.STATIC))) { String flagName; - if (mods.contains(Requires.Modifier.TRANSITIVE)) { - flagName = "ACC_TRANSITIVE"; - } else { + if (mods.contains(Requires.Modifier.STATIC)) { flagName = "ACC_STATIC_PHASE"; + } else { + flagName = "ACC_TRANSITIVE"; } throw invalidModuleDescriptor("The requires entry for java.base" + " has " + flagName + " set"); diff --git a/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java b/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java index b0d9c7154cdec..bcaa8bacbaa7c 100644 --- a/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java +++ b/src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java @@ -40,13 +40,10 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.security.PrivilegedAction; -import java.util.Properties; import jdk.internal.access.JavaLangReflectAccess; import jdk.internal.access.SharedSecrets; import jdk.internal.misc.VM; import jdk.internal.vm.annotation.Stable; -import sun.security.action.GetPropertyAction; -import sun.security.util.SecurityConstants; /**

The master factory for all reflective objects, both those in java.lang.reflect (Fields, Methods, Constructors) as well as their @@ -93,27 +90,12 @@ public ReflectionFactory run() { * Provides the caller with the capability to instantiate reflective * objects. * - *

First, if there is a security manager, its - * checkPermission method is called with a {@link - * java.lang.RuntimePermission} with target - * "reflectionFactoryAccess". This may result in a - * security exception. - * *

The returned ReflectionFactory object should be * carefully guarded by the caller, since it can be used to read and * write private data and invoke private methods, as well as to load * unverified bytecodes. It must never be passed to untrusted code. - * - * @exception SecurityException if a security manager exists and its - * checkPermission method doesn't allow - * access to the RuntimePermission "reflectionFactoryAccess". */ + */ public static ReflectionFactory getReflectionFactory() { - @SuppressWarnings("removal") - SecurityManager security = System.getSecurityManager(); - if (security != null) { - security.checkPermission( - SecurityConstants.REFLECTION_FACTORY_ACCESS_PERMISSION); - } return soleInstance; } @@ -549,11 +531,10 @@ private static Config config() { private static Config loadConfig() { assert VM.isModuleSystemInited(); - Properties props = GetPropertyAction.privilegedGetProperties(); boolean useNativeAccessorOnly = - "true".equals(props.getProperty("jdk.reflect.useNativeAccessorOnly")); + "true".equals(System.getProperty("jdk.reflect.useNativeAccessorOnly")); boolean disableSerialConstructorChecks = - "true".equals(props.getProperty("jdk.disableSerialConstructorChecks")); + "true".equals(System.getProperty("jdk.disableSerialConstructorChecks")); return new Config(useNativeAccessorOnly, disableSerialConstructorChecks); } diff --git a/src/java.base/share/classes/module-info.java b/src/java.base/share/classes/module-info.java index fc5e235313c5a..828e0d415040c 100644 --- a/src/java.base/share/classes/module-info.java +++ b/src/java.base/share/classes/module-info.java @@ -146,6 +146,8 @@ jdk.compiler; exports com.sun.security.ntlm to java.security.sasl; + exports jdk.internal to + jdk.incubator.vector; // Note: all modules in the exported list participate in preview features // and therefore if they use preview features they do not need to be // compiled with "--enable-preview". @@ -154,6 +156,7 @@ exports jdk.internal.javac to java.compiler, java.desktop, // for ScopedValue + java.se, // for ParticipatesInPreview jdk.compiler, jdk.incubator.vector, // participates in preview features jdk.jartool, // participates in preview features @@ -165,7 +168,6 @@ java.desktop, java.logging, java.management, - java.naming, java.rmi, jdk.charsets, jdk.jartool, @@ -313,7 +315,6 @@ java.desktop; exports sun.reflect.misc to java.desktop, - java.datatransfer, java.management, java.management.rmi, java.rmi, diff --git a/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java b/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java index 076d04632c9fc..850da5ef83d75 100644 --- a/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java +++ b/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java @@ -311,8 +311,6 @@ public static boolean ensureTypeVisible(Class type, Class refc) { // will use the result cached in the JVM system dictionary. Note that the JVM system dictionary // will record the first successful result. Unsuccessful results are not stored. // - // We use doPrivileged in order to allow an unprivileged caller to ask an arbitrary - // class loader about the binding of the proposed name (type.getName()). // The looked up type ("res") is compared for equality against the proposed // type ("type") and then is discarded. Thus, the worst that can happen to // the "child" class loader is that it is bothered to load and report a class @@ -320,17 +318,12 @@ public static boolean ensureTypeVisible(Class type, Class refc) { // memoization. And the caller never gets to look at the alternate type binding // ("res"), whether it exists or not. final String name = type.getName(); - @SuppressWarnings("removal") - Class res = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction<>() { - public Class run() { - try { - return Class.forName(name, false, refcLoader); - } catch (ClassNotFoundException | LinkageError e) { - return null; // Assume the class is not found - } - } - }); + Class res = null; + try { + res = Class.forName(name, false, refcLoader); + } catch (ClassNotFoundException | LinkageError e) { + // Assume the class is not found + } return (type == res); } diff --git a/src/java.base/share/classes/sun/net/ftp/FtpClient.java b/src/java.base/share/classes/sun/net/ftp/FtpClient.java index da0cffd3f20e2..970d095242cea 100644 --- a/src/java.base/share/classes/sun/net/ftp/FtpClient.java +++ b/src/java.base/share/classes/sun/net/ftp/FtpClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -234,8 +234,6 @@ public static FtpClient create(String dest) throws FtpProtocolException, IOExcep * @param dest the address of the destination server * @return this FtpClient * @throws IOException if connection failed. - * @throws SecurityException if there is a SecurityManager installed and it - * denied the authorization to connect to the destination. * @throws FtpProtocolException */ public abstract FtpClient connect(SocketAddress dest) throws FtpProtocolException, IOException; @@ -247,8 +245,6 @@ public static FtpClient create(String dest) throws FtpProtocolException, IOExcep * @param timeout the value, in milliseconds, to use as a connection timeout * @return this FtpClient * @throws IOException if connection failed. - * @throws SecurityException if there is a SecurityManager installed and it - * denied the authorization to connect to the destination. * @throws FtpProtocolException */ public abstract FtpClient connect(SocketAddress dest, int timeout) throws FtpProtocolException, IOException; diff --git a/src/java.base/share/classes/sun/net/ftp/FtpClientProvider.java b/src/java.base/share/classes/sun/net/ftp/FtpClientProvider.java index ad5d092aab198..94136d85f1df1 100644 --- a/src/java.base/share/classes/sun/net/ftp/FtpClientProvider.java +++ b/src/java.base/share/classes/sun/net/ftp/FtpClientProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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,8 +24,6 @@ */ package sun.net.ftp; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ServiceConfigurationError; //import java.util.ServiceLoader; @@ -50,16 +48,8 @@ public abstract class FtpClientProvider { /** * Initializes a new instance of this class. - * - * @throws SecurityException if a security manager is installed and it denies - * {@link RuntimePermission}{@code ("ftpClientProvider")} */ protected FtpClientProvider() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("ftpClientProvider")); - } } private static boolean loadProviderFromProperty() { @@ -74,8 +64,7 @@ private static boolean loadProviderFromProperty() { return true; } catch (ClassNotFoundException | IllegalAccessException | - InstantiationException | - SecurityException x) { + InstantiationException x) { throw new ServiceConfigurationError(x.toString()); } } @@ -135,26 +124,19 @@ private static boolean loadProviderAsService() { * * @return The system-wide default FtpClientProvider */ - @SuppressWarnings("removal") public static FtpClientProvider provider() { synchronized (lock) { if (provider != null) { return provider; } - return (FtpClientProvider) AccessController.doPrivileged( - new PrivilegedAction() { - - public Object run() { - if (loadProviderFromProperty()) { - return provider; - } - if (loadProviderAsService()) { - return provider; - } - provider = new sun.net.ftp.impl.DefaultFtpClientProvider(); - return provider; - } - }); + if (loadProviderFromProperty()) { + return provider; + } + if (loadProviderAsService()) { + return provider; + } + provider = new sun.net.ftp.impl.DefaultFtpClientProvider(); + return provider; } } } diff --git a/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java b/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java index 8b6dd9c5ec7b1..bfc10028ae042 100644 --- a/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java +++ b/src/java.base/share/classes/sun/net/ftp/impl/FtpClient.java @@ -44,9 +44,6 @@ import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedExceptionAction; import java.text.DateFormat; import java.time.ZoneOffset; import java.time.ZonedDateTime; @@ -133,31 +130,17 @@ public class FtpClient extends sun.net.ftp.FtpClient { private DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, java.util.Locale.US); private static final boolean acceptPasvAddressVal; static { - final int vals[] = {0, 0}; - final String acceptPasvAddress[] = {null}; - @SuppressWarnings("removal") - final String enc = AccessController.doPrivileged( - new PrivilegedAction() { - public String run() { - acceptPasvAddress[0] = System.getProperty("jdk.net.ftp.trustPasvAddress", "false"); - vals[0] = Integer.getInteger("sun.net.client.defaultReadTimeout", 300_000).intValue(); - vals[1] = Integer.getInteger("sun.net.client.defaultConnectTimeout", 300_000).intValue(); - return System.getProperty("file.encoding", "ISO8859_1"); - } - }); - if (vals[0] == 0) { + defaultSoTimeout = Integer.getInteger("sun.net.client.defaultReadTimeout", 300_000).intValue(); + if (defaultSoTimeout == 0) { defaultSoTimeout = -1; - } else { - defaultSoTimeout = vals[0]; } - if (vals[1] == 0) { + defaultConnectTimeout = Integer.getInteger("sun.net.client.defaultConnectTimeout", 300_000).intValue(); + if (defaultConnectTimeout == 0) { defaultConnectTimeout = -1; - } else { - defaultConnectTimeout = vals[1]; } - encoding = enc; + encoding = System.getProperty("file.encoding", "ISO8859_1"); try { if (!isASCIISuperset(encoding)) { encoding = "ISO8859_1"; @@ -171,7 +154,7 @@ public String run() { patterns[i] = Pattern.compile(patStrings[i]); } - acceptPasvAddressVal = Boolean.parseBoolean(acceptPasvAddress[0]); + acceptPasvAddressVal = Boolean.getBoolean("jdk.net.ftp.trustPasvAddress"); } /** @@ -662,10 +645,7 @@ private Socket openPassiveDataConnection(String cmd) throws sun.net.ftp.FtpProto Socket s; if (proxy != null) { if (proxy.type() == Proxy.Type.SOCKS) { - PrivilegedAction pa = () -> new Socket(proxy); - @SuppressWarnings("removal") - var tmp = AccessController.doPrivileged(pa); - s = tmp; + s = new Socket(proxy); } else { s = new Socket(Proxy.NO_PROXY); } @@ -673,9 +653,7 @@ private Socket openPassiveDataConnection(String cmd) throws sun.net.ftp.FtpProto s = new Socket(); } - PrivilegedAction pa = () -> server.getLocalAddress(); - @SuppressWarnings("removal") - InetAddress serverAddress = AccessController.doPrivileged(pa); + InetAddress serverAddress = server.getLocalAddress(); // Bind the socket to the same address as the control channel. This // is needed in case of multi-homed systems. @@ -761,11 +739,8 @@ private InetSocketAddress validatePasvAddress(int port, String s, InetAddress ad } private static InetAddress privilegedLocalHost() throws FtpProtocolException { - PrivilegedExceptionAction action = InetAddress::getLocalHost; try { - @SuppressWarnings("removal") - var tmp = AccessController.doPrivileged(action); - return tmp; + return InetAddress.getLocalHost(); } catch (Exception e) { var ftpEx = new FtpProtocolException(ERROR_MSG); ftpEx.initCause(e); @@ -774,11 +749,8 @@ private static InetAddress privilegedLocalHost() throws FtpProtocolException { } private static InetAddress[] privilegedGetAllByName(String hostName) throws FtpProtocolException { - PrivilegedExceptionAction pAction = () -> InetAddress.getAllByName(hostName); try { - @SuppressWarnings("removal") - var tmp =AccessController.doPrivileged(pAction); - return tmp; + return InetAddress.getAllByName(hostName); } catch (Exception e) { var ftpEx = new FtpProtocolException(ERROR_MSG); ftpEx.initCause(e); @@ -1021,10 +993,7 @@ private Socket doConnect(InetSocketAddress dest, int timeout) throws IOException Socket s; if (proxy != null) { if (proxy.type() == Proxy.Type.SOCKS) { - PrivilegedAction pa = () -> new Socket(proxy); - @SuppressWarnings("removal") - var tmp = AccessController.doPrivileged(pa); - s = tmp; + s = new Socket(proxy); } else { s = new Socket(Proxy.NO_PROXY); } diff --git a/src/java.base/share/classes/sun/net/www/protocol/jar/JarFileFactory.java b/src/java.base/share/classes/sun/net/www/protocol/jar/JarFileFactory.java index 17ca43d4ace9f..9afbea8bf76e8 100644 --- a/src/java.base/share/classes/sun/net/www/protocol/jar/JarFileFactory.java +++ b/src/java.base/share/classes/sun/net/www/protocol/jar/JarFileFactory.java @@ -31,7 +31,6 @@ import java.net.URLConnection; import java.util.HashMap; import java.util.jar.JarFile; -import java.security.Permission; import jdk.internal.util.OperatingSystem; import sun.net.util.URLUtil; @@ -219,35 +218,7 @@ public void close(JarFile jarFile) { private JarFile getCachedJarFile(URL url) { assert Thread.holdsLock(instance); - JarFile result = fileCache.get(urlKey(url)); - - /* if the JAR file is cached, the permission will always be there */ - if (result != null) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - Permission perm = getPermission(result); - if (perm != null) { - try { - sm.checkPermission(perm); - } catch (SecurityException se) { - // fallback to checkRead/checkConnect for pre 1.2 - // security managers - if ((perm instanceof java.io.FilePermission) && - perm.getActions().contains("read")) { - sm.checkRead(perm.getName()); - } else if ((perm instanceof - java.net.SocketPermission) && - perm.getActions().contains("connect")) { - sm.checkConnect(url.getHost(), url.getPort()); - } else { - throw se; - } - } - } - } - } - return result; + return fileCache.get(urlKey(url)); } private String urlKey(URL url) { @@ -255,16 +226,4 @@ private String urlKey(URL url) { if ("runtime".equals(url.getRef())) urlstr += "#runtime"; return urlstr; } - - private Permission getPermission(JarFile jarFile) { - try { - URLConnection uc = getConnection(jarFile); - if (uc != null) - return uc.getPermission(); - } catch (IOException ioe) { - // gulp - } - - return null; - } } diff --git a/src/java.base/share/classes/sun/nio/cs/StreamDecoder.java b/src/java.base/share/classes/sun/nio/cs/StreamDecoder.java index a2026744f04b5..124e41b77c9f7 100644 --- a/src/java.base/share/classes/sun/nio/cs/StreamDecoder.java +++ b/src/java.base/share/classes/sun/nio/cs/StreamDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -44,8 +44,6 @@ import java.nio.charset.UnsupportedCharsetException; import java.util.Arrays; -import jdk.internal.misc.InternalLock; - public class StreamDecoder extends Reader { private static final int MIN_BYTE_BUFFER_SIZE = 32; @@ -121,178 +119,109 @@ public int read() throws IOException { return read0(); } + @SuppressWarnings("fallthrough") private int read0() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return lockedRead0(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - return lockedRead0(); + synchronized (lock) { + // Return the leftover char, if there is one + if (haveLeftoverChar) { + haveLeftoverChar = false; + return leftoverChar; } - } - } - - @SuppressWarnings("fallthrough") - private int lockedRead0() throws IOException { - // Return the leftover char, if there is one - if (haveLeftoverChar) { - haveLeftoverChar = false; - return leftoverChar; - } - // Convert more bytes - char[] cb = new char[2]; - int n = read(cb, 0, 2); - switch (n) { - case -1: - return -1; - case 2: - leftoverChar = cb[1]; - haveLeftoverChar = true; - // FALL THROUGH - case 1: - return cb[0]; - default: - assert false : n; - return -1; + // Convert more bytes + char[] cb = new char[2]; + int n = read(cb, 0, 2); + switch (n) { + case -1: + return -1; + case 2: + leftoverChar = cb[1]; + haveLeftoverChar = true; + // FALL THROUGH + case 1: + return cb[0]; + default: + assert false : n; + return -1; + } } } public int read(char[] cbuf, int offset, int length) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return lockedRead(cbuf, offset, length); - } finally { - locker.unlock(); + synchronized (lock) { + int off = offset; + int len = length; + + ensureOpen(); + if ((off < 0) || (off > cbuf.length) || (len < 0) || + ((off + len) > cbuf.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); } - } else { - synchronized (lock) { - return lockedRead(cbuf, offset, length); + if (len == 0) + return 0; + + int n = 0; + + if (haveLeftoverChar) { + // Copy the leftover char into the buffer + cbuf[off] = leftoverChar; + off++; len--; + haveLeftoverChar = false; + n = 1; + if ((len == 0) || !implReady()) + // Return now if this is all we can produce w/o blocking + return n; } - } - } - private int lockedRead(char[] cbuf, int offset, int length) throws IOException { - int off = offset; - int len = length; + if (len == 1) { + // Treat single-character array reads just like read() + int c = read0(); + if (c == -1) + return (n == 0) ? -1 : n; + cbuf[off] = (char)c; + return n + 1; + } - ensureOpen(); - if ((off < 0) || (off > cbuf.length) || (len < 0) || - ((off + len) > cbuf.length) || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } - if (len == 0) - return 0; - - int n = 0; - - if (haveLeftoverChar) { - // Copy the leftover char into the buffer - cbuf[off] = leftoverChar; - off++; len--; - haveLeftoverChar = false; - n = 1; - if ((len == 0) || !implReady()) - // Return now if this is all we can produce w/o blocking - return n; - } + // Read remaining characters + int nr = implRead(cbuf, off, off + len); - if (len == 1) { - // Treat single-character array reads just like read() - int c = read0(); - if (c == -1) - return (n == 0) ? -1 : n; - cbuf[off] = (char)c; - return n + 1; + // At this point, n is either 1 if a leftover character was read, + // or 0 if no leftover character was read. If n is 1 and nr is -1, + // indicating EOF, then we don't return their sum as this loses data. + return (nr < 0) ? (n == 1 ? 1 : nr) : (n + nr); } - - // Read remaining characters - int nr = implRead(cbuf, off, off + len); - - // At this point, n is either 1 if a leftover character was read, - // or 0 if no leftover character was read. If n is 1 and nr is -1, - // indicating EOF, then we don't return their sum as this loses data. - return (nr < 0) ? (n == 1 ? 1 : nr) : (n + nr); } public boolean ready() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - return lockedReady(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - return lockedReady(); - } + synchronized (lock) { + ensureOpen(); + return haveLeftoverChar || implReady(); } } - private boolean lockedReady() throws IOException { - ensureOpen(); - return haveLeftoverChar || implReady(); - } - public void close() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { + if (closed) + return; try { - lockedClose(); + implClose(); } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - lockedClose(); + closed = true; } } } - private void lockedClose() throws IOException { - if (closed) - return; - try { - implClose(); - } finally { - closed = true; - } - } - private boolean isOpen() { return !closed; } public void fillZeroToPosition() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - lockedFillZeroToPosition(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - lockedFillZeroToPosition(); - } + synchronized (lock) { + Arrays.fill(bb.array(), bb.arrayOffset(), + bb.arrayOffset() + bb.position(), (byte)0); } } - private void lockedFillZeroToPosition() { - Arrays.fill(bb.array(), bb.arrayOffset(), bb.arrayOffset() + bb.position(), (byte)0); - } - // -- Charset-based stream decoder impl -- private final Charset cs; diff --git a/src/java.base/share/classes/sun/nio/cs/StreamEncoder.java b/src/java.base/share/classes/sun/nio/cs/StreamEncoder.java index 3a82030121abc..b580ad2f92157 100644 --- a/src/java.base/share/classes/sun/nio/cs/StreamEncoder.java +++ b/src/java.base/share/classes/sun/nio/cs/StreamEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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,6 @@ import java.nio.charset.CodingErrorAction; import java.nio.charset.IllegalCharsetNameException; import java.nio.charset.UnsupportedCharsetException; -import jdk.internal.misc.InternalLock; public final class StreamEncoder extends Writer { @@ -97,28 +96,14 @@ public String getEncoding() { } public void flushBuffer() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - lockedFlushBuffer(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - lockedFlushBuffer(); - } + synchronized (lock) { + if (isOpen()) + implFlushBuffer(); + else + throw new IOException("Stream closed"); } } - private void lockedFlushBuffer() throws IOException { - if (isOpen()) - implFlushBuffer(); - else - throw new IOException("Stream closed"); - } - public void write(int c) throws IOException { char[] cbuf = new char[1]; cbuf[0] = (char) c; @@ -126,30 +111,16 @@ public void write(int c) throws IOException { } public void write(char[] cbuf, int off, int len) throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - lockedWrite(cbuf, off, len); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - lockedWrite(cbuf, off, len); - } - } - } - - private void lockedWrite(char[] cbuf, int off, int len) throws IOException { - ensureOpen(); - if ((off < 0) || (off > cbuf.length) || (len < 0) || + synchronized (lock) { + ensureOpen(); + if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { - return; + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return; + } + implWrite(cbuf, off, len); } - implWrite(cbuf, off, len); } public void write(String str, int off, int len) throws IOException { @@ -164,76 +135,34 @@ public void write(String str, int off, int len) throws IOException { public void write(CharBuffer cb) throws IOException { int position = cb.position(); try { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - lockedWrite(cb); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - lockedWrite(cb); - } + synchronized (lock) { + ensureOpen(); + implWrite(cb); } } finally { cb.position(position); } } - private void lockedWrite(CharBuffer cb) throws IOException { - ensureOpen(); - implWrite(cb); - } - public void flush() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); - try { - lockedFlush(); - } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - lockedFlush(); - } + synchronized (lock) { + ensureOpen(); + implFlush(); } } - private void lockedFlush() throws IOException { - ensureOpen(); - implFlush(); - } - public void close() throws IOException { - Object lock = this.lock; - if (lock instanceof InternalLock locker) { - locker.lock(); + synchronized (lock) { + if (closed) + return; try { - lockedClose(); + implClose(); } finally { - locker.unlock(); - } - } else { - synchronized (lock) { - lockedClose(); + closed = true; } } } - private void lockedClose() throws IOException { - if (closed) - return; - try { - implClose(); - } finally { - closed = true; - } - } - private boolean isOpen() { return !closed; } diff --git a/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java b/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java index 540a9d6411027..86eadc2b2eea1 100644 --- a/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java +++ b/src/java.base/share/classes/sun/reflect/misc/ReflectUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024, 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,6 @@ * questions. */ - package sun.reflect.misc; import java.lang.reflect.Member; @@ -31,16 +30,13 @@ import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; import jdk.internal.reflect.Reflection; -import sun.security.util.SecurityConstants; public final class ReflectUtil { private ReflectUtil() { } - public static Class forName(String name) - throws ClassNotFoundException { - checkPackageAccess(name); + public static Class forName(String name) throws ClassNotFoundException { return Class.forName(name); } @@ -73,182 +69,48 @@ public static void ensureMemberAccess(Class currentClass, } /** - * Does a conservative approximation of member access check. Use this if - * you don't have an actual 'userland' caller Class/ClassLoader available. - * This might be more restrictive than a precise member access check where - * you have a caller, but should never allow a member access that is - * forbidden. - * - * @param m the {@code Member} about to be accessed + * Does nothing. */ - public static void conservativeCheckMemberAccess(Member m) throws SecurityException{ - @SuppressWarnings("removal") - final SecurityManager sm = System.getSecurityManager(); - if (sm == null) - return; - - // Check for package access on the declaring class. - // - // In addition, unless the member and the declaring class are both - // public check for access declared member permissions. - // - // This is done regardless of ClassLoader relations between the {@code - // Member m} and any potential caller. - - final Class declaringClass = m.getDeclaringClass(); - - privateCheckPackageAccess(sm, declaringClass); - - if (Modifier.isPublic(m.getModifiers()) && - Modifier.isPublic(declaringClass.getModifiers())) - return; - - // Check for declared member access. - sm.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); + public static void conservativeCheckMemberAccess(Member m) { } /** - * Checks package access on the given class. - * - * If it is a {@link Proxy#isProxyClass(java.lang.Class)} that implements - * a non-public interface (i.e. may be in a non-restricted package), - * also check the package access on the proxy interfaces. + * Does nothing. */ public static void checkPackageAccess(Class clazz) { - @SuppressWarnings("removal") - SecurityManager s = System.getSecurityManager(); - if (s != null) { - privateCheckPackageAccess(s, clazz); - } } /** - * NOTE: should only be called if a SecurityManager is installed + * Does nothing */ - private static void privateCheckPackageAccess(@SuppressWarnings("removal") SecurityManager s, Class clazz) { - String pkg = clazz.getPackageName(); - if (!pkg.isEmpty()) { - s.checkPackageAccess(pkg); - } - - if (isNonPublicProxyClass(clazz)) { - privateCheckProxyPackageAccess(s, clazz); - } + public static void checkPackageAccess(String name) { } /** - * Checks package access on the given classname. - * This method is typically called when the Class instance is not - * available and the caller attempts to load a class on behalf - * the true caller (application). + * Returns true. */ - public static void checkPackageAccess(String name) { - @SuppressWarnings("removal") - SecurityManager s = System.getSecurityManager(); - if (s != null) { - String cname = name.replace('/', '.'); - if (cname.startsWith("[")) { - int b = cname.lastIndexOf('[') + 2; - if (b > 1 && b < cname.length()) { - cname = cname.substring(b); - } - } - int i = cname.lastIndexOf('.'); - if (i != -1) { - s.checkPackageAccess(cname.substring(0, i)); - } - } - } - public static boolean isPackageAccessible(Class clazz) { - try { - checkPackageAccess(clazz); - } catch (SecurityException e) { - return false; - } return true; } - // Returns true if p is an ancestor of cl i.e. class loader 'p' can - // be found in the cl's delegation chain - private static boolean isAncestor(ClassLoader p, ClassLoader cl) { - ClassLoader acl = cl; - do { - acl = acl.getParent(); - if (p == acl) { - return true; - } - } while (acl != null); - return false; - } - /** - * Returns true if package access check is needed for reflective - * access from a class loader 'from' to classes or members in - * a class defined by class loader 'to'. This method returns true - * if 'from' is not the same as or an ancestor of 'to'. All code - * in a system domain are granted with all permission and so this - * method returns false if 'from' class loader is a class loader - * loading system classes. On the other hand, if a class loader - * attempts to access system domain classes, it requires package - * access check and this method will return true. + * Returns false. */ public static boolean needsPackageAccessCheck(ClassLoader from, ClassLoader to) { - if (from == null || from == to) - return false; - - if (to == null) - return true; - - return !isAncestor(from, to); + return false; } /** - * Check package access on the proxy interfaces that the given proxy class - * implements. - * - * @param clazz Proxy class object + * Does nothing */ public static void checkProxyPackageAccess(Class clazz) { - @SuppressWarnings("removal") - SecurityManager s = System.getSecurityManager(); - if (s != null) { - privateCheckProxyPackageAccess(s, clazz); - } } /** - * NOTE: should only be called if a SecurityManager is installed - */ - private static void privateCheckProxyPackageAccess(@SuppressWarnings("removal") SecurityManager s, Class clazz) { - // check proxy interfaces if the given class is a proxy class - if (Proxy.isProxyClass(clazz)) { - for (Class intf : clazz.getInterfaces()) { - privateCheckPackageAccess(s, intf); - } - } - } - /** - * Access check on the interfaces that a proxy class implements and throw - * {@code SecurityException} if it accesses a restricted package from - * the caller's class loader. - * - * @param ccl the caller's class loader - * @param interfaces the list of interfaces that a proxy class implements + * Does nothing. */ public static void checkProxyPackageAccess(ClassLoader ccl, - Class... interfaces) - { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - for (Class intf : interfaces) { - ClassLoader cl = intf.getClassLoader(); - if (needsPackageAccessCheck(ccl, cl)) { - privateCheckPackageAccess(sm, intf); - } - } - } + Class... interfaces) { } // Note that bytecode instrumentation tools may exclude 'sun.*' diff --git a/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java b/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java index bc463d01faf3a..7612242733eeb 100644 --- a/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java +++ b/src/java.base/share/classes/sun/security/util/DisabledAlgorithmConstraints.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024, 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 @@ -42,21 +42,21 @@ import java.security.spec.PSSParameterSpec; import java.time.DateTimeException; import java.time.Instant; -import java.time.ZonedDateTime; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.Collection; import java.util.StringTokenizer; import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Pattern; import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Algorithm constraints for disabled algorithms property @@ -101,6 +101,7 @@ private static class JarHolder { } private final Set disabledAlgorithms; + private final List disabledPatterns; private final Constraints algorithmConstraints; private volatile SoftReference> cacheRef = new SoftReference<>(null); @@ -136,6 +137,13 @@ public DisabledAlgorithmConstraints(String propertyName, super(decomposer); disabledAlgorithms = getAlgorithms(propertyName); + // Support patterns only for jdk.tls.disabledAlgorithms + if (PROPERTY_TLS_DISABLED_ALGS.equals(propertyName)) { + disabledPatterns = getDisabledPatterns(); + } else { + disabledPatterns = null; + } + // Check for alias for (String s : disabledAlgorithms) { Matcher matcher = INCLUDE_PATTERN.matcher(s); @@ -967,11 +975,48 @@ private boolean cachedCheckAlgorithm(String algorithm) { if (result != null) { return result; } - result = checkAlgorithm(disabledAlgorithms, algorithm, decomposer); + // We won't check patterns if algorithm check fails. + result = checkAlgorithm(disabledAlgorithms, algorithm, decomposer) + && checkDisabledPatterns(algorithm); cache.put(algorithm, result); return result; } + private boolean checkDisabledPatterns(final String algorithm) { + return disabledPatterns == null || disabledPatterns.stream().noneMatch( + p -> p.matcher(algorithm).matches()); + } + + private List getDisabledPatterns() { + List ret = null; + List patternStrings = new ArrayList<>(4); + + for (String p : disabledAlgorithms) { + if (p.contains("*")) { + if (!p.startsWith("TLS_")) { + throw new IllegalArgumentException( + "Wildcard pattern must start with \"TLS_\""); + } + patternStrings.add(p); + } + } + + if (!patternStrings.isEmpty()) { + ret = new ArrayList<>(patternStrings.size()); + + for (String p : patternStrings) { + // Exclude patterns from algorithm code flow. + disabledAlgorithms.remove(p); + + // Ignore all regex characters but asterisk. + ret.add(Pattern.compile( + "^\\Q" + p.replace("*", "\\E.*\\Q") + "\\E$")); + } + } + + return ret; + } + /* * This constraint is used for the complete disabling of the algorithm. */ diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security index 1d329df0cfb02..6374c1951bd02 100644 --- a/src/java.base/share/conf/security/java.security +++ b/src/java.base/share/conf/security/java.security @@ -729,7 +729,11 @@ http.auth.digest.disabledAlgorithms = MD5, SHA-1 # This is in addition to the jdk.certpath.disabledAlgorithms property above. # # See the specification of "jdk.certpath.disabledAlgorithms" for the -# syntax of the disabled algorithm string. +# syntax of the disabled algorithm string. Additionally, TLS cipher suites +# can be disabled with this property using one or more "*" wildcard characters. +# For example, "TLS_RSA_*" disables all cipher suites that start with +# "TLS_RSA_". Only cipher suites starting with "TLS_" are allowed to have +# wildcard characters. # # Note: The algorithm restrictions do not apply to trust anchors or # self-signed certificates. @@ -739,7 +743,7 @@ http.auth.digest.disabledAlgorithms = MD5, SHA-1 # # Example: # jdk.tls.disabledAlgorithms=MD5, SSLv3, DSA, RSA keySize < 2048, \ -# rsa_pkcs1_sha1, secp224r1 +# rsa_pkcs1_sha1, secp224r1, TLS_RSA_* jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, DTLSv1.0, RC4, DES, \ MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \ ECDH diff --git a/src/java.base/unix/classes/java/lang/ProcessImpl.java b/src/java.base/unix/classes/java/lang/ProcessImpl.java index da4874b01817c..7b5d27f1cc161 100644 --- a/src/java.base/unix/classes/java/lang/ProcessImpl.java +++ b/src/java.base/unix/classes/java/lang/ProcessImpl.java @@ -42,14 +42,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import jdk.internal.access.JavaIOFileDescriptorAccess; import jdk.internal.access.SharedSecrets; import jdk.internal.util.OperatingSystem; import jdk.internal.util.StaticProperty; -import sun.security.action.GetPropertyAction; /** * java.lang.Process subclass in the UNIX environment. @@ -95,7 +91,7 @@ private static enum LaunchMechanism { * @throws Error if the requested launch mechanism is not found or valid */ private static LaunchMechanism launchMechanism() { - String s = GetPropertyAction.privilegedGetProperty("jdk.lang.Process.launchMechanism"); + String s = System.getProperty("jdk.lang.Process.launchMechanism"); if (s == null) { return LaunchMechanism.POSIX_SPAWN; } @@ -282,7 +278,6 @@ private native int forkAndExec(int mode, byte[] helperpath, boolean redirectErrorStream) throws IOException; - @SuppressWarnings("removal") private ProcessImpl(final byte[] prog, final byte[] argBlock, final int argc, final byte[] envBlock, final int envc, @@ -302,14 +297,7 @@ private ProcessImpl(final byte[] prog, redirectErrorStream); processHandle = ProcessHandleImpl.getInternal(pid); - try { - AccessController.doPrivileged((PrivilegedExceptionAction) () -> { - initStreams(fds, forceNullOutputStream); - return null; - }); - } catch (PrivilegedActionException ex) { - throw (IOException) ex.getCause(); - } + initStreams(fds, forceNullOutputStream); } static FileDescriptor newFileDescriptor(int fd) { @@ -507,11 +495,6 @@ public CompletableFuture onExit() { @Override public ProcessHandle toHandle() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("manageProcess")); - } return processHandle; } diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixFileAttributeViews.java b/src/java.base/unix/classes/sun/nio/fs/UnixFileAttributeViews.java index 033deee2f4fda..4ba1d2b87748b 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixFileAttributeViews.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixFileAttributeViews.java @@ -72,42 +72,25 @@ public void setTimes(FileTime lastModifiedTime, // permission check file.checkWrite(); - boolean haveFd = false; - boolean useFutimes = false; - boolean useFutimens = false; - boolean useLutimes = false; - boolean useUtimensat = false; + // use a file descriptor if possible to avoid a race due to + // accessing a path more than once as the file at that path could + // change. + // if path is a symlink, then the open should fail with ELOOP and + // the path will be used instead of the file descriptor. int fd = -1; try { - if (!followLinks) { - // these path-based syscalls also work if following links - if (!(useUtimensat = utimensatSupported())) { - useLutimes = lutimesSupported(); - } - } - if (!useUtimensat && !useLutimes) { - fd = file.openForAttributeAccess(followLinks); - if (fd != -1) { - haveFd = true; - if (!(useFutimens = futimensSupported())) { - useFutimes = futimesSupported(); - } - } - } + fd = file.openForAttributeAccess(followLinks); } catch (UnixException x) { - if (!(x.errno() == ENXIO || - (x.errno() == ELOOP && (useUtimensat || useLutimes)))) { + if (!(x.errno() == ENXIO || (x.errno() == ELOOP))) { x.rethrowAsIOException(file); } } try { - // assert followLinks || !UnixFileAttributes.get(fd).isSymbolicLink(); - // if not changing both attributes then need existing attributes if (lastModifiedTime == null || lastAccessTime == null) { try { - UnixFileAttributes attrs = haveFd ? + UnixFileAttributes attrs = fd >= 0 ? UnixFileAttributes.get(fd) : UnixFileAttributes.get(file, followLinks); if (lastModifiedTime == null) @@ -120,28 +103,20 @@ public void setTimes(FileTime lastModifiedTime, } // update times - TimeUnit timeUnit = (useFutimens || useUtimensat) ? - TimeUnit.NANOSECONDS : TimeUnit.MICROSECONDS; - long modValue = lastModifiedTime.to(timeUnit); - long accessValue= lastAccessTime.to(timeUnit); + long modValue = lastModifiedTime.to(TimeUnit.NANOSECONDS); + long accessValue= lastAccessTime.to(TimeUnit.NANOSECONDS); boolean retry = false; try { - if (useFutimens) { + if (fd >= 0) futimens(fd, accessValue, modValue); - } else if (useFutimes) { - futimes(fd, accessValue, modValue); - } else if (useLutimes) { - lutimes(file, accessValue, modValue); - } else if (useUtimensat) { + else utimensat(AT_FDCWD, file, accessValue, modValue, followLinks ? 0 : AT_SYMLINK_NOFOLLOW); - } else { - utimes(file, accessValue, modValue); - } } catch (UnixException x) { - // if futimes/utimes fails with EINVAL and one/both of the times is - // negative then we adjust the value to the epoch and retry. + // if utimensat fails with EINVAL and one/both of + // the times is negative then we adjust the value to the + // epoch and retry. if (x.errno() == EINVAL && (modValue < 0L || accessValue < 0L)) { retry = true; @@ -153,18 +128,11 @@ public void setTimes(FileTime lastModifiedTime, if (modValue < 0L) modValue = 0L; if (accessValue < 0L) accessValue= 0L; try { - if (useFutimens) { + if (fd >= 0) futimens(fd, accessValue, modValue); - } else if (useFutimes) { - futimes(fd, accessValue, modValue); - } else if (useLutimes) { - lutimes(file, accessValue, modValue); - } else if (useUtimensat) { + else utimensat(AT_FDCWD, file, accessValue, modValue, followLinks ? 0 : AT_SYMLINK_NOFOLLOW); - } else { - utimes(file, accessValue, modValue); - } } catch (UnixException x) { x.rethrowAsIOException(file); } diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java b/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java index 2b9ab775ed815..56a7624e436d4 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java @@ -577,14 +577,14 @@ private void copyDirectory(UnixPath source, // copy time stamps last if (flags.copyBasicAttributes) { try { - if (dfd >= 0 && futimesSupported()) { - futimes(dfd, - attrs.lastAccessTime().to(TimeUnit.MICROSECONDS), - attrs.lastModifiedTime().to(TimeUnit.MICROSECONDS)); + if (dfd >= 0) { + futimens(dfd, + attrs.lastAccessTime().to(TimeUnit.NANOSECONDS), + attrs.lastModifiedTime().to(TimeUnit.NANOSECONDS)); } else { - utimes(target, - attrs.lastAccessTime().to(TimeUnit.MICROSECONDS), - attrs.lastModifiedTime().to(TimeUnit.MICROSECONDS)); + utimensat(AT_FDCWD, target, + attrs.lastAccessTime().to(TimeUnit.NANOSECONDS), + attrs.lastModifiedTime().to(TimeUnit.NANOSECONDS), 0); } } catch (UnixException x) { // unable to set times @@ -727,15 +727,9 @@ void copyFile(UnixPath source, // copy time attributes if (flags.copyBasicAttributes) { try { - if (futimesSupported()) { - futimes(fo, - attrs.lastAccessTime().to(TimeUnit.MICROSECONDS), - attrs.lastModifiedTime().to(TimeUnit.MICROSECONDS)); - } else { - utimes(target, - attrs.lastAccessTime().to(TimeUnit.MICROSECONDS), - attrs.lastModifiedTime().to(TimeUnit.MICROSECONDS)); - } + futimens(fo, + attrs.lastAccessTime().to(TimeUnit.NANOSECONDS), + attrs.lastModifiedTime().to(TimeUnit.NANOSECONDS)); } catch (UnixException x) { if (flags.failIfUnableToCopyBasic) x.rethrowAsIOException(target); @@ -814,9 +808,10 @@ private void copySpecial(UnixPath source, } if (flags.copyBasicAttributes) { try { - utimes(target, - attrs.lastAccessTime().to(TimeUnit.MICROSECONDS), - attrs.lastModifiedTime().to(TimeUnit.MICROSECONDS)); + utimensat(AT_FDCWD, target, + attrs.lastAccessTime().to(TimeUnit.NANOSECONDS), + attrs.lastModifiedTime().to(TimeUnit.NANOSECONDS), + 0); } catch (UnixException x) { if (flags.failIfUnableToCopyBasic) x.rethrowAsIOException(target); diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java b/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java index d6d2b9fdcd719..046f843371d36 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixNativeDispatcher.java @@ -347,28 +347,6 @@ static void fchmod(int fd, int mode) throws UnixException { } private static native void fchmod0(int fd, int mode) throws UnixException; - /** - * utimes(const char* path, const struct timeval times[2]) - */ - static void utimes(UnixPath path, long times0, long times1) - throws UnixException - { - try (NativeBuffer buffer = copyToNativeBuffer(path)) { - utimes0(buffer.address(), times0, times1); - } - } - private static native void utimes0(long pathAddress, long times0, long times1) - throws UnixException; - - /** - * futimes(int fildes, const struct timeval times[2]) - */ - static void futimes(int fd, long times0, long times1) throws UnixException { - futimes0(fd, times0, times1); - } - private static native void futimes0(int fd, long times0, long times1) - throws UnixException; - /** * futimens(int fildes, const struct timespec times[2]) */ @@ -378,19 +356,6 @@ static void futimens(int fd, long times0, long times1) throws UnixException { private static native void futimens0(int fd, long times0, long times1) throws UnixException; - /** - * lutimes(const char* path, const struct timeval times[2]) - */ - static void lutimes(UnixPath path, long times0, long times1) - throws UnixException - { - try (NativeBuffer buffer = copyToNativeBuffer(path)) { - lutimes0(buffer.address(), times0, times1); - } - } - private static native void lutimes0(long pathAddress, long times0, long times1) - throws UnixException; - /** * utimensat(int fd, const char* path, * const struct timeval times[2], int flags) @@ -568,11 +533,7 @@ static native int flistxattr(int filedes, long listAddress, int size) * Capabilities */ private static final int SUPPORTS_OPENAT = 1 << 1; // syscalls - private static final int SUPPORTS_FUTIMES = 1 << 2; - private static final int SUPPORTS_FUTIMENS = 1 << 3; - private static final int SUPPORTS_LUTIMES = 1 << 4; - private static final int SUPPORTS_UTIMENSAT = 1 << 5; - private static final int SUPPORTS_XATTR = 1 << 6; + private static final int SUPPORTS_XATTR = 1 << 3; private static final int SUPPORTS_BIRTHTIME = 1 << 16; // other features private static final int capabilities; @@ -583,34 +544,6 @@ static boolean openatSupported() { return (capabilities & SUPPORTS_OPENAT) != 0; } - /** - * Supports futimes - */ - static boolean futimesSupported() { - return (capabilities & SUPPORTS_FUTIMES) != 0; - } - - /** - * Supports futimens - */ - static boolean futimensSupported() { - return (capabilities & SUPPORTS_FUTIMENS) != 0; - } - - /** - * Supports lutimes - */ - static boolean lutimesSupported() { - return (capabilities & SUPPORTS_LUTIMES) != 0; - } - - /** - * Supports utimensat - */ - static boolean utimensatSupported() { - return (capabilities & SUPPORTS_UTIMENSAT) != 0; - } - /** * Supports file birth (creation) time attribute */ diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixSecureDirectoryStream.java b/src/java.base/unix/classes/sun/nio/fs/UnixSecureDirectoryStream.java index bedf847c6e71b..9497ca3644e85 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixSecureDirectoryStream.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixSecureDirectoryStream.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -415,9 +415,9 @@ public void setTimes(FileTime lastModifiedTime, } // update times try { - futimes(fd, - lastAccessTime.to(TimeUnit.MICROSECONDS), - lastModifiedTime.to(TimeUnit.MICROSECONDS)); + futimens(fd, + lastAccessTime.to(TimeUnit.NANOSECONDS), + lastModifiedTime.to(TimeUnit.NANOSECONDS)); } catch (UnixException x) { x.rethrowAsIOException(file); } diff --git a/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java b/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java index 41528a55e3767..e814dde3229f3 100644 --- a/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java +++ b/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -194,7 +194,7 @@ public int read(String name, ByteBuffer dst) throws IOException { int n = read(name, address, rem); // copy from buffer into backing array - int off = dst.arrayOffset() + pos + Unsafe.ARRAY_BYTE_BASE_OFFSET; + long off = dst.arrayOffset() + pos + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET; unsafe.copyMemory(null, address, dst.array(), off, n); dst.position(pos + n); @@ -257,7 +257,7 @@ public int write(String name, ByteBuffer src) throws IOException { if (src.hasArray()) { // copy from backing array into buffer - int off = src.arrayOffset() + pos + Unsafe.ARRAY_BYTE_BASE_OFFSET; + long off = src.arrayOffset() + pos + (long) Unsafe.ARRAY_BYTE_BASE_OFFSET; unsafe.copyMemory(src.array(), off, null, address, rem); } else { // backing array not accessible so transfer via temporary array diff --git a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c index aa46a2470a104..1a616446b4abc 100644 --- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c +++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c @@ -204,28 +204,19 @@ typedef int openat_func(int, const char *, int, ...); typedef int fstatat_func(int, const char *, struct stat *, int); typedef int unlinkat_func(int, const char*, int); typedef int renameat_func(int, const char*, int, const char*); -typedef int futimes_func(int, const struct timeval *); -typedef int futimens_func(int, const struct timespec *); -typedef int lutimes_func(const char *, const struct timeval *); typedef DIR* fdopendir_func(int); #if defined(__linux__) typedef int statx_func(int dirfd, const char *restrict pathname, int flags, unsigned int mask, struct my_statx *restrict statxbuf); -typedef int utimensat_func(int dirfd, const char *pathname, - const struct timespec[2], int flags); #endif static openat_func* my_openat_func = NULL; static fstatat_func* my_fstatat_func = NULL; static unlinkat_func* my_unlinkat_func = NULL; static renameat_func* my_renameat_func = NULL; -static futimes_func* my_futimes_func = NULL; -static futimens_func* my_futimens_func = NULL; -static lutimes_func* my_lutimes_func = NULL; static fdopendir_func* my_fdopendir_func = NULL; #if defined(__linux__) static statx_func* my_statx_func = NULL; -static utimensat_func* my_utimensat_func = NULL; #endif /** @@ -375,18 +366,6 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this) #endif my_unlinkat_func = (unlinkat_func*) dlsym(RTLD_DEFAULT, "unlinkat"); my_renameat_func = (renameat_func*) dlsym(RTLD_DEFAULT, "renameat"); -#if defined(__linux__) && defined(__arm__) - my_futimes_func = (futimes_func*) lookup_time_t_function("futimes", - "__futimes64"); - my_lutimes_func = (lutimes_func*) lookup_time_t_function("lutimes", - "__lutimes64"); - my_futimens_func = (futimens_func*) lookup_time_t_function("futimens", - "__futimens64"); -#else - my_futimes_func = (futimes_func*) dlsym(RTLD_DEFAULT, "futimes"); - my_lutimes_func = (lutimes_func*) dlsym(RTLD_DEFAULT, "lutimes"); - my_futimens_func = (futimens_func*) dlsym(RTLD_DEFAULT, "futimens"); -#endif #if defined(_AIX) // Make sure we link to the 64-bit version of the function my_fdopendir_func = (fdopendir_func*) dlsym(RTLD_DEFAULT, "fdopendir64"); @@ -402,25 +381,11 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this) my_fstatat_func = (fstatat_func*)&fstatat_wrapper; #endif - /* supports futimes, futimens, and/or lutimes */ - -#ifdef _ALLBSD_SOURCE - capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES; - capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES; -#else - if (my_futimes_func != NULL) - capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMES; - if (my_lutimes_func != NULL) - capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_LUTIMES; -#endif - if (my_futimens_func != NULL) - capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_FUTIMENS; - /* supports openat, etc. */ if (my_openat_func != NULL && my_fstatat_func != NULL && my_unlinkat_func != NULL && my_renameat_func != NULL && - my_futimes_func != NULL && my_fdopendir_func != NULL) + my_fdopendir_func != NULL) { capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_OPENAT; } @@ -435,10 +400,6 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this) if (my_statx_func != NULL) { capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_BIRTHTIME; } - my_utimensat_func = (utimensat_func*) dlsym(RTLD_DEFAULT, "utimensat"); - if (my_utimensat_func != NULL) { - capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_UTIMENSAT; - } #endif /* supports extended attributes */ @@ -905,33 +866,6 @@ Java_sun_nio_fs_UnixNativeDispatcher_utimes0(JNIEnv* env, jclass this, } } -JNIEXPORT void JNICALL -Java_sun_nio_fs_UnixNativeDispatcher_futimes0(JNIEnv* env, jclass this, jint filedes, - jlong accessTime, jlong modificationTime) -{ - struct timeval times[2]; - int err = 0; - - times[0].tv_sec = accessTime / 1000000; - times[0].tv_usec = accessTime % 1000000; - - times[1].tv_sec = modificationTime / 1000000; - times[1].tv_usec = modificationTime % 1000000; - -#ifdef _ALLBSD_SOURCE - RESTARTABLE(futimes(filedes, ×[0]), err); -#else - if (my_futimes_func == NULL) { - JNU_ThrowInternalError(env, "my_futimes_func is NULL"); - return; - } - RESTARTABLE((*my_futimes_func)(filedes, ×[0]), err); -#endif - if (err == -1) { - throwUnixException(env, errno); - } -} - JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_futimens0(JNIEnv* env, jclass this, jint filedes, jlong accessTime, jlong modificationTime) @@ -945,39 +879,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_futimens0(JNIEnv* env, jclass this, jint fi times[1].tv_sec = modificationTime / 1000000000; times[1].tv_nsec = modificationTime % 1000000000; - if (my_futimens_func == NULL) { - JNU_ThrowInternalError(env, "my_futimens_func is NULL"); - return; - } - RESTARTABLE((*my_futimens_func)(filedes, ×[0]), err); - if (err == -1) { - throwUnixException(env, errno); - } -} - -JNIEXPORT void JNICALL -Java_sun_nio_fs_UnixNativeDispatcher_lutimes0(JNIEnv* env, jclass this, - jlong pathAddress, jlong accessTime, jlong modificationTime) -{ - int err; - struct timeval times[2]; - const char* path = (const char*)jlong_to_ptr(pathAddress); - - times[0].tv_sec = accessTime / 1000000; - times[0].tv_usec = accessTime % 1000000; - - times[1].tv_sec = modificationTime / 1000000; - times[1].tv_usec = modificationTime % 1000000; - -#ifdef _ALLBSD_SOURCE - RESTARTABLE(lutimes(path, ×[0]), err); -#else - if (my_lutimes_func == NULL) { - JNU_ThrowInternalError(env, "my_lutimes_func is NULL"); - return; - } - RESTARTABLE((*my_lutimes_func)(path, ×[0]), err); -#endif + RESTARTABLE(futimens(filedes, ×[0]), err); if (err == -1) { throwUnixException(env, errno); } @@ -986,7 +888,6 @@ Java_sun_nio_fs_UnixNativeDispatcher_lutimes0(JNIEnv* env, jclass this, JNIEXPORT void JNICALL Java_sun_nio_fs_UnixNativeDispatcher_utimensat0(JNIEnv* env, jclass this, jint fd, jlong pathAddress, jlong accessTime, jlong modificationTime, jint flags) { -#if defined(__linux__) int err; struct timespec times[2]; const char* path = (const char*)jlong_to_ptr(pathAddress); @@ -997,18 +898,11 @@ Java_sun_nio_fs_UnixNativeDispatcher_utimensat0(JNIEnv* env, jclass this, times[1].tv_sec = modificationTime / 1000000000; times[1].tv_nsec = modificationTime % 1000000000; - if (my_utimensat_func == NULL) { - JNU_ThrowInternalError(env, "my_utimensat_func is NULL"); - return; - } - RESTARTABLE((*my_utimensat_func)(fd, path, ×[0], flags), err); + RESTARTABLE(utimensat(fd, path, ×[0], flags), err); if (err == -1) { throwUnixException(env, errno); } -#else - JNU_ThrowInternalError(env, "should not reach here"); -#endif } JNIEXPORT jlong JNICALL diff --git a/src/java.base/windows/classes/java/lang/ProcessImpl.java b/src/java.base/windows/classes/java/lang/ProcessImpl.java index fd0d5b03b0cdf..967693dcbc321 100644 --- a/src/java.base/windows/classes/java/lang/ProcessImpl.java +++ b/src/java.base/windows/classes/java/lang/ProcessImpl.java @@ -35,8 +35,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.lang.ProcessBuilder.Redirect; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Locale; import java.util.concurrent.CompletableFuture; @@ -48,7 +46,6 @@ import jdk.internal.access.SharedSecrets; import jdk.internal.ref.CleanerFactory; import jdk.internal.misc.Blocker; -import sun.security.action.GetPropertyAction; /* This class is for the exclusive use of ProcessBuilder.start() to * create new processes. @@ -71,25 +68,15 @@ final class ProcessImpl extends Process { * to append to a file does not open the file in a manner that guarantees * that writes by the child process will be atomic. */ - @SuppressWarnings("removal") private static FileOutputStream newFileOutputStream(File f, boolean append) throws IOException { if (append) { String path = f.getPath(); - SecurityManager sm = System.getSecurityManager(); - if (sm != null) - sm.checkWrite(path); long handle = openForAtomicAppend(path); final FileDescriptor fd = new FileDescriptor(); fdAccess.setHandle(fd, handle); - return AccessController.doPrivileged( - new PrivilegedAction() { - public FileOutputStream run() { - return new FileOutputStream(fd); - } - } - ); + return new FileOutputStream(fd); } else { return new FileOutputStream(f); } @@ -424,7 +411,6 @@ private static int countLeadingBackslash(int verificationType, private InputStream stdout_stream; private InputStream stderr_stream; - @SuppressWarnings("removal") private ProcessImpl(String cmd[], final String envblock, final String path, @@ -434,13 +420,10 @@ private ProcessImpl(String cmd[], throws IOException { String cmdstr; - final SecurityManager security = System.getSecurityManager(); - final String value = GetPropertyAction. - privilegedGetProperty("jdk.lang.Process.allowAmbiguousCommands", - (security == null ? "true" : "false")); + final String value = System.getProperty("jdk.lang.Process.allowAmbiguousCommands", "true"); final boolean allowAmbiguousCommands = !"false".equalsIgnoreCase(value); - if (allowAmbiguousCommands && security == null) { + if (allowAmbiguousCommands) { // Legacy mode. // Normalize path if possible. @@ -478,10 +461,6 @@ private ProcessImpl(String cmd[], // Parse the command line again. cmd = getTokensFromCommand(join.toString()); executablePath = getExecutablePath(cmd[0]); - - // Check new executable name once more - if (security != null) - security.checkExec(executablePath); } // Quotation protects from interpretation of the [path] argument as @@ -505,39 +484,34 @@ private ProcessImpl(String cmd[], processHandle = ProcessHandleImpl.getInternal(getProcessId0(handle)); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Void run() { - if (stdHandles[0] == -1L) - stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE; - else { - FileDescriptor stdin_fd = new FileDescriptor(); - fdAccess.setHandle(stdin_fd, stdHandles[0]); - fdAccess.registerCleanup(stdin_fd); - stdin_stream = new BufferedOutputStream( - new PipeOutputStream(stdin_fd)); - } - - if (stdHandles[1] == -1L || forceNullOutputStream) - stdout_stream = ProcessBuilder.NullInputStream.INSTANCE; - else { - FileDescriptor stdout_fd = new FileDescriptor(); - fdAccess.setHandle(stdout_fd, stdHandles[1]); - fdAccess.registerCleanup(stdout_fd); - stdout_stream = new BufferedInputStream( - new PipeInputStream(stdout_fd)); - } + if (stdHandles[0] == -1L) + stdin_stream = ProcessBuilder.NullOutputStream.INSTANCE; + else { + FileDescriptor stdin_fd = new FileDescriptor(); + fdAccess.setHandle(stdin_fd, stdHandles[0]); + fdAccess.registerCleanup(stdin_fd); + stdin_stream = new BufferedOutputStream( + new PipeOutputStream(stdin_fd)); + } - if (stdHandles[2] == -1L) - stderr_stream = ProcessBuilder.NullInputStream.INSTANCE; - else { - FileDescriptor stderr_fd = new FileDescriptor(); - fdAccess.setHandle(stderr_fd, stdHandles[2]); - fdAccess.registerCleanup(stderr_fd); - stderr_stream = new PipeInputStream(stderr_fd); - } + if (stdHandles[1] == -1L || forceNullOutputStream) + stdout_stream = ProcessBuilder.NullInputStream.INSTANCE; + else { + FileDescriptor stdout_fd = new FileDescriptor(); + fdAccess.setHandle(stdout_fd, stdHandles[1]); + fdAccess.registerCleanup(stdout_fd); + stdout_stream = new BufferedInputStream( + new PipeInputStream(stdout_fd)); + } - return null; }}); + if (stdHandles[2] == -1L) + stderr_stream = ProcessBuilder.NullInputStream.INSTANCE; + else { + FileDescriptor stderr_fd = new FileDescriptor(); + fdAccess.setHandle(stderr_fd, stdHandles[2]); + fdAccess.registerCleanup(stderr_fd); + stderr_stream = new PipeInputStream(stderr_fd); + } } public OutputStream getOutputStream() { @@ -632,11 +606,6 @@ public CompletableFuture onExit() { @Override public ProcessHandle toHandle() { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("manageProcess")); - } return processHandle; } diff --git a/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java b/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java index 757c4f99f4508..f228f1a4da107 100644 --- a/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java +++ b/src/java.datatransfer/share/classes/java/awt/datatransfer/DataFlavor.java @@ -45,7 +45,6 @@ import java.util.Objects; import sun.datatransfer.DataFlavorUtil; -import sun.reflect.misc.ReflectUtil; /** * A {@code DataFlavor} provides meta information about data. {@code DataFlavor} @@ -131,32 +130,22 @@ protected static final Class tryToLoadClass(String className, ClassLoader fallback) throws ClassNotFoundException { - ReflectUtil.checkPackageAccess(className); + ClassLoader loader = ClassLoader.getSystemClassLoader(); try { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("getClassLoader")); - } - ClassLoader loader = ClassLoader.getSystemClassLoader(); - try { - // bootstrap class loader and system class loader if present - return Class.forName(className, true, loader); - } - catch (ClassNotFoundException exception) { - // thread context class loader if and only if present - loader = Thread.currentThread().getContextClassLoader(); - if (loader != null) { - try { - return Class.forName(className, true, loader); - } - catch (ClassNotFoundException e) { - // fallback to user's class loader - } + // bootstrap class loader and system class loader if present + return Class.forName(className, true, loader); + } + catch (ClassNotFoundException exception) { + // thread context class loader if and only if present + loader = Thread.currentThread().getContextClassLoader(); + if (loader != null) { + try { + return Class.forName(className, true, loader); + } + catch (ClassNotFoundException e) { + // fallback to user's class loader } } - } catch (SecurityException exception) { - // ignore secured class loaders } return Class.forName(className, true, fallback); } diff --git a/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java b/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java index 6b2dc14c05fc1..deea133b7344b 100644 --- a/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java +++ b/src/java.datatransfer/share/classes/java/awt/datatransfer/SystemFlavorMap.java @@ -30,8 +30,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.lang.ref.SoftReference; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -202,12 +200,8 @@ private void initSystemFlavorMap() { } isMapInitialized = true; - @SuppressWarnings("removal") - InputStream is = AccessController.doPrivileged( - (PrivilegedAction) () -> { - return SystemFlavorMap.class.getResourceAsStream( + InputStream is = SystemFlavorMap.class.getResourceAsStream( "/sun/datatransfer/resources/flavormap.properties"); - }); if (is == null) { throw new InternalError("Default flavor mapping not found"); } diff --git a/src/java.desktop/aix/native/libawt_xawt/awt/awt_InputMethod.c b/src/java.desktop/aix/native/libawt_xawt/awt/awt_InputMethod.c index 908b7cca653cc..bbfb5ae42f99b 100644 --- a/src/java.desktop/aix/native/libawt_xawt/awt/awt_InputMethod.c +++ b/src/java.desktop/aix/native/libawt_xawt/awt/awt_InputMethod.c @@ -449,7 +449,7 @@ awt_x11inputmethod_lookupString(XKeyPressedEvent *event, KeySym *keysymp) "(Ljava/lang/String;J)V", javastr, event->time); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } @@ -682,7 +682,7 @@ static void onoffStatusWindow(X11InputMethodData* pX11IMData, parent = JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod, "getCurrentParentWindow", "()J").j; - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } @@ -1057,7 +1057,7 @@ PreeditDoneCallback(XIC ic, XPointer client_data, XPointer call_data) "clearComposedText", "(J)V", awt_util_nowMillisUTC()); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } @@ -1160,7 +1160,7 @@ PreeditDrawCallback(XIC ic, XPointer client_data, (jint)pre_draw->caret, awt_util_nowMillisUTC()); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } @@ -2125,7 +2125,7 @@ JNIEXPORT jstring JNICALL Java_sun_awt_X11InputMethodBase_resetXIC JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod, "clearComposedText", "()V"); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m index e881c5cc38f51..889eaa4aff738 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/AWTView.m @@ -515,23 +515,6 @@ - (void) drawRect:(NSRect)dirtyRect { [super drawRect:dirtyRect]; JNIEnv *env = [ThreadUtilities getJNIEnv]; if (env != NULL) { - /* - if ([self inLiveResize]) { - NSRect rs[4]; - NSInteger count; - [self getRectsExposedDuringLiveResize:rs count:&count]; - for (int i = 0; i < count; i++) { - JNU_CallMethodByName(env, NULL, [m_awtWindow cPlatformView], - "deliverWindowDidExposeEvent", "(FFFF)V", - (jfloat)rs[i].origin.x, (jfloat)rs[i].origin.y, - (jfloat)rs[i].size.width, (jfloat)rs[i].size.height); - if ((*env)->ExceptionOccurred(env)) { - (*env)->ExceptionDescribe(env); - (*env)->ExceptionClear(env); - } - } - } else { - */ DECLARE_CLASS(jc_CPlatformView, "sun/lwawt/macosx/CPlatformView"); DECLARE_METHOD(jm_deliverWindowDidExposeEvent, jc_CPlatformView, "deliverWindowDidExposeEvent", "()V"); jobject jlocal = (*env)->NewLocalRef(env, m_cPlatformView); @@ -540,9 +523,6 @@ - (void) drawRect:(NSRect)dirtyRect { CHECK_EXCEPTION(); (*env)->DeleteLocalRef(env, jlocal); } - /* - } - */ } } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m index f0bc347197f66..ca92d67faf59c 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDataTransferer.m @@ -136,7 +136,7 @@ static jobjectArray CreateJavaFilenameArray(JNIEnv *env, NSArray *filenameArray) jclass stringClazz = (*env)->FindClass(env, "java/lang/String"); CHECK_NULL_RETURN(stringClazz, nil); jobject jfilenameArray = (*env)->NewObjectArray(env, filenameCount, stringClazz, NULL); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); return nil; @@ -156,7 +156,7 @@ static jobjectArray CreateJavaFilenameArray(JNIEnv *env, NSArray *filenameArray) // Create a Java String: jstring string = (*env)->NewStringUTF(env, stringBytes); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); continue; @@ -168,7 +168,7 @@ static jobjectArray CreateJavaFilenameArray(JNIEnv *env, NSArray *filenameArray) // Set the Java array element with our String: (*env)->SetObjectArrayElement(env, jfilenameArray, i, string); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); continue; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m index b8e87b25343d8..8752af237fed8 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTarget.m @@ -371,10 +371,10 @@ - (jobject) copyDraggingDataForFormat:(jlong)format (*env)->ReleaseByteArrayElements(env, gbyteArray, jbytes, 0); // In case of an error make sure to return nil: - if ((*env)->ExceptionOccurred(env)) { - (*env)->ExceptionDescribe(env); + if ((*env)->ExceptionCheck(env)) { + (*env)->ExceptionDescribe(env); gbyteArray = nil; - } + } return gbyteArray; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m index 2e590369508f9..0ee8300f72f4e 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CDropTargetContextPeer.m @@ -85,7 +85,7 @@ static void TransferFailed(JNIEnv *env, jobject jthis, jlong jdroptarget, jlong GET_DTCP_CLASS_RETURN(result); DECLARE_METHOD_RETURN(newDataMethod, jc_CDropTargetContextPeer, "newData", "(J[B)V", result); - if ((*env)->ExceptionOccurred(env) || !newDataMethod) { + if ((*env)->ExceptionCheck(env) || !newDataMethod) { DLog2(@"[CDropTargetContextPeer startTransfer]: couldn't get newData method for %d.\n", (NSInteger) jdroptarget); TransferFailed(env, jthis, jdroptarget, (jlong) 0L, jformat); return result; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m index 468c5f6dae09a..787b90b4b9018 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m @@ -364,7 +364,7 @@ static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env) { if (cRef != NULL) { jobject oneMode = createJavaDisplayMode(cRef, env); (*env)->SetObjectArrayElement(env, jreturnArray, n, oneMode); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); continue; diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m index 3bfd72668c37d..7d580216985b5 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CInputMethod.m @@ -316,10 +316,10 @@ + (void) _nativeEndComposition:(AWTView *)view { } if ((*env)->CallBooleanMethod(env, returnValue, jm_listContains, localeObj) == JNI_FALSE) { - if ((*env)->ExceptionOccurred(env)) (*env)->ExceptionClear(env); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); (*env)->CallBooleanMethod(env, returnValue, jm_listAdd, localeObj); } - if ((*env)->ExceptionOccurred(env)) (*env)->ExceptionClear(env); + if ((*env)->ExceptionCheck(env)) (*env)->ExceptionClear(env); (*env)->DeleteLocalRef(env, localeObj); } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m index 5e1d6ba0cb1c1..a1f4afb0929e8 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTFont.m @@ -577,7 +577,7 @@ static OSStatus CreateFSRef(FSRef *myFSRefPtr, NSString *inPath) jstring jFontName = (jstring)NSStringToJavaString(env, fontname); CFRelease(fontname); (*env)->CallBooleanMethod(env, arrayListOfString, addMID, jFontName); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { CFRelease(fds); return; } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m index 1e2ba23d9aa40..7b43638206527 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/font/AWTStrike.m @@ -95,7 +95,7 @@ + (AWTStrike *) awtStrikeForFont:(AWTFont *)awtFont _fontThrowJavaException = YES; \ goto cleanup; \ } \ - if ((*env)->ExceptionCheck(env) == JNI_TRUE) { \ + if ((*env)->ExceptionCheck(env)) { \ goto cleanup; \ } diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m index 90b77879b2a7d..d09e1fc32c757 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLSurfaceData.m @@ -154,7 +154,7 @@ static jboolean MTLSurfaceData_initTexture(BMTLSDOps *bmtlsdo, jboolean isOpaque } JNU_SetFieldByName(env, NULL, sdObject, "nativeWidth", "I", width); - if (!((*env)->ExceptionOccurred(env))) { + if (!((*env)->ExceptionCheck(env))) { JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height); } diff --git a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h index 41dd4c48b75c9..fec64e09141c7 100644 --- a/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h +++ b/src/java.desktop/macosx/native/libosxapp/JNIUtilities.h @@ -38,11 +38,11 @@ NSLog(@"Bad JNI lookup %s\n", name); \ NSLog(@"%@",[NSThread callStackSymbols]); \ if ([NSThread isMainThread] == NO) { \ - if ((*env)->ExceptionOccurred(env) == NULL) { \ + if (!(*env)->ExceptionCheck(env)) { \ JNU_ThrowInternalError(env, "Bad JNI Lookup"); \ } \ } else { \ - if ((*env)->ExceptionOccurred(env) != NULL) { \ + if ((*env)->ExceptionCheck(env)) { \ (*env)->ExceptionDescribe(env); \ } \ } \ @@ -184,7 +184,7 @@ * nature of the problem that has been detected and how survivable it is. */ #define CHECK_EXCEPTION() \ - if ((*env)->ExceptionOccurred(env) != NULL) { \ + if ((*env)->ExceptionCheck(env)) { \ if ([NSThread isMainThread] == YES) { \ if (getenv("JNU_APPKIT_TRACE")) { \ (*env)->ExceptionDescribe(env); \ diff --git a/src/java.desktop/share/classes/javax/swing/AbstractAction.java b/src/java.desktop/share/classes/javax/swing/AbstractAction.java index 6a22a985d69b7..2bf40e810c6c5 100644 --- a/src/java.desktop/share/classes/javax/swing/AbstractAction.java +++ b/src/java.desktop/share/classes/javax/swing/AbstractAction.java @@ -32,12 +32,9 @@ import java.io.ObjectOutputStream; import java.io.Serial; import java.io.Serializable; -import java.security.AccessController; import javax.swing.event.SwingPropertyChangeSupport; -import sun.security.action.GetPropertyAction; - /** * This class provides default implementations for the JFC Action * interface. Standard behaviors like the get and set methods for @@ -81,14 +78,11 @@ public abstract class AbstractAction implements Action, Cloneable, Serializable * Whether or not to reconfigure all action properties from the * specified event. */ - @SuppressWarnings("removal") static boolean shouldReconfigure(PropertyChangeEvent e) { if (e.getPropertyName() == null) { synchronized(AbstractAction.class) { if (RECONFIGURE_ON_NULL == null) { - RECONFIGURE_ON_NULL = Boolean.valueOf( - AccessController.doPrivileged(new GetPropertyAction( - "swing.actions.reconfigureOnNull", "false"))); + RECONFIGURE_ON_NULL = Boolean.getBoolean("swing.actions.reconfigureOnNull"); } return RECONFIGURE_ON_NULL; } diff --git a/src/java.desktop/share/classes/javax/swing/DebugGraphics.java b/src/java.desktop/share/classes/javax/swing/DebugGraphics.java index 9a9a4fbe70f93..1d6c52c4680f3 100644 --- a/src/java.desktop/share/classes/javax/swing/DebugGraphics.java +++ b/src/java.desktop/share/classes/javax/swing/DebugGraphics.java @@ -27,8 +27,6 @@ import java.awt.*; import java.awt.image.*; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.text.AttributedCharacterIterator; /** @@ -79,7 +77,6 @@ public class DebugGraphics extends Graphics { * applications, it is for internal use only. When called directly * it will create an un-usable instance. */ - @SuppressWarnings("removal") public DebugGraphics() { super(); buffer = null; @@ -87,14 +84,7 @@ public DebugGraphics() { // Creates a Graphics context when the constructor is called. if (this.graphics == null) { - StackWalker walker = AccessController.doPrivileged(new PrivilegedAction() { - @Override - public StackWalker run() { - StackWalker stackwalker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); - return stackwalker; - } - }); - + StackWalker walker = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); if (walker.getCallerClass() != this.getClass()) { BufferedImage bi = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB); this.graphics = bi.createGraphics(); diff --git a/src/java.desktop/share/classes/javax/swing/ImageIcon.java b/src/java.desktop/share/classes/javax/swing/ImageIcon.java index 2eeac8961bcfe..2bae31ba31fec 100644 --- a/src/java.desktop/share/classes/javax/swing/ImageIcon.java +++ b/src/java.desktop/share/classes/javax/swing/ImageIcon.java @@ -44,10 +44,6 @@ import java.io.Serial; import java.io.Serializable; import java.net.URL; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.ProtectionDomain; import java.util.Locale; import javax.accessibility.Accessible; @@ -105,27 +101,19 @@ public class ImageIcon implements Icon, Serializable, Accessible { * It is left for backward compatibility only. * @deprecated since 1.8 */ - @SuppressWarnings("removal") @Deprecated - protected static final Component component - = AccessController.doPrivileged(new PrivilegedAction() { - public Component run() { - try { - final Component component = createNoPermsComponent(); - - // 6482575 - clear the appContext field so as not to leak it - AWTAccessor.getComponentAccessor(). - setAppContext(component, null); - - return component; - } catch (Throwable e) { - // We don't care about component. - // So don't prevent class initialisation. - e.printStackTrace(); - return null; - } + protected static final Component component = createComponent(); + + private static final Component createComponent() { + try { + Component component = new Component() {}; + // 6482575 - clear the appContext field so as not to leak it + AWTAccessor.getComponentAccessor().setAppContext(component, null); + return component; + } catch (Throwable t) { + return null; } - }); + } /** * Do not use this shared media tracker, which is used to load images. @@ -135,23 +123,6 @@ public Component run() { @Deprecated protected static final MediaTracker tracker = new MediaTracker(component); - @SuppressWarnings("removal") - private static Component createNoPermsComponent() { - // 7020198 - set acc field to no permissions and no subject - // Note, will have appContext set. - return AccessController.doPrivileged( - new PrivilegedAction() { - public Component run() { - return new Component() { - }; - } - }, - new AccessControlContext(new ProtectionDomain[]{ - new ProtectionDomain(null, null) - }) - ); - } - /** * Id used in loading images from MediaTracker. */ diff --git a/src/java.desktop/share/classes/javax/swing/JLayer.java b/src/java.desktop/share/classes/javax/swing/JLayer.java index c2076299e4426..b08b140933f8a 100644 --- a/src/java.desktop/share/classes/javax/swing/JLayer.java +++ b/src/java.desktop/share/classes/javax/swing/JLayer.java @@ -38,8 +38,6 @@ import java.io.ObjectInputStream; import java.io.Serial; import java.util.ArrayList; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * {@code JLayer} is a universal decorator for Swing components @@ -816,27 +814,14 @@ private long getCurrentEventMask() { return currentEventMask; } - @SuppressWarnings("removal") private void addAWTEventListener(final long eventMask) { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - Toolkit.getDefaultToolkit(). - addAWTEventListener(LayerEventController.this, eventMask); - return null; - } - }); - + Toolkit.getDefaultToolkit(). + addAWTEventListener(LayerEventController.this, eventMask); } - @SuppressWarnings("removal") private void removeAWTEventListener() { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - Toolkit.getDefaultToolkit(). - removeAWTEventListener(LayerEventController.this); - return null; - } - }); + Toolkit.getDefaultToolkit(). + removeAWTEventListener(LayerEventController.this); } private boolean isEventEnabled(long eventMask, int id) { diff --git a/src/java.desktop/share/classes/javax/swing/JPopupMenu.java b/src/java.desktop/share/classes/javax/swing/JPopupMenu.java index 29cc59b1bb166..d1fff6a11e068 100644 --- a/src/java.desktop/share/classes/javax/swing/JPopupMenu.java +++ b/src/java.desktop/share/classes/javax/swing/JPopupMenu.java @@ -119,11 +119,8 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey"); /** Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced */ - @SuppressWarnings("removal") static boolean popupPositionFixDisabled = - java.security.AccessController.doPrivileged( - new sun.security.action.GetPropertyAction( - "javax.swing.adjustPopupLocationToFit","")).equals("false"); + System.getProperty("javax.swing.adjustPopupLocationToFit","").equals("false"); transient Component invoker; transient Popup popup; diff --git a/src/java.desktop/share/classes/javax/swing/JRootPane.java b/src/java.desktop/share/classes/javax/swing/JRootPane.java index 0e2668b363a5b..44eb41248e608 100644 --- a/src/java.desktop/share/classes/javax/swing/JRootPane.java +++ b/src/java.desktop/share/classes/javax/swing/JRootPane.java @@ -26,13 +26,10 @@ import java.awt.*; import java.beans.*; -import java.security.AccessController; import javax.accessibility.*; import javax.swing.plaf.RootPaneUI; import java.io.Serializable; -import sun.security.action.GetBooleanAction; - /** * A lightweight container used behind the scenes by @@ -202,19 +199,15 @@ public class JRootPane extends JComponent implements Accessible { * Whether or not we should dump the stack when true double buffering * is disabled. Default is false. */ - @SuppressWarnings("removal") private static final boolean LOG_DISABLE_TRUE_DOUBLE_BUFFERING - = AccessController.doPrivileged(new GetBooleanAction( - "swing.logDoubleBufferingDisable")); + = Boolean.getBoolean("swing.logDoubleBufferingDisable"); /** * Whether or not we should ignore requests to disable true double * buffering. Default is false. */ - @SuppressWarnings("removal") private static final boolean IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING - = AccessController.doPrivileged(new GetBooleanAction( - "swing.ignoreDoubleBufferingDisable")); + = Boolean.getBoolean("swing.ignoreDoubleBufferingDisable"); /** * Constant used for the windowDecorationStyle property. Indicates that diff --git a/src/java.desktop/share/classes/javax/swing/RepaintManager.java b/src/java.desktop/share/classes/javax/swing/RepaintManager.java index eb696a7b489d8..2636c81be075f 100644 --- a/src/java.desktop/share/classes/javax/swing/RepaintManager.java +++ b/src/java.desktop/share/classes/javax/swing/RepaintManager.java @@ -28,9 +28,6 @@ import java.awt.*; import java.awt.event.*; import java.awt.image.VolatileImage; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.applet.*; @@ -211,22 +208,13 @@ public void removeRepaintListener(RepaintManager rm, RepaintListener l) { } }); - @SuppressWarnings("removal") - var t1 = "true".equals(AccessController. - doPrivileged(new GetPropertyAction( - "swing.volatileImageBufferEnabled", "true"))); - volatileImageBufferEnabled = t1; + volatileImageBufferEnabled = "true".equals(System.getProperty("swing.volatileImageBufferEnabled", "true")); boolean headless = GraphicsEnvironment.isHeadless(); if (volatileImageBufferEnabled && headless) { volatileImageBufferEnabled = false; } - @SuppressWarnings("removal") - var t2 = "true".equals(AccessController.doPrivileged( - new GetPropertyAction("awt.nativeDoubleBuffering"))); - nativeDoubleBuffering = t2; - @SuppressWarnings("removal") - String bs = AccessController.doPrivileged( - new GetPropertyAction("swing.bufferPerWindow")); + nativeDoubleBuffering = "true".equals(System.getProperty("awt.nativeDoubleBuffering")); + String bs = System.getProperty("swing.bufferPerWindow"); if (headless) { BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF; } @@ -239,10 +227,7 @@ else if ("true".equals(bs)) { else { BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF; } - @SuppressWarnings("removal") - var t3 = "true".equals(AccessController.doPrivileged( - new GetPropertyAction("swing.handleTopLevelPaint", "true"))); - HANDLE_TOP_LEVEL_PAINT = t3; + HANDLE_TOP_LEVEL_PAINT = "true".equals(System.getProperty("swing.handleTopLevelPaint", "true")); GraphicsEnvironment ge = GraphicsEnvironment. getLocalGraphicsEnvironment(); if (ge instanceof SunGraphicsEnvironment) { @@ -611,21 +596,7 @@ void nativeQueueSurfaceDataRunnable(AppContext appContext, if (runnableList == null) { runnableList = new LinkedList(); } - runnableList.add(new Runnable() { - public void run() { - @SuppressWarnings("removal") - AccessControlContext stack = AccessController.getContext(); - @SuppressWarnings("removal") - AccessControlContext acc = - AWTAccessor.getComponentAccessor().getAccessControlContext(c); - javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction() { - public Void run() { - r.run(); - return null; - } - }, stack, acc); - } - }); + runnableList.add(r); } scheduleProcessingRunnable(appContext); } @@ -746,18 +717,7 @@ public void validateInvalidComponents() { int n = ic.size(); for(int i = 0; i < n; i++) { final Component c = ic.get(i); - @SuppressWarnings("removal") - AccessControlContext stack = AccessController.getContext(); - @SuppressWarnings("removal") - AccessControlContext acc = - AWTAccessor.getComponentAccessor().getAccessControlContext(c); - javaSecurityAccess.doIntersectionPrivilege( - new PrivilegedAction() { - public Void run() { - c.validate(); - return null; - } - }, stack, acc); + c.validate(); } } @@ -853,61 +813,50 @@ private void paintDirtyRegions( for (int j=0 ; j < count.get(); j++) { final int i = j; final Component dirtyComponent = roots.get(j); - @SuppressWarnings("removal") - AccessControlContext stack = AccessController.getContext(); - @SuppressWarnings("removal") - AccessControlContext acc = - AWTAccessor.getComponentAccessor().getAccessControlContext(dirtyComponent); - javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction() { - public Void run() { - Rectangle rect = tmpDirtyComponents.get(dirtyComponent); - // Sometimes when RepaintManager is changed during the painting - // we may get null here, see #6995769 for details - if (rect == null) { - return null; - } + Rectangle rect = tmpDirtyComponents.get(dirtyComponent); + // Sometimes when RepaintManager is changed during the painting + // we may get null here, see #6995769 for details + if (rect == null) { + continue; + } - int localBoundsH = dirtyComponent.getHeight(); - int localBoundsW = dirtyComponent.getWidth(); - SwingUtilities.computeIntersection(0, - 0, - localBoundsW, - localBoundsH, - rect); - if (dirtyComponent instanceof JComponent) { - ((JComponent)dirtyComponent).paintImmediately( - rect.x,rect.y,rect.width, rect.height); - } - else if (dirtyComponent.isShowing()) { - Graphics g = JComponent.safelyGetGraphics( - dirtyComponent, dirtyComponent); - // If the Graphics goes away, it means someone disposed of - // the window, don't do anything. - if (g != null) { - g.setClip(rect.x, rect.y, rect.width, rect.height); - try { - dirtyComponent.paint(g); - } finally { - g.dispose(); - } - } - } - // If the repaintRoot has been set, service it now and - // remove any components that are children of repaintRoot. - if (repaintRoot != null) { - adjustRoots(repaintRoot, roots, i + 1); - count.set(roots.size()); - paintManager.isRepaintingRoot = true; - repaintRoot.paintImmediately(0, 0, repaintRoot.getWidth(), - repaintRoot.getHeight()); - paintManager.isRepaintingRoot = false; - // Only service repaintRoot once. - repaintRoot = null; + int localBoundsH = dirtyComponent.getHeight(); + int localBoundsW = dirtyComponent.getWidth(); + SwingUtilities.computeIntersection(0, + 0, + localBoundsW, + localBoundsH, + rect); + if (dirtyComponent instanceof JComponent) { + ((JComponent)dirtyComponent).paintImmediately( + rect.x,rect.y,rect.width, rect.height); + } + else if (dirtyComponent.isShowing()) { + Graphics g = JComponent.safelyGetGraphics( + dirtyComponent, dirtyComponent); + // If the Graphics goes away, it means someone disposed of + // the window, don't do anything. + if (g != null) { + g.setClip(rect.x, rect.y, rect.width, rect.height); + try { + dirtyComponent.paint(g); + } finally { + g.dispose(); } - - return null; } - }, stack, acc); + } + // If the repaintRoot has been set, service it now and + // remove any components that are children of repaintRoot. + if (repaintRoot != null) { + adjustRoots(repaintRoot, roots, i + 1); + count.set(roots.size()); + paintManager.isRepaintingRoot = true; + repaintRoot.paintImmediately(0, 0, repaintRoot.getWidth(), + repaintRoot.getHeight()); + paintManager.isRepaintingRoot = false; + // Only service repaintRoot once. + repaintRoot = null; + } } } finally { painting = false; diff --git a/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java b/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java index 92f98fdfc992f..ab306187e3206 100644 --- a/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java +++ b/src/java.desktop/share/classes/javax/swing/SortingFocusTraversalPolicy.java @@ -29,8 +29,6 @@ import java.util.*; import java.awt.FocusTraversalPolicy; import sun.util.logging.PlatformLogger; -import sun.security.action.GetPropertyAction; -import java.security.AccessController; /** * A FocusTraversalPolicy that determines traversal order by sorting the @@ -95,10 +93,8 @@ public class SortingFocusTraversalPolicy * When false, the default (tim-sort) algo is used, which may lead to an exception. * See: JDK-8048887 */ - @SuppressWarnings("removal") private static final boolean legacySortingFTPEnabled = "true".equals( - AccessController.doPrivileged( - new GetPropertyAction("swing.legacySortingFTPEnabled", "true"))); + System.getProperty("swing.legacySortingFTPEnabled", "true")); /** * Constructs a SortingFocusTraversalPolicy without a Comparator. diff --git a/src/java.desktop/share/classes/javax/swing/SwingPaintEventDispatcher.java b/src/java.desktop/share/classes/javax/swing/SwingPaintEventDispatcher.java index d0e34256ed4d4..4bada6e8bc726 100644 --- a/src/java.desktop/share/classes/javax/swing/SwingPaintEventDispatcher.java +++ b/src/java.desktop/share/classes/javax/swing/SwingPaintEventDispatcher.java @@ -32,8 +32,6 @@ import sun.awt.AppContext; import sun.awt.SunToolkit; import sun.awt.event.IgnorePaintEvent; -import sun.security.action.GetBooleanAction; -import sun.security.action.GetPropertyAction; /** * Swing's PaintEventDispatcher. If the component specified by the PaintEvent @@ -41,16 +39,15 @@ * will forward the request to the RepaintManager for eventual painting. * */ -@SuppressWarnings("removal") class SwingPaintEventDispatcher extends sun.awt.PaintEventDispatcher { private static final boolean SHOW_FROM_DOUBLE_BUFFER; private static final boolean ERASE_BACKGROUND; static { - SHOW_FROM_DOUBLE_BUFFER = "true".equals(AccessController.doPrivileged( - new GetPropertyAction("swing.showFromDoubleBuffer", "true"))); - ERASE_BACKGROUND = AccessController.doPrivileged( - new GetBooleanAction("swing.nativeErase")); + SHOW_FROM_DOUBLE_BUFFER = + "true".equals(System.getProperty("swing.showFromDoubleBuffer", "true")); + ERASE_BACKGROUND = + "true".equals(System.getProperty("swing.swing.nativeErase", "false")); } public PaintEvent createPaintEvent(Component component, int x, int y, diff --git a/src/java.desktop/share/classes/javax/swing/SwingUtilities.java b/src/java.desktop/share/classes/javax/swing/SwingUtilities.java index 4097062295678..89fe897053176 100644 --- a/src/java.desktop/share/classes/javax/swing/SwingUtilities.java +++ b/src/java.desktop/share/classes/javax/swing/SwingUtilities.java @@ -40,8 +40,6 @@ import javax.swing.event.MenuDragMouseEvent; import javax.swing.plaf.UIResource; import javax.swing.text.View; -import java.security.AccessController; -import sun.security.action.GetPropertyAction; import sun.awt.AppContext; import sun.awt.AWTAccessor; @@ -75,12 +73,9 @@ public class SwingUtilities implements SwingConstants * Returns true if setTransferHandler should change the * DropTarget. */ - @SuppressWarnings("removal") private static boolean getSuppressDropTarget() { if (!checkedSuppressDropSupport) { - suppressDropSupport = Boolean.parseBoolean( - AccessController.doPrivileged( - new GetPropertyAction("suppressSwingDropSupport"))); + suppressDropSupport = Boolean.getBoolean("suppressSwingDropSupport"); checkedSuppressDropSupport = true; } return suppressDropSupport; diff --git a/src/java.desktop/share/classes/javax/swing/SwingWorker.java b/src/java.desktop/share/classes/javax/swing/SwingWorker.java index 4eacdfcbf5027..a8f1e754aabc0 100644 --- a/src/java.desktop/share/classes/javax/swing/SwingWorker.java +++ b/src/java.desktop/share/classes/javax/swing/SwingWorker.java @@ -31,8 +31,6 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.lang.ref.WeakReference; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; @@ -797,7 +795,6 @@ public Thread newThread(final Runnable r) { final ExecutorService es = executorService; appContext.addPropertyChangeListener(AppContext.DISPOSED_PROPERTY_NAME, new PropertyChangeListener() { - @SuppressWarnings("removal") @Override public void propertyChange(PropertyChangeEvent pce) { boolean disposed = (Boolean)pce.getNewValue(); @@ -807,14 +804,7 @@ public void propertyChange(PropertyChangeEvent pce) { final ExecutorService executorService = executorServiceRef.get(); if (executorService != null) { - AccessController.doPrivileged( - new PrivilegedAction() { - public Void run() { - executorService.shutdown(); - return null; - } - } - ); + executorService.shutdown(); } } } diff --git a/src/java.desktop/share/classes/javax/swing/Timer.java b/src/java.desktop/share/classes/javax/swing/Timer.java index 4974aee0b7c01..3801eb0a0728f 100644 --- a/src/java.desktop/share/classes/javax/swing/Timer.java +++ b/src/java.desktop/share/classes/javax/swing/Timer.java @@ -32,9 +32,6 @@ import java.io.ObjectInputStream; import java.io.Serial; import java.io.Serializable; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.EventListener; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Lock; @@ -209,25 +206,6 @@ public Timer(int delay, ActionListener listener) { } } - /* - * The timer's AccessControlContext. - */ - @SuppressWarnings("removal") - private transient volatile AccessControlContext acc = - AccessController.getContext(); - - /** - * Returns the acc this timer was constructed with. - */ - @SuppressWarnings("removal") - final AccessControlContext getAccessControlContext() { - if (acc == null) { - throw new SecurityException( - "Timer is missing AccessControlContext"); - } - return acc; - } - /** * DoPostEvent is a runnable class that fires actionEvents to * the listeners on the EventDispatchThread, via invokeLater. @@ -609,15 +587,9 @@ void cancelEvent() { } - @SuppressWarnings("removal") void post() { - if (notify.compareAndSet(false, true) || !coalesce) { - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - SwingUtilities.invokeLater(doPostEvent); - return null; - } - }, getAccessControlContext()); + if (notify.compareAndSet(false, true) || !coalesce) { + SwingUtilities.invokeLater(doPostEvent); } } @@ -630,7 +602,6 @@ Lock getLock() { private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { - this.acc = AccessController.getContext(); ObjectInputStream.GetField f = in.readFields(); EventListenerList newListenerList = (EventListenerList) diff --git a/src/java.desktop/share/classes/javax/swing/TimerQueue.java b/src/java.desktop/share/classes/javax/swing/TimerQueue.java index 2743baefae661..249593caa7e02 100644 --- a/src/java.desktop/share/classes/javax/swing/TimerQueue.java +++ b/src/java.desktop/share/classes/javax/swing/TimerQueue.java @@ -25,8 +25,6 @@ package javax.swing; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.concurrent.*; import java.util.concurrent.locks.*; import java.util.concurrent.atomic.AtomicLong; @@ -83,7 +81,6 @@ public static TimerQueue sharedInstance() { } - @SuppressWarnings("removal") void startIfNeeded() { if (! running) { runningLock.lock(); @@ -92,15 +89,11 @@ void startIfNeeded() { } try { final ThreadGroup threadGroup = AppContext.getAppContext().getThreadGroup(); - AccessController.doPrivileged((PrivilegedAction) () -> { - String name = "TimerQueue"; - Thread timerThread = - new Thread(threadGroup, this, name, 0, false); - timerThread.setDaemon(true); - timerThread.setPriority(Thread.NORM_PRIORITY); - timerThread.start(); - return null; - }); + String name = "TimerQueue"; + Thread timerThread = new Thread(threadGroup, this, name, 0, false); + timerThread.setDaemon(true); + timerThread.setPriority(Thread.NORM_PRIORITY); + timerThread.start(); running = true; } finally { runningLock.unlock(); diff --git a/src/java.desktop/share/classes/javax/swing/UIDefaults.java b/src/java.desktop/share/classes/javax/swing/UIDefaults.java index 97f061fdb3d3a..62939b90e707c 100644 --- a/src/java.desktop/share/classes/javax/swing/UIDefaults.java +++ b/src/java.desktop/share/classes/javax/swing/UIDefaults.java @@ -51,7 +51,6 @@ import java.beans.PropertyChangeListener; import java.security.AccessController; import java.security.AccessControlContext; -import java.security.PrivilegedAction; import sun.reflect.misc.MethodUtil; import sun.reflect.misc.ReflectUtil; @@ -341,25 +340,19 @@ private Map getResourceCache(Locale l) { * Test if the specified baseName of the ROOT locale is in java.desktop module. * JDK always defines the resource bundle of the ROOT locale. */ - @SuppressWarnings("removal") private static boolean isDesktopResourceBundle(String baseName) { Module thisModule = UIDefaults.class.getModule(); - return AccessController.doPrivileged(new PrivilegedAction() { - @Override - public Boolean run() { - Class c = Class.forName(thisModule, baseName); - if (c != null) { - return true; - } else { - String resourceName = baseName.replace('.', '/') + ".properties"; - try (InputStream in = thisModule.getResourceAsStream(resourceName)) { - return in != null; - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } + Class c = Class.forName(thisModule, baseName); + if (c != null) { + return true; + } else { + String resourceName = baseName.replace('.', '/') + ".properties"; + try (InputStream in = thisModule.getResourceAsStream(resourceName)) { + return in != null; + } catch (IOException e) { + throw new UncheckedIOException(e); } - }); + } } /** @@ -1141,52 +1134,41 @@ public ProxyLazyValue(String c, String m, Object[] o) { * @param table a UIDefaults table * @return the created Object */ - @SuppressWarnings("removal") public Object createValue(final UIDefaults table) { - // In order to pick up the security policy in effect at the - // time of creation we use a doPrivileged with the - // AccessControlContext that was in place when this was created. - if (acc == null && System.getSecurityManager() != null) { - throw new SecurityException("null AccessControlContext"); - } - return AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - try { - Class c; - Object cl; - // See if we should use a separate ClassLoader - if (table == null || !((cl = table.get("ClassLoader")) - instanceof ClassLoader)) { - cl = Thread.currentThread(). - getContextClassLoader(); - if (cl == null) { - // Fallback to the system class loader. - cl = ClassLoader.getSystemClassLoader(); - } - } - ReflectUtil.checkPackageAccess(className); - c = Class.forName(className, true, (ClassLoader)cl); - SwingUtilities2.checkAccess(c.getModifiers()); - if (methodName != null) { - Class[] types = getClassArray(args); - Method m = c.getMethod(methodName, types); - return MethodUtil.invoke(m, c, args); - } else { - Class[] types = getClassArray(args); - Constructor constructor = c.getConstructor(types); - SwingUtilities2.checkAccess(constructor.getModifiers()); - return constructor.newInstance(args); - } - } catch(Exception e) { - // Ideally we would throw an exception, unfortunately - // often times there are errors as an initial look and - // feel is loaded before one can be switched. Perhaps a - // flag should be added for debugging, so that if true - // the exception would be thrown. + try { + Class c; + Object cl; + // See if we should use a separate ClassLoader + if (table == null || !((cl = table.get("ClassLoader")) + instanceof ClassLoader)) { + cl = Thread.currentThread(). + getContextClassLoader(); + if (cl == null) { + // Fallback to the system class loader. + cl = ClassLoader.getSystemClassLoader(); } - return null; } - }, acc); + ReflectUtil.checkPackageAccess(className); + c = Class.forName(className, true, (ClassLoader)cl); + SwingUtilities2.checkAccess(c.getModifiers()); + if (methodName != null) { + Class[] types = getClassArray(args); + Method m = c.getMethod(methodName, types); + return MethodUtil.invoke(m, c, args); + } else { + Class[] types = getClassArray(args); + Constructor constructor = c.getConstructor(types); + SwingUtilities2.checkAccess(constructor.getModifiers()); + return constructor.newInstance(args); + } + } catch(Exception e) { + // Ideally we would throw an exception, unfortunately + // often times there are errors as an initial look and + // feel is loaded before one can be switched. Perhaps a + // flag should be added for debugging, so that if true + // the exception would be thrown. + } + return null; } /* diff --git a/src/java.desktop/share/classes/javax/swing/UIManager.java b/src/java.desktop/share/classes/javax/swing/UIManager.java index 4bed87dc562ce..4c55e0c514993 100644 --- a/src/java.desktop/share/classes/javax/swing/UIManager.java +++ b/src/java.desktop/share/classes/javax/swing/UIManager.java @@ -35,8 +35,6 @@ import java.awt.event.KeyEvent; -import java.security.AccessController; - import javax.swing.plaf.ComponentUI; import javax.swing.border.Border; @@ -55,7 +53,6 @@ import sun.awt.SunToolkit; import sun.awt.OSInfo; -import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2; import java.util.HashMap; import java.util.Objects; @@ -292,8 +289,6 @@ private static String makeInstalledLAFKey(String laf, String attr) { */ private static String makeSwingPropertiesFilename() { String sep = File.separator; - // No need to wrap this in a doPrivileged as it's called from - // a doPrivileged. String javaHome = System.getProperty("java.home"); if (javaHome == null) { javaHome = ""; @@ -650,9 +645,7 @@ public static void setLookAndFeel(String className) * @see #getCrossPlatformLookAndFeelClassName */ public static String getSystemLookAndFeelClassName() { - @SuppressWarnings("removal") - String systemLAF = AccessController.doPrivileged( - new GetPropertyAction("swing.systemlaf")); + String systemLAF = System.getProperty("swing.systemlaf"); if (systemLAF != null) { return systemLAF; } @@ -691,9 +684,7 @@ public static String getSystemLookAndFeelClassName() { * @see #getSystemLookAndFeelClassName */ public static String getCrossPlatformLookAndFeelClassName() { - @SuppressWarnings("removal") - String laf = AccessController.doPrivileged( - new GetPropertyAction("swing.crossplatformlaf")); + String laf = System.getProperty("swing.crossplatformlaf"); if (laf != null) { return laf; } @@ -1282,46 +1273,38 @@ private static Properties loadSwingProperties() else { final Properties props = new Properties(); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { - props.put(defaultLAFKey, getSystemLookAndFeelClassName()); - } + if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) { + props.put(defaultLAFKey, getSystemLookAndFeelClassName()); + } - try { - File file = new File(makeSwingPropertiesFilename()); + try { + File file = new File(makeSwingPropertiesFilename()); - if (file.exists()) { - // InputStream has been buffered in Properties - // class - try (FileInputStream ins = new FileInputStream(file)) { - props.load(ins); - } - } - } - catch (Exception e) { - // No such file, or file is otherwise non-readable. + if (file.exists()) { + // InputStream has been buffered in Properties + // class + try (FileInputStream ins = new FileInputStream(file)) { + props.load(ins); } - - // Check whether any properties were overridden at the - // command line. - checkProperty(props, defaultLAFKey); - checkProperty(props, auxiliaryLAFsKey); - checkProperty(props, multiplexingLAFKey); - checkProperty(props, installedLAFsKey); - checkProperty(props, disableMnemonicKey); - // Don't care about return value. - return null; } - }); + } + catch (Exception e) { + // No such file, or file is otherwise non-readable. + } + + // Check whether any properties were overridden at the + // command line. + checkProperty(props, defaultLAFKey); + checkProperty(props, auxiliaryLAFsKey); + checkProperty(props, multiplexingLAFKey); + checkProperty(props, installedLAFsKey); + checkProperty(props, disableMnemonicKey); + return props; } } private static void checkProperty(Properties props, String key) { - // No need to do catch the SecurityException here, this runs - // in a doPrivileged. String value = System.getProperty(key); if (value != null) { props.put(key, value); diff --git a/src/java.desktop/share/classes/javax/swing/filechooser/FileSystemView.java b/src/java.desktop/share/classes/javax/swing/filechooser/FileSystemView.java index cfe90a8ec8c6e..fb89f725cd0ca 100644 --- a/src/java.desktop/share/classes/javax/swing/filechooser/FileSystemView.java +++ b/src/java.desktop/share/classes/javax/swing/filechooser/FileSystemView.java @@ -32,8 +32,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.lang.ref.WeakReference; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -917,13 +915,7 @@ public boolean isDrive(File dir) { } public boolean isFloppyDrive(final File dir) { - @SuppressWarnings("removal") - String path = AccessController.doPrivileged(new PrivilegedAction() { - public String run() { - return dir.getAbsolutePath(); - } - }); - + String path = dir.getAbsolutePath(); return path != null && (path.equals("A:\\") || path.equals("B:\\")); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java index 4c40dc2d278f9..2e1d894cc8f05 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicHTML.java @@ -393,12 +393,9 @@ public View create(Element elem) { private static Boolean useOV = null; - @SuppressWarnings("removal") private static void setAllowHTMLObject() { if (useOV == null) { - useOV = java.security.AccessController.doPrivileged( - new sun.security.action.GetBooleanAction( - "swing.html.object")); + useOV = Boolean.getBoolean("swing.html.object"); }; SwingAccessor.setAllowHTMLObject(useOV); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java index 4041bfca71435..12b871d6efddc 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicLookAndFeel.java @@ -45,8 +45,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.Serializable; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.HashSet; import java.util.Locale; @@ -194,7 +192,6 @@ public void propertyChange(PropertyChangeEvent prpChg) { /** * {@inheritDoc} */ - @SuppressWarnings("removal") public void uninitialize() { AppContext context = AppContext.getAppContext(); synchronized (BasicPopupMenuUI.MOUSE_GRABBER_KEY) { @@ -212,7 +209,7 @@ public void uninitialize() { } if(invocator != null) { - AccessController.doPrivileged(invocator); + invocator.run(); invocator = null; } @@ -2082,25 +2079,18 @@ private byte[] loadAudioData(final String soundFile){ * Class.getResourceAsStream just returns raw * bytes, which we can convert to a sound. */ - @SuppressWarnings("removal") - byte[] buffer = AccessController.doPrivileged( - new PrivilegedAction() { - public byte[] run() { - try { - InputStream resource = BasicLookAndFeel.this. - getClass().getResourceAsStream(soundFile); - if (resource == null) { - return null; - } - try (BufferedInputStream in = new BufferedInputStream(resource)) { - return in.readAllBytes(); - } - } catch (IOException ioe) { - System.err.println(ioe.toString()); - return null; - } + byte[] buffer = null; + try { + InputStream resource = BasicLookAndFeel.this. + getClass().getResourceAsStream(soundFile); + if (resource != null) { + try (BufferedInputStream in = new BufferedInputStream(resource)) { + buffer = in.readAllBytes(); } - }); + } + } catch (IOException ioe) { + System.err.println(ioe.toString()); + } if (buffer == null) { System.err.println(getClass().getName() + "/" + soundFile + " not found."); @@ -2190,11 +2180,10 @@ static void playSound(JComponent c, Object actionKey) { * This class contains listener that watches for all the mouse * events that can possibly invoke popup on the component */ - class AWTEventHelper implements AWTEventListener,PrivilegedAction { - @SuppressWarnings("removal") + class AWTEventHelper implements AWTEventListener { AWTEventHelper() { super(); - AccessController.doPrivileged(this); + run(); } public Object run() { diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java index db68e126afa12..28a797f693716 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicPopupMenuUI.java @@ -776,22 +776,14 @@ void uninstall() { } } - @SuppressWarnings("removal") void grabWindow(MenuElement[] newPath) { // A grab needs to be added final Toolkit tk = Toolkit.getDefaultToolkit(); - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - tk.addAWTEventListener(MouseGrabber.this, - AWTEvent.MOUSE_EVENT_MASK | - AWTEvent.MOUSE_MOTION_EVENT_MASK | - AWTEvent.MOUSE_WHEEL_EVENT_MASK | - AWTEvent.WINDOW_EVENT_MASK | sun.awt.SunToolkit.GRAB_EVENT_MASK); - return null; - } - } - ); + tk.addAWTEventListener(MouseGrabber.this, + AWTEvent.MOUSE_EVENT_MASK | + AWTEvent.MOUSE_MOTION_EVENT_MASK | + AWTEvent.MOUSE_WHEEL_EVENT_MASK | + AWTEvent.WINDOW_EVENT_MASK | sun.awt.SunToolkit.GRAB_EVENT_MASK); Component invoker = newPath[0].getComponent(); if (invoker instanceof JPopupMenu) { @@ -812,18 +804,10 @@ public Object run() { } } - @SuppressWarnings("removal") void ungrabWindow() { final Toolkit tk = Toolkit.getDefaultToolkit(); // The grab should be removed - java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Object run() { - tk.removeAWTEventListener(MouseGrabber.this); - return null; - } - } - ); + tk.removeAWTEventListener(MouseGrabber.this); realUngrabWindow(); } diff --git a/src/java.desktop/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java b/src/java.desktop/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java index e6d44c0fae45e..3b9c79a8a9a7b 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/metal/DefaultMetalTheme.java @@ -30,7 +30,6 @@ import java.awt.*; import sun.awt.AppContext; -import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2; /** @@ -182,9 +181,7 @@ static String getDefaultPropertyName(int key) { } static { - @SuppressWarnings("removal") - Object boldProperty = java.security.AccessController.doPrivileged( - new GetPropertyAction("swing.boldMetal")); + Object boldProperty = System.getProperty("swing.boldMetal"); if (boldProperty == null || !"false".equals(boldProperty)) { PLAIN_FONTS = false; } @@ -371,7 +368,7 @@ public FontDelegate() { public FontUIResource getFont(int type) { int mappedType = defaultMapping[type]; if (fonts[type] == null) { - Font f = getPrivilegedFont(mappedType); + Font f = getFontForType(mappedType); if (f == null) { f = new Font(getDefaultFontName(type), @@ -385,18 +382,10 @@ public FontUIResource getFont(int type) { /** * This is the same as invoking - * Font.getFont(key), with the exception - * that it is wrapped inside a doPrivileged call. + * Font.getFont(key) */ - @SuppressWarnings("removal") - protected Font getPrivilegedFont(final int key) { - return java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public Font run() { - return Font.getFont(getDefaultPropertyName(key)); - } - } - ); + protected Font getFontForType(final int key) { + return Font.getFont(getDefaultPropertyName(key)); } } @@ -405,21 +394,21 @@ public Font run() { */ private static class WindowsFontDelegate extends FontDelegate { private MetalFontDesktopProperty[] props; - private boolean[] checkedPrivileged; + private boolean[] checked; public WindowsFontDelegate() { props = new MetalFontDesktopProperty[6]; - checkedPrivileged = new boolean[6]; + checked = new boolean[6]; } public FontUIResource getFont(int type) { if (fonts[type] != null) { return fonts[type]; } - if (!checkedPrivileged[type]) { - Font f = getPrivilegedFont(type); + if (!checked[type]) { + Font f = getFontForType(type); - checkedPrivileged[type] = true; + checked[type] = true; if (f != null) { fonts[type] = new FontUIResource(f); return fonts[type]; diff --git a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java index e46091c523cb6..18547fcbbf94b 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/metal/MetalLookAndFeel.java @@ -36,7 +36,6 @@ import java.beans.PropertyChangeListener; import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; -import java.security.AccessController; import javax.swing.ButtonModel; import javax.swing.DefaultButtonModel; @@ -145,9 +144,7 @@ static boolean isWindows() { if (!checkedWindows) { if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) { isWindows = true; - @SuppressWarnings("removal") - String systemFonts = AccessController.doPrivileged( - new GetPropertyAction("swing.useSystemFontSettings")); + String systemFonts = System.getProperty("swing.useSystemFontSettings"); useSystemFonts = Boolean.parseBoolean(systemFonts); } checkedWindows = true; @@ -1662,9 +1659,7 @@ public static MetalTheme getCurrentTheme() { else { // Create the default theme. We prefer Ocean, but will // use DefaultMetalTheme if told to. - @SuppressWarnings("removal") - String theme = AccessController.doPrivileged( - new GetPropertyAction("swing.metalTheme")); + String theme = System.getProperty("swing.metalTheme"); if ("steel".equals(theme)) { currentTheme = new DefaultMetalTheme(); } diff --git a/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java b/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java index 6c21e71c2efa7..de84947677282 100644 --- a/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java +++ b/src/java.desktop/share/classes/javax/swing/text/AbstractDocument.java @@ -147,14 +147,7 @@ protected AbstractDocument(Content data, AttributeContext context) { if (defaultI18NProperty == null) { // determine default setting for i18n support - @SuppressWarnings("removal") - String o = java.security.AccessController.doPrivileged( - new java.security.PrivilegedAction() { - public String run() { - return System.getProperty(I18NProperty); - } - } - ); + String o = System.getProperty(I18NProperty); if (o != null) { defaultI18NProperty = Boolean.valueOf(o); } else { diff --git a/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java b/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java index 21e2b6115e3ae..ce36a5d5a1fe6 100644 --- a/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java +++ b/src/java.desktop/share/classes/javax/swing/text/JTextComponent.java @@ -26,9 +26,6 @@ import com.sun.beans.util.Cache; -import java.security.AccessController; -import java.security.PrivilegedAction; - import java.beans.JavaBean; import java.beans.BeanProperty; import java.beans.Transient; @@ -3969,17 +3966,12 @@ public Boolean create(final Class type) { if (get(type.getSuperclass())) { return Boolean.TRUE; } - return AccessController.doPrivileged( - new PrivilegedAction() { - public Boolean run() { - try { - type.getDeclaredMethod("processInputMethodEvent", InputMethodEvent.class); - return Boolean.TRUE; - } catch (NoSuchMethodException exception) { - return Boolean.FALSE; - } - } - }); + try { + type.getDeclaredMethod("processInputMethodEvent", InputMethodEvent.class); + return Boolean.TRUE; + } catch (NoSuchMethodException exception) { + return Boolean.FALSE; + } } }; diff --git a/src/java.desktop/share/classes/javax/swing/text/PlainView.java b/src/java.desktop/share/classes/javax/swing/text/PlainView.java index 6697ca4e2a39a..148238354b53a 100644 --- a/src/java.desktop/share/classes/javax/swing/text/PlainView.java +++ b/src/java.desktop/share/classes/javax/swing/text/PlainView.java @@ -27,8 +27,6 @@ import java.awt.*; import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Objects; import javax.swing.event.*; import java.lang.ref.SoftReference; @@ -839,20 +837,13 @@ static boolean getFPMethodOverridden(Class cls, String method, return isFPMethodOverridden; } - @SuppressWarnings("removal") private static boolean checkFPMethodOverridden(final Class className, final String methodName, final FPMethodArgs methodArgs) { - return AccessController - .doPrivileged(new PrivilegedAction() { - @Override - public Boolean run() { - return isFPMethodOverridden(methodName, className, - methodArgs.getMethodArguments(false), - methodArgs.getMethodArguments(true)); - } - }); + return isFPMethodOverridden(methodName, className, + methodArgs.getMethodArguments(false), + methodArgs.getMethodArguments(true)); } private static boolean isFPMethodOverridden(String method, diff --git a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java index f17804e624dcd..53ceea32668f2 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/HTMLEditorKit.java @@ -53,8 +53,6 @@ import java.lang.ref.WeakReference; import java.net.MalformedURLException; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Enumeration; import javax.accessibility.Accessible; @@ -471,22 +469,13 @@ public StyleSheet getStyleSheet() { /** * Fetch a resource relative to the HTMLEditorKit classfile. - * If this is called on 1.2 the loading will occur under the - * protection of a doPrivileged call to allow the HTMLEditorKit - * to function when used in an applet. * * @param name the name of the resource, relative to the * HTMLEditorKit class * @return a stream representing the resource */ - @SuppressWarnings("removal") static InputStream getResourceAsStream(final String name) { - return AccessController.doPrivileged( - new PrivilegedAction() { - public InputStream run() { - return HTMLEditorKit.class.getResourceAsStream(name); - } - }); + return HTMLEditorKit.class.getResourceAsStream(name); } /** diff --git a/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java b/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java index 0dbeb9967789e..bf360574f6d1f 100644 --- a/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java +++ b/src/java.desktop/share/classes/javax/swing/text/html/parser/ParserDelegator.java @@ -35,8 +35,6 @@ import java.io.Reader; import java.io.Serial; import java.io.Serializable; -import java.security.AccessController; -import java.security.PrivilegedAction; /** * Responsible for starting up a new DocumentParser @@ -131,14 +129,8 @@ public void parse(Reader r, HTMLEditorKit.ParserCallback cb, boolean ignoreCharS * ParserDelegator class. * @return a stream representing the resource */ - @SuppressWarnings("removal") static InputStream getResourceAsStream(final String name) { - return AccessController.doPrivileged( - new PrivilegedAction() { - public InputStream run() { - return ParserDelegator.class.getResourceAsStream(name); - } - }); + return ParserDelegator.class.getResourceAsStream(name); } @Serial diff --git a/src/java.desktop/share/classes/javax/swing/text/rtf/RTFReader.java b/src/java.desktop/share/classes/javax/swing/text/rtf/RTFReader.java index 60cfd585c732e..3afaf828417f4 100644 --- a/src/java.desktop/share/classes/javax/swing/text/rtf/RTFReader.java +++ b/src/java.desktop/share/classes/javax/swing/text/rtf/RTFReader.java @@ -37,8 +37,6 @@ import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Dictionary; import java.util.Enumeration; import java.util.HashMap; @@ -644,13 +642,7 @@ public void setCharacterSet(String name) { char[] set = characterSets.get(name); if (set == null) { - @SuppressWarnings("removal") - InputStream charsetStream = AccessController.doPrivileged( - new PrivilegedAction() { - public InputStream run() { - return RTFReader.class.getResourceAsStream("charsets/" + name + ".txt"); - } - }); + InputStream charsetStream = RTFReader.class.getResourceAsStream("charsets/" + name + ".txt"); set = readCharset(charsetStream); defineCharacterSet(name, set); } diff --git a/src/java.desktop/share/native/common/java2d/opengl/OGLSurfaceData.c b/src/java.desktop/share/native/common/java2d/opengl/OGLSurfaceData.c index 59773ec666d32..36163e885edf0 100644 --- a/src/java.desktop/share/native/common/java2d/opengl/OGLSurfaceData.c +++ b/src/java.desktop/share/native/common/java2d/opengl/OGLSurfaceData.c @@ -542,7 +542,7 @@ OGLSD_SetNativeDimensions(JNIEnv *env, OGLSDOps *oglsdo, } JNU_SetFieldByName(env, NULL, sdObject, "nativeWidth", "I", width); - if (!((*env)->ExceptionOccurred(env))) { + if (!((*env)->ExceptionCheck(env))) { JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height); } diff --git a/src/java.desktop/share/native/libawt/awt/image/awt_parseImage.c b/src/java.desktop/share/native/libawt/awt/image/awt_parseImage.c index c8d1464f8aabd..29690b9c9a7b5 100644 --- a/src/java.desktop/share/native/libawt/awt/image/awt_parseImage.c +++ b/src/java.desktop/share/native/libawt/awt/image/awt_parseImage.c @@ -984,7 +984,7 @@ int awt_getPixels(JNIEnv *env, RasterS_t *rasterP, void *bufferP) { 0, y, w, maxLines, jdata, jdatabuffer); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->DeleteLocalRef(env, jdata); return -1; } @@ -1104,7 +1104,7 @@ int awt_setPixels(JNIEnv *env, RasterS_t *rasterP, void *bufferP) { 0, y, w, maxLines, jdata, jdatabuffer); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->DeleteLocalRef(env, jdata); return -1; } diff --git a/src/java.desktop/share/native/libawt/awt/image/gif/gifdecoder.c b/src/java.desktop/share/native/libawt/awt/image/gif/gifdecoder.c index 02b10bef76f85..964c2f4a4c110 100644 --- a/src/java.desktop/share/native/libawt/awt/image/gif/gifdecoder.c +++ b/src/java.desktop/share/native/libawt/awt/image/gif/gifdecoder.c @@ -237,7 +237,7 @@ Java_sun_awt_image_GifImageDecoder_parseImage(JNIEnv *env, len = (*env)->CallIntMethod(env, this, readID, blockh, remain, blockLength + 1); if (len > blockLength + 1) len = blockLength + 1; - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { return 0; } GET_ARRAYS(); @@ -314,10 +314,10 @@ Java_sun_awt_image_GifImageDecoder_parseImage(JNIEnv *env, } if ((*env)->CallIntMethod(env, this, readID, blockh, 0, blockLength + 1) != 0 - || (*env)->ExceptionOccurred(env)) + || (*env)->ExceptionCheck(env)) { /* quietly accept truncated GIF images */ - return (!(*env)->ExceptionOccurred(env)); + return (!(*env)->ExceptionCheck(env)); } GET_ARRAYS(); blockLength = block[blockLength]; @@ -412,7 +412,7 @@ Java_sun_awt_image_GifImageDecoder_parseImage(JNIEnv *env, relx, rely + y, width, passht, raslineh, cmh); - if (count <= 0 || (*env)->ExceptionOccurred(env)) { + if (count <= 0 || (*env)->ExceptionCheck(env)) { /* Nobody is listening any more. */ if (verbose) { fprintf(stdout, "Orphan gif decoder quitting\n"); diff --git a/src/java.desktop/share/native/libawt/awt/medialib/awt_ImagingLib.c b/src/java.desktop/share/native/libawt/awt/medialib/awt_ImagingLib.c index 7e382eec175c0..b617081422304 100644 --- a/src/java.desktop/share/native/libawt/awt/medialib/awt_ImagingLib.c +++ b/src/java.desktop/share/native/libawt/awt/medialib/awt_ImagingLib.c @@ -2017,7 +2017,7 @@ cvtCustomToDefault(JNIEnv *env, BufImageS_t *imageP, int component, g_BImgGetRGBMID, 0, y, w, numLines, jpixels, 0, w); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->DeleteLocalRef(env, jpixels); return -1; } @@ -2093,7 +2093,7 @@ cvtDefaultToCustom(JNIEnv *env, BufImageS_t *imageP, int component, (*env)->CallVoidMethod(env, imageP->jimage, g_BImgSetRGBMID, 0, y, w, numLines, jpixels, 0, w); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->DeleteLocalRef(env, jpixels); return -1; } diff --git a/src/java.desktop/share/native/libawt/java2d/SurfaceData.c b/src/java.desktop/share/native/libawt/java2d/SurfaceData.c index 4d96a2d3ff40d..fbed597096bac 100644 --- a/src/java.desktop/share/native/libawt/java2d/SurfaceData.c +++ b/src/java.desktop/share/native/libawt/java2d/SurfaceData.c @@ -118,7 +118,7 @@ GetSDOps(JNIEnv *env, jobject sData, jboolean callSetup) } ops = (SurfaceDataOps *)JNU_GetLongFieldAsPtr(env, sData, pDataID); if (ops == NULL) { - if (!(*env)->ExceptionOccurred(env) && + if (!(*env)->ExceptionCheck(env) && !(*env)->IsInstanceOf(env, sData, pNullSurfaceDataClass)) { if (!(*env)->GetBooleanField(env, sData, validID)) { diff --git a/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc b/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc index f2c08541d7c3d..caeca3e634657 100644 --- a/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc +++ b/src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc @@ -50,7 +50,7 @@ hb_jdk_get_nominal_glyph (hb_font_t *font HB_UNUSED, jobject font2D = jdkFontInfo->font2D; *glyph = (hb_codepoint_t)env->CallIntMethod( font2D, sunFontIDs.f2dCharToGlyphMID, unicode); - if (env->ExceptionOccurred()) + if (env->ExceptionCheck()) { env->ExceptionClear(); } @@ -75,7 +75,7 @@ hb_jdk_get_variation_glyph (hb_font_t *font HB_UNUSED, *glyph = (hb_codepoint_t)env->CallIntMethod( font2D, sunFontIDs.f2dCharToVariationGlyphMID, unicode, variation_selector); - if (env->ExceptionOccurred()) + if (env->ExceptionCheck()) { env->ExceptionClear(); } diff --git a/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c b/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c index 4e2ba2a35c5d3..a764eb1ae3bbb 100644 --- a/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c +++ b/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c @@ -575,7 +575,7 @@ sun_jpeg_output_message (j_common_ptr cinfo) (*env)->CallVoidMethod(env, theObject, JPEGImageReader_warningWithMessageID, string); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit(cinfo); } @@ -585,7 +585,7 @@ sun_jpeg_output_message (j_common_ptr cinfo) (*env)->CallVoidMethod(env, theObject, JPEGImageWriter_warningWithMessageID, string); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, (const JOCTET **)(&dest->next_output_byte))) { cinfo->err->error_exit(cinfo); @@ -625,7 +625,7 @@ static void imageio_set_stream(JNIEnv *env, if (setjmp(jerr->setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error while aborting. */ - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message) (cinfo, buffer); @@ -651,7 +651,7 @@ static void imageio_reset(JNIEnv *env, if (setjmp(jerr->setjmp_buffer)) { /* If we get here, the JPEG code has signaled an error while aborting. */ - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message) (cinfo, buffer); JNU_ThrowByName(env, "javax/imageio/IIOException", buffer); @@ -969,7 +969,7 @@ imageio_fill_input_buffer(j_decompress_ptr cinfo) if ((ret > 0) && ((unsigned int)ret > sb->bufferLength)) { ret = (int)sb->bufferLength; } - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -992,7 +992,7 @@ imageio_fill_input_buffer(j_decompress_ptr cinfo) (*env)->CallVoidMethod(env, reader, JPEGImageReader_warningOccurredID, READ_NO_EOI); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -1067,7 +1067,7 @@ imageio_fill_suspended_buffer(j_decompress_ptr cinfo) sb->hstreamBuffer, offset, buflen); if ((ret > 0) && ((unsigned int)ret > buflen)) ret = (int)buflen; - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -1083,7 +1083,7 @@ imageio_fill_suspended_buffer(j_decompress_ptr cinfo) (*env)->CallVoidMethod(env, reader, JPEGImageReader_warningOccurredID, READ_NO_EOI); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -1168,7 +1168,7 @@ imageio_skip_input_data(j_decompress_ptr cinfo, long num_bytes) input, JPEGImageReader_skipInputBytesID, (jlong) num_bytes); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -1187,7 +1187,7 @@ imageio_skip_input_data(j_decompress_ptr cinfo, long num_bytes) JPEGImageReader_warningOccurredID, READ_NO_EOI); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -1221,7 +1221,7 @@ imageio_term_source(j_decompress_ptr cinfo) JPEGImageReader_pushBackID, src->bytes_in_buffer); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -1660,7 +1660,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader /* If we get here, the JPEG code has signaled an error while reading the header. */ RELEASE_ARRAYS(env, data, src->next_input_byte); - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message) ((struct jpeg_common_struct *) cinfo, buffer); @@ -1819,7 +1819,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader cinfo->out_color_space, cinfo->num_components, profileData); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -1988,7 +1988,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage /* If we get here, the JPEG code has signaled an error while reading. */ RELEASE_ARRAYS(env, data, src->next_input_byte); - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message) ((struct jpeg_common_struct *) cinfo, buffer); @@ -2074,7 +2074,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage (*env)->CallVoidMethod(env, this, JPEGImageReader_passStartedID, cinfo->input_scan_number-1); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -2084,7 +2084,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage (*env)->CallVoidMethod(env, this, JPEGImageReader_passStartedID, 0); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -2144,7 +2144,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage targetLine++, progressive); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -2178,7 +2178,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage RELEASE_ARRAYS(env, data, src->next_input_byte); (*env)->CallVoidMethod(env, this, JPEGImageReader_passCompleteID); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, &(src->next_input_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); } @@ -2336,7 +2336,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_resetReader become more flexible. */ - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionClear(env); } } else { @@ -2415,7 +2415,7 @@ imageio_empty_output_buffer (j_compress_ptr cinfo) sb->hstreamBuffer, 0, sb->bufferLength); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, (const JOCTET **)(&dest->next_output_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); @@ -2458,7 +2458,7 @@ imageio_term_destination (j_compress_ptr cinfo) 0, datacount); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, (const JOCTET **)(&dest->next_output_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); @@ -2669,7 +2669,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeTables /* If we get here, the JPEG code has signaled an error while writing. */ RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte)); - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message) ((j_common_ptr) cinfo, buffer); @@ -2892,7 +2892,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeImage /* If we get here, the JPEG code has signaled an error while writing. */ RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte)); - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message) ((j_common_ptr) cinfo, buffer); @@ -3039,7 +3039,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeImage (*env)->CallVoidMethod(env, this, JPEGImageWriter_writeMetadataID); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, (const JOCTET **)(&dest->next_output_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); @@ -3059,7 +3059,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageWriter_writeImage this, JPEGImageWriter_grabPixelsID, targetLine); - if ((*env)->ExceptionOccurred(env) + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, data, (const JOCTET **)(&dest->next_output_byte))) { cinfo->err->error_exit((j_common_ptr) cinfo); diff --git a/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c b/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c index a01a6bbd58e6b..889c7a9c0f6d1 100644 --- a/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c +++ b/src/java.desktop/share/native/libjavajpeg/jpegdecoder.c @@ -298,7 +298,7 @@ sun_jpeg_fill_input_buffer(j_decompress_ptr cinfo) ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID, src->hInputBuffer, 0, buflen); if (ret > buflen) ret = buflen; - if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } if (ret <= 0) { @@ -334,7 +334,7 @@ sun_jpeg_fill_suspended_buffer(j_decompress_ptr cinfo) RELEASE_ARRAYS(env, src); ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_availableID); - if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } if (ret < 0 || (unsigned int)ret <= src->remaining_skip) { @@ -359,7 +359,7 @@ sun_jpeg_fill_suspended_buffer(j_decompress_ptr cinfo) ret = (*env)->CallIntMethod(env, src->hInputStream, InputStream_readID, src->hInputBuffer, offset, buflen); if ((ret > 0) && ((unsigned int)ret > buflen)) ret = (int)buflen; - if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { + if ((*env)->ExceptionCheck(env) || !GET_ARRAYS(env, src)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } if (ret <= 0) { @@ -439,7 +439,7 @@ sun_jpeg_skip_input_data(j_decompress_ptr cinfo, long num_bytes) InputStream_readID, src->hInputBuffer, 0, buflen); if (ret > buflen) ret = buflen; - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); } if (ret < 0) { @@ -538,7 +538,7 @@ Java_sun_awt_image_JPEGImageDecoder_readImage(JNIEnv *env, */ jpeg_destroy_decompress(&cinfo); RELEASE_ARRAYS(env, &jsrc); - if (!(*env)->ExceptionOccurred(env)) { + if (!(*env)->ExceptionCheck(env)) { char buffer[JMSG_LENGTH_MAX]; (*cinfo.err->format_message) ((struct jpeg_common_struct *) &cinfo, buffer); @@ -584,7 +584,7 @@ Java_sun_awt_image_JPEGImageDecoder_readImage(JNIEnv *env, ret = (*env)->CallBooleanMethod(env, this, sendHeaderInfoID, cinfo.image_width, cinfo.image_height, grayscale, hasalpha, buffered_mode); - if ((*env)->ExceptionOccurred(env) || !ret) { + if ((*env)->ExceptionCheck(env) || !ret) { /* No more interest in this image... */ jpeg_destroy_decompress(&cinfo); return; @@ -694,7 +694,7 @@ Java_sun_awt_image_JPEGImageDecoder_readImage(JNIEnv *env, jsrc.hOutputBuffer, cinfo.output_scanline - 1); } - if ((*env)->ExceptionOccurred(env) || !ret || + if ((*env)->ExceptionCheck(env) || !ret || !GET_ARRAYS(env, &jsrc)) { /* No more interest in this image... */ jpeg_destroy_decompress(&cinfo); diff --git a/src/java.desktop/share/native/libjsound/PortMixer.c b/src/java.desktop/share/native/libjsound/PortMixer.c index c7f35b37b6904..23f08d8dca60c 100644 --- a/src/java.desktop/share/native/libjsound/PortMixer.c +++ b/src/java.desktop/share/native/libjsound/PortMixer.c @@ -209,7 +209,7 @@ void* PORT_NewBooleanControl(void* creatorV, void* controlID, char* type) { if (!ctrl) { ERROR0("PORT_NewBooleanControl: ctrl is NULL\n"); } - if ((*creator->env)->ExceptionOccurred(creator->env)) { + if ((*creator->env)->ExceptionCheck(creator->env)) { ERROR0("PORT_NewBooleanControl: ExceptionOccurred!\n"); } TRACE0("PORT_NewBooleanControl succeeded\n"); @@ -264,7 +264,7 @@ void* PORT_NewCompoundControl(void* creatorV, char* type, void** controls, int c if (!ctrl) { ERROR0("PORT_NewCompoundControl: ctrl is NULL\n"); } - if ((*creator->env)->ExceptionOccurred(creator->env)) { + if ((*creator->env)->ExceptionCheck(creator->env)) { ERROR0("PORT_NewCompoundControl: ExceptionOccurred!\n"); } TRACE0("PORT_NewCompoundControl succeeded\n"); @@ -327,7 +327,7 @@ void* PORT_NewFloatControl(void* creatorV, void* controlID, char* type, if (!ctrl) { ERROR0("PORT_NewFloatControl: ctrl is NULL!\n"); } - if ((*creator->env)->ExceptionOccurred(creator->env)) { + if ((*creator->env)->ExceptionCheck(creator->env)) { ERROR0("PORT_NewFloatControl: ExceptionOccurred!\n"); } TRACE1("PORT_NewFloatControl succeeded %p\n", (void*) ctrl); @@ -339,7 +339,7 @@ int PORT_AddControl(void* creatorV, void* control) { TRACE1("PORT_AddControl %p\n", (void*) control); (*creator->env)->CallVoidMethod(creator->env, creator->vector, creator->vectorAddElement, (jobject) control); - if ((*creator->env)->ExceptionOccurred(creator->env)) { + if ((*creator->env)->ExceptionCheck(creator->env)) { ERROR0("PORT_AddControl: ExceptionOccurred!\n"); } TRACE0("PORT_AddControl succeeded\n"); diff --git a/src/java.desktop/share/native/libsplashscreen/java_awt_SplashScreen.c b/src/java.desktop/share/native/libsplashscreen/java_awt_SplashScreen.c index d71e261decd80..259afd94acbea 100644 --- a/src/java.desktop/share/native/libsplashscreen/java_awt_SplashScreen.c +++ b/src/java.desktop/share/native/libsplashscreen/java_awt_SplashScreen.c @@ -122,7 +122,7 @@ Java_java_awt_SplashScreen__1getBounds(JNIEnv * env, jclass thisClass, if (clazz && mid) { bounds = (*env)->NewObject(env, clazz, mid, splash->x, splash->y, splash->width, splash->height); - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { bounds = NULL; (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); diff --git a/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c b/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c index 33d2aeb66bbc1..51c425c8c5937 100644 --- a/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c +++ b/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c @@ -1287,7 +1287,7 @@ Java_sun_awt_X11GraphicsDevice_pGetBounds(JNIEnv *env, jobject this, jint screen xwa.width, xwa.height); } - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { return NULL; } } diff --git a/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c b/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c index f9fe7b2b12613..94468d548ef96 100644 --- a/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c +++ b/src/java.desktop/unix/native/libawt_xawt/awt/awt_InputMethod.c @@ -1328,7 +1328,7 @@ static void DestroyXIMCallback(XIM im, XPointer client_data, XPointer call_data) x11InputMethodGRefListHead->inputMethodGRef) == NULL) { /* Clear possible exceptions */ - if ((*env)->ExceptionOccurred(env)) { + if ((*env)->ExceptionCheck(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } diff --git a/src/java.desktop/unix/native/libawt_xawt/awt/awt_util.c b/src/java.desktop/unix/native/libawt_xawt/awt/awt_util.c index d61c59b5915fb..67b1ad2bc45e8 100644 --- a/src/java.desktop/unix/native/libawt_xawt/awt/awt_util.c +++ b/src/java.desktop/unix/native/libawt_xawt/awt/awt_util.c @@ -96,7 +96,7 @@ awtJNI_ThreadYield(JNIEnv *env) { } /* threadClass == NULL*/ (*env)->CallStaticVoidMethod(env, threadClass, yieldMethodID); - DASSERT(!((*env)->ExceptionOccurred(env))); + DASSERT(!((*env)->ExceptionCheck(env))); if ((*env)->ExceptionCheck(env)) { return JNI_FALSE; } diff --git a/src/java.desktop/unix/native/libawt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c b/src/java.desktop/unix/native/libawt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c index d778c0bf6d65a..db6acc0f3d18e 100644 --- a/src/java.desktop/unix/native/libawt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c +++ b/src/java.desktop/unix/native/libawt_xawt/awt/sun_awt_X11_GtkFileDialogPeer.c @@ -85,7 +85,7 @@ static gboolean filenameFilterCallback(const GtkFileFilterInfo * filter_info, gp static void quit(JNIEnv * env, jobject jpeer, gboolean isSignalHandler) { jthrowable pendingException; - if (pendingException = (*env)->ExceptionOccurred(env)) { + if ((pendingException = (*env)->ExceptionOccurred(env)) != NULL) { (*env)->ExceptionClear(env); } diff --git a/src/java.desktop/windows/native/libawt/java2d/d3d/D3DSurfaceData.cpp b/src/java.desktop/windows/native/libawt/java2d/d3d/D3DSurfaceData.cpp index 9732d4d046b80..1e3baa1c686c5 100644 --- a/src/java.desktop/windows/native/libawt/java2d/d3d/D3DSurfaceData.cpp +++ b/src/java.desktop/windows/native/libawt/java2d/d3d/D3DSurfaceData.cpp @@ -62,7 +62,7 @@ void D3DSD_SetNativeDimensions(JNIEnv *env, D3DSDOps *d3dsdo) { } JNU_SetFieldByName(env, NULL, sdObject, "nativeWidth", "I", width); - if (!(env->ExceptionOccurred())) { + if (!(env->ExceptionCheck())) { JNU_SetFieldByName(env, NULL, sdObject, "nativeHeight", "I", height); } diff --git a/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp b/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp index 2489ac21952d2..406a82a022f35 100644 --- a/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp +++ b/src/java.desktop/windows/native/libawt/java2d/windows/GDIWindowSurfaceData.cpp @@ -372,7 +372,7 @@ Java_sun_java2d_windows_GDIWindowSurfaceData_initOps(JNIEnv *env, jobject wsd, wsdo->invalid = JNI_FALSE; wsdo->lockType = WIN32SD_LOCK_UNLOCKED; wsdo->peer = env->NewWeakGlobalRef(peer); - if (env->ExceptionOccurred()) { + if (env->ExceptionCheck()) { return; } wsdo->depth = depth; diff --git a/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java b/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java index fce6d9327352e..48f015d5393b7 100644 --- a/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, 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 @@ -28,6 +28,7 @@ import java.io.*; import java.util.ArrayList; import java.util.Locale; +import java.util.Set; import java.util.Vector; import java.util.Hashtable; import java.util.concurrent.locks.ReentrantLock; @@ -86,32 +87,23 @@ public final class LdapClient implements PooledConnection { static final boolean caseIgnore = true; // Default list of binary attributes - private static final Hashtable defaultBinaryAttrs = - new Hashtable<>(23,0.75f); - static { - defaultBinaryAttrs.put("userpassword", Boolean.TRUE); //2.5.4.35 - defaultBinaryAttrs.put("javaserializeddata", Boolean.TRUE); - //1.3.6.1.4.1.42.2.27.4.1.8 - defaultBinaryAttrs.put("javaserializedobject", Boolean.TRUE); - // 1.3.6.1.4.1.42.2.27.4.1.2 - defaultBinaryAttrs.put("jpegphoto", Boolean.TRUE); - //0.9.2342.19200300.100.1.60 - defaultBinaryAttrs.put("audio", Boolean.TRUE); //0.9.2342.19200300.100.1.55 - defaultBinaryAttrs.put("thumbnailphoto", Boolean.TRUE); - //1.3.6.1.4.1.1466.101.120.35 - defaultBinaryAttrs.put("thumbnaillogo", Boolean.TRUE); - //1.3.6.1.4.1.1466.101.120.36 - defaultBinaryAttrs.put("usercertificate", Boolean.TRUE); //2.5.4.36 - defaultBinaryAttrs.put("cacertificate", Boolean.TRUE); //2.5.4.37 - defaultBinaryAttrs.put("certificaterevocationlist", Boolean.TRUE); - //2.5.4.39 - defaultBinaryAttrs.put("authorityrevocationlist", Boolean.TRUE); //2.5.4.38 - defaultBinaryAttrs.put("crosscertificatepair", Boolean.TRUE); //2.5.4.40 - defaultBinaryAttrs.put("photo", Boolean.TRUE); //0.9.2342.19200300.100.1.7 - defaultBinaryAttrs.put("personalsignature", Boolean.TRUE); - //0.9.2342.19200300.100.1.53 - defaultBinaryAttrs.put("x500uniqueidentifier", Boolean.TRUE); //2.5.4.45 - } + private static final Set defaultBinaryAttrs = Set.of( + "userpassword", //2.5.4.35 + "javaserializeddata", //1.3.6.1.4.1.42.2.27.4.1.8 + "javaserializedobject", //1.3.6.1.4.1.42.2.27.4.1.2 + "jpegphoto", //0.9.2342.19200300.100.1.60 + "audio", //0.9.2342.19200300.100.1.55 + "thumbnailphoto", //1.3.6.1.4.1.1466.101.120.35 + "thumbnaillogo", //1.3.6.1.4.1.1466.101.120.36 + "usercertificate", //2.5.4.36 + "cacertificate", //2.5.4.37 + "certificaterevocationlist",//2.5.4.39 + "authorityrevocationlist", //2.5.4.38 + "crosscertificatepair", //2.5.4.40 + "photo", //0.9.2342.19200300.100.1.7 + "personalsignature", //0.9.2342.19200300.100.1.53 + "x500uniqueidentifier" //2.5.4.45 + ); private static final String DISCONNECT_OID = "1.3.6.1.4.1.1466.20036"; @@ -790,7 +782,7 @@ private boolean isBinaryValued(String attrid, String id = attrid.toLowerCase(Locale.ENGLISH); return id.contains(";binary") || - defaultBinaryAttrs.containsKey(id) || + defaultBinaryAttrs.contains(id) || ((binaryAttrs != null) && (binaryAttrs.containsKey(id))); } diff --git a/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java b/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java index 1d7565e00e3ad..53a20b9959405 100644 --- a/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/VersionHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, 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 @@ -25,8 +25,6 @@ package com.sun.jndi.ldap; -import jdk.internal.access.SharedSecrets; - import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; @@ -109,14 +107,8 @@ Class loadClass(String className) throws ClassNotFoundException { return Class.forName(className, true, getContextClassLoader()); } - @SuppressWarnings("removal") Thread createThread(Runnable r) { - AccessControlContext acc = AccessController.getContext(); - // 4290486: doPrivileged is needed to create a thread in - // an environment that restricts "modifyThreadGroup". - PrivilegedAction act = - () -> SharedSecrets.getJavaLangAccess().newThreadWithAcc(r, acc); - return AccessController.doPrivileged(act); + return new Thread(r); } @SuppressWarnings("removal") diff --git a/src/java.net.http/share/classes/java/net/http/HttpClient.java b/src/java.net.http/share/classes/java/net/http/HttpClient.java index c1269eed8238f..fbd2e2aba3695 100644 --- a/src/java.net.http/share/classes/java/net/http/HttpClient.java +++ b/src/java.net.http/share/classes/java/net/http/HttpClient.java @@ -37,9 +37,6 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.ProxySelector; -import java.net.URLPermission; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.time.Duration; import java.util.Objects; import java.util.Optional; diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/Exchange.java b/src/java.net.http/share/classes/jdk/internal/net/http/Exchange.java index 1ff1e5f47330f..71e4e05d2c56f 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/Exchange.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/Exchange.java @@ -26,25 +26,15 @@ package jdk.internal.net.http; import java.io.IOException; -import java.net.InetSocketAddress; import java.net.ProtocolException; -import java.net.ProxySelector; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLPermission; -import java.security.AccessControlContext; import java.time.Duration; -import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.net.http.HttpClient; -import java.net.http.HttpHeaders; import java.net.http.HttpResponse; import java.net.http.HttpTimeoutException; @@ -53,20 +43,11 @@ import jdk.internal.net.http.common.Utils; import jdk.internal.net.http.common.Log; -import static jdk.internal.net.http.common.Utils.permissionForProxy; - /** * One request/response exchange (handles 100/101 intermediate response also). * depth field used to track number of times a new request is being sent * for a given API request. If limit exceeded exception is thrown. * - * Security check is performed here: - * - uses AccessControlContext captured at API level - * - checks for appropriate URLPermission for request - * - if permission allowed, grants equivalent SocketPermission to call - * - in case of direct HTTP proxy, checks additionally for access to proxy - * (CONNECT proxying uses its own Exchange, so check done there) - * */ final class Exchange { @@ -83,8 +64,6 @@ final class Exchange { // used to record possible cancellation raised before the exchImpl // has been established. private volatile IOException failed; - @SuppressWarnings("removal") - final AccessControlContext acc; final MultiExchange multi; final Executor parentExecutor; volatile boolean upgrading; // to HTTP/2 @@ -103,22 +82,6 @@ final class Exchange { this.upgrading = false; this.client = multi.client(); this.multi = multi; - this.acc = multi.acc; - this.parentExecutor = multi.executor; - this.pushGroup = multi.pushGroup; - this.dbgTag = "Exchange"; - } - - /* If different AccessControlContext to be used */ - Exchange(HttpRequestImpl request, - MultiExchange multi, - @SuppressWarnings("removal") AccessControlContext acc) - { - this.request = request; - this.acc = acc; - this.upgrading = false; - this.client = multi.client(); - this.multi = multi; this.parentExecutor = multi.executor; this.pushGroup = multi.pushGroup; this.dbgTag = "Exchange"; @@ -338,7 +301,7 @@ private void checkCancelled() { } } - CompletableFuture checkCancelled(CompletableFuture cf, HttpConnection connection) { + CompletableFuture checkCancelled(CompletableFuture cf, HttpConnection connection) { return cf.handle((r,t) -> { if (t == null) { if (multi.requestCancelled()) { @@ -354,7 +317,7 @@ CompletableFuture checkCancelled(CompletableFuture cf, HttpConnection } catch (Throwable x) { if (debug.on()) debug.log("Failed to close connection", x); } - return MinimalFuture.failedFuture(t); + return MinimalFuture.failedFuture(t); } } } @@ -422,15 +385,6 @@ public CompletableFuture responseAsync() { return responseAsyncImpl(null); } - CompletableFuture responseAsyncImpl(HttpConnection connection) { - SecurityException e = checkPermissions(); - if (e != null) { - return MinimalFuture.failedFuture(e); - } else { - return responseAsyncImpl0(connection); - } - } - // check whether the headersSentCF was completed exceptionally with // ProxyAuthorizationRequired. If so the Response embedded in the // exception is returned. Otherwise we proceed. @@ -584,7 +538,7 @@ private CompletableFuture ignore1xxResponse(final Response rsp) { } } - CompletableFuture responseAsyncImpl0(HttpConnection connection) { + CompletableFuture responseAsyncImpl(HttpConnection connection) { Function, CompletableFuture> after407Check; bodyIgnored = null; if (request.expectContinue()) { @@ -735,109 +689,6 @@ HttpResponse.BodySubscriber ignoreBody(HttpResponse.ResponseInfo hdrs) { return MinimalFuture.completedFuture(resp); } - private URI getURIForSecurityCheck() { - URI u; - String method = request.method(); - InetSocketAddress authority = request.authority(); - URI uri = request.uri(); - - // CONNECT should be restricted at API level - if (method.equalsIgnoreCase("CONNECT")) { - try { - u = new URI("socket", - null, - authority.getHostString(), - authority.getPort(), - null, - null, - null); - } catch (URISyntaxException e) { - throw new InternalError(e); // shouldn't happen - } - } else { - u = uri; - } - return u; - } - - /** - * Returns the security permission required for the given details. - * If method is CONNECT, then uri must be of form "scheme://host:port" - */ - private static URLPermission permissionForServer(URI uri, - String method, - Map> headers) { - if (method.equals("CONNECT")) { - return new URLPermission(uri.toString(), "CONNECT"); - } else { - return Utils.permissionForServer(uri, method, headers.keySet().stream()); - } - } - - /** - * Performs the necessary security permission checks required to retrieve - * the response. Returns a security exception representing the denied - * permission, or null if all checks pass or there is no security manager. - */ - private SecurityException checkPermissions() { - String method = request.method(); - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm == null || method.equals("CONNECT")) { - // tunneling will have a null acc, which is fine. The proxy - // permission check will have already been preformed. - return null; - } - - HttpHeaders userHeaders = request.getUserHeaders(); - URI u = getURIForSecurityCheck(); - URLPermission p = permissionForServer(u, method, userHeaders.map()); - - try { - assert acc != null; - sm.checkPermission(p, acc); - } catch (SecurityException e) { - return e; - } - String hostHeader = userHeaders.firstValue("Host").orElse(null); - if (hostHeader != null && !hostHeader.equalsIgnoreCase(u.getHost())) { - // user has set a Host header different to request URI - // must check that for URLPermission also - URI u1 = replaceHostInURI(u, hostHeader); - URLPermission p1 = permissionForServer(u1, method, userHeaders.map()); - try { - assert acc != null; - sm.checkPermission(p1, acc); - } catch (SecurityException e) { - return e; - } - } - ProxySelector ps = client.proxySelector(); - if (ps != null) { - if (!method.equals("CONNECT")) { - // a non-tunneling HTTP proxy. Need to check access - URLPermission proxyPerm = permissionForProxy(request.proxy()); - if (proxyPerm != null) { - try { - sm.checkPermission(proxyPerm, acc); - } catch (SecurityException e) { - return e; - } - } - } - } - return null; - } - - private static URI replaceHostInURI(URI u, String hostPort) { - StringBuilder sb = new StringBuilder(); - sb.append(u.getScheme()) - .append("://") - .append(hostPort) - .append(u.getRawPath()); - return URI.create(sb.toString()); - } - HttpClient.Version version() { return multi.version(); } diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java b/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java index c4157b3c74c9d..65e9210f9cb29 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientBuilderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -46,7 +46,6 @@ public class HttpClientBuilderImpl implements HttpClient.Builder { Authenticator authenticator; HttpClient.Version version; Executor executor; - // Security parameters SSLContext sslContext; SSLParameters sslParams; int priority = -1; diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java b/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java index e1f4ec16dcd46..4d7518d40545b 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpClientImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -48,10 +48,7 @@ import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -import java.security.AccessControlContext; -import java.security.AccessController; import java.security.NoSuchAlgorithmException; -import java.security.PrivilegedAction; import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.ArrayList; @@ -97,7 +94,6 @@ import jdk.internal.net.http.common.OperationTrackers.Trackable; import jdk.internal.net.http.common.OperationTrackers.Tracker; import jdk.internal.net.http.websocket.BuilderImpl; -import jdk.internal.misc.InnocuousThread; /** * Client implementation. Contains all configuration information and also @@ -131,16 +127,10 @@ private static final class DefaultThreadFactory implements ThreadFactory { namePrefix = "HttpClient-" + clientID + "-Worker-"; } - @SuppressWarnings("removal") @Override public Thread newThread(Runnable r) { String name = namePrefix + nextId.getAndIncrement(); - Thread t; - if (System.getSecurityManager() == null) { - t = new Thread(null, r, name, 0, false); - } else { - t = InnocuousThread.newThread(name, r); - } + Thread t = new Thread(null, r, name, 0, false); t.setDaemon(true); return t; } @@ -188,15 +178,9 @@ public void ensureExecutedAsync(Runnable command) { } } - @SuppressWarnings("removal") private void shutdown() { if (delegate instanceof ExecutorService service) { - PrivilegedAction action = () -> { - service.shutdown(); - return null; - }; - AccessController.doPrivileged(action, null, - new RuntimePermission("modifyThread")); + service.shutdown(); } } } @@ -336,7 +320,6 @@ static void abortPendingRequests(HttpClientImpl client, Throwable reason) { private final ConnectionPool connections; private final DelegatingExecutor delegatingExecutor; private final boolean isDefaultExecutor; - // Security parameters private final SSLContext sslContext; private final SSLParameters sslParams; private final SelectorManager selmgr; @@ -445,16 +428,6 @@ private HttpClientImpl(HttpClientBuilderImpl builder, SingleFacadeFactory facadeFactory) { id = CLIENT_IDS.incrementAndGet(); dbgTag = "HttpClientImpl(" + id +")"; - @SuppressWarnings("removal") - var sm = System.getSecurityManager(); - if (sm != null && builder.localAddr != null) { - // when a specific local address is configured, it will eventually - // lead to the SocketChannel.bind(...) call with an InetSocketAddress - // whose InetAddress is the local address and the port is 0. That ultimately - // leads to a SecurityManager.checkListen permission check for that port. - // so we do that security manager check here with port 0. - sm.checkListen(0); - } localAddr = builder.localAddr; if (builder.sslContext == null) { try { @@ -484,7 +457,7 @@ private HttpClientImpl(HttpClientBuilderImpl builder, Redirect.NEVER : builder.followRedirects; this.userProxySelector = builder.proxy; this.proxySelector = Optional.ofNullable(userProxySelector) - .orElseGet(HttpClientImpl::getDefaultProxySelector); + .orElseGet(ProxySelector::getDefault); if (debug.on()) debug.log("proxySelector is %s (user-supplied=%s)", this.proxySelector, userProxySelector != null); @@ -642,12 +615,6 @@ private static SSLParameters getDefaultParams(SSLContext ctx) { return params; } - @SuppressWarnings("removal") - private static ProxySelector getDefaultProxySelector() { - PrivilegedAction action = ProxySelector::getDefault; - return AccessController.doPrivileged(action); - } - // Returns the facade that was returned to the application code. // May be null if that facade is no longer referenced. final HttpClientFacade facade() { @@ -992,7 +959,6 @@ private void debugCompleted(String tag, long startNanos, HttpRequest req) { return sendAsync(userRequest, responseHandler, pushPromiseHandler, delegatingExecutor.delegate); } - @SuppressWarnings("removal") private CompletableFuture> sendAsync(HttpRequest userRequest, BodyHandler responseHandler, @@ -1012,11 +978,7 @@ private void debugCompleted(String tag, long startNanos, HttpRequest req) { return MinimalFuture.failedFuture(selmgr.selectorClosedException()); } - AccessControlContext acc = null; - if (System.getSecurityManager() != null) - acc = AccessController.getContext(); - - // Clone the, possibly untrusted, HttpRequest + // Clone the possibly untrusted HttpRequest HttpRequestImpl requestImpl = new HttpRequestImpl(userRequest, proxySelector); if (requestImpl.method().equals("CONNECT")) throw new IllegalArgumentException("Unsupported method CONNECT"); @@ -1049,8 +1011,7 @@ private void debugCompleted(String tag, long startNanos, HttpRequest req) { requestImpl, this, responseHandler, - pushPromiseHandler, - acc); + pushPromiseHandler); CompletableFuture> mexCf = mex.responseAsync(executor); CompletableFuture> res = mexCf.whenComplete((b,t) -> requestUnreference()); if (DEBUGELAPSED) { diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestImpl.java b/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestImpl.java index 839b6a6185d75..bb79403150858 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestImpl.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/HttpRequestImpl.java @@ -31,9 +31,6 @@ import java.net.Proxy; import java.net.ProxySelector; import java.net.URI; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.time.Duration; import java.util.List; import java.util.Locale; @@ -65,17 +62,13 @@ public class HttpRequestImpl extends HttpRequest implements WebSocketRequest { final boolean secure; final boolean expectContinue; private volatile boolean isWebSocket; - @SuppressWarnings("removal") - private volatile AccessControlContext acc; private final Duration timeout; // may be null private final Optional version; private volatile boolean userSetAuthorization; private volatile boolean userSetProxyAuthorization; private static String userAgent() { - PrivilegedAction pa = () -> System.getProperty("java.version"); - @SuppressWarnings("removal") - String version = AccessController.doPrivileged(pa); + String version = System.getProperty("java.version"); return "Java-http-client/" + version; } @@ -196,7 +189,6 @@ private HttpRequestImpl(URI uri, this.expectContinue = other.expectContinue; this.secure = uri.getScheme().toLowerCase(Locale.US).equals("https"); this.requestPublisher = mayHaveBody ? publisher(other) : null; // may be null - this.acc = other.acc; this.timeout = other.timeout; this.version = other.version(); this.authority = null; @@ -274,7 +266,6 @@ private HttpRequestImpl(HttpRequestImpl parent, HttpHeaders headers) this.expectContinue = parent.expectContinue; this.secure = parent.secure; this.requestPublisher = parent.requestPublisher; - this.acc = parent.acc; this.timeout = parent.timeout; this.version = parent.version; this.authority = null; @@ -395,7 +386,6 @@ public void setSystemHeader(String name, String value) { systemHeadersBuilder.setHeader(name, value); } - @SuppressWarnings("removal") InetSocketAddress getAddress() { URI uri = uri(); if (uri == null) { @@ -412,8 +402,7 @@ InetSocketAddress getAddress() { final String host = uri.getHost(); final int port = p; if (proxy() == null) { - PrivilegedAction pa = () -> new InetSocketAddress(host, port); - return AccessController.doPrivileged(pa); + return new InetSocketAddress(host, port); } else { return InetSocketAddress.createUnresolved(host, port); } diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/MultiExchange.java b/src/java.net.http/share/classes/jdk/internal/net/http/MultiExchange.java index 2c15a704ef978..a7fe5f19e0292 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/MultiExchange.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/MultiExchange.java @@ -30,7 +30,6 @@ import java.net.ConnectException; import java.net.http.HttpConnectTimeoutException; import java.time.Duration; -import java.security.AccessControlContext; import java.util.List; import java.util.ListIterator; import java.util.Objects; @@ -79,8 +78,6 @@ class MultiExchange implements Cancelable { private final HttpRequest userRequest; // the user request private final HttpRequestImpl request; // a copy of the user request private final ConnectTimeoutTracker connectTimeout; // null if no timeout - @SuppressWarnings("removal") - final AccessControlContext acc; final HttpClientImpl client; final HttpResponse.BodyHandler responseHandler; final HttpClientImpl.DelegatingExecutor executor; @@ -155,8 +152,7 @@ Duration getRemaining() { HttpRequestImpl requestImpl, HttpClientImpl client, HttpResponse.BodyHandler responseHandler, - PushPromiseHandler pushPromiseHandler, - @SuppressWarnings("removal") AccessControlContext acc) { + PushPromiseHandler pushPromiseHandler) { this.previous = null; this.userRequest = userRequest; this.request = requestImpl; @@ -164,15 +160,11 @@ Duration getRemaining() { this.previousreq = null; this.client = client; this.filters = client.filterChain(); - this.acc = acc; this.executor = client.theExecutor(); this.responseHandler = responseHandler; if (pushPromiseHandler != null) { - Executor ensureExecutedAsync = this.executor::ensureExecutedAsync; - Executor executor = acc == null - ? ensureExecutedAsync - : new PrivilegedExecutor(ensureExecutedAsync, acc); + Executor executor = this.executor::ensureExecutedAsync; this.pushGroup = new PushGroup<>(pushPromiseHandler, request, executor); } else { pushGroup = null; @@ -470,7 +462,7 @@ private CompletableFuture responseAsyncImpl() { previousreq = currentreq; currentreq = newrequest; retriedOnce = false; - setExchange(new Exchange<>(currentreq, this, acc)); + setExchange(new Exchange<>(currentreq, this)); return responseAsyncImpl(); }).thenCompose(Function.identity()); } }) diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/PlainHttpConnection.java b/src/java.net.http/share/classes/jdk/internal/net/http/PlainHttpConnection.java index 1b42801e9ba2b..747945701f8d8 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/PlainHttpConnection.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/PlainHttpConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -32,9 +32,6 @@ import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.locks.ReentrantLock; @@ -167,7 +164,6 @@ public void abort(IOException ioe) { } } - @SuppressWarnings("removal") @Override public CompletableFuture connectAsync(Exchange exchange) { CompletableFuture cf = new MinimalFuture<>(); @@ -191,14 +187,12 @@ public CompletableFuture connectAsync(Exchange exchange) { debug.log("binding to configured local address " + localAddr); } var sockAddr = new InetSocketAddress(localAddr, 0); - PrivilegedExceptionAction pa = () -> chan.bind(sockAddr); try { - AccessController.doPrivileged(pa); + chan.bind(sockAddr); if (debug.on()) { debug.log("bind completed " + localAddr); } - } catch (PrivilegedActionException e) { - var cause = e.getCause(); + } catch (IOException cause) { if (debug.on()) { debug.log("bind to " + localAddr + " failed: " + cause.getMessage()); } @@ -206,13 +200,7 @@ public CompletableFuture connectAsync(Exchange exchange) { } } - PrivilegedExceptionAction pa = - () -> chan.connect(Utils.resolveAddress(address)); - try { - finished = AccessController.doPrivileged(pa); - } catch (PrivilegedActionException e) { - throw e.getCause(); - } + finished = chan.connect(Utils.resolveAddress(address)); if (finished) { if (debug.on()) debug.log("connect finished without blocking"); if (connectionOpened()) { diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/PlainTunnelingConnection.java b/src/java.net.http/share/classes/jdk/internal/net/http/PlainTunnelingConnection.java index 4565514f577fe..80ca6ba8a3aad 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/PlainTunnelingConnection.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/PlainTunnelingConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -72,7 +72,7 @@ public CompletableFuture connectAsync(Exchange exchange) { assert client != null; HttpRequestImpl req = new HttpRequestImpl("CONNECT", address, proxyHeaders); MultiExchange mulEx = new MultiExchange<>(null, req, - client, discarding(), null, null); + client, discarding(), null); Exchange connectExchange = mulEx.getExchange(); return connectExchange diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/PrivilegedExecutor.java b/src/java.net.http/share/classes/jdk/internal/net/http/PrivilegedExecutor.java deleted file mode 100644 index 72518f2c4e805..0000000000000 --- a/src/java.net.http/share/classes/jdk/internal/net/http/PrivilegedExecutor.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2015, 2021, 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. - */ - -package jdk.internal.net.http; - -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Objects; -import java.util.concurrent.Executor; - -/** - * Executes tasks within a given access control context, and by a given executor. - */ -class PrivilegedExecutor implements Executor { - - /** The underlying executor. May be provided by the user. */ - final Executor executor; - /** The ACC to execute the tasks within. */ - @SuppressWarnings("removal") - final AccessControlContext acc; - - public PrivilegedExecutor(Executor executor, @SuppressWarnings("removal") AccessControlContext acc) { - Objects.requireNonNull(executor); - Objects.requireNonNull(acc); - this.executor = executor; - this.acc = acc; - } - - private static class PrivilegedRunnable implements Runnable { - private final Runnable r; - @SuppressWarnings("removal") - private final AccessControlContext acc; - PrivilegedRunnable(Runnable r, @SuppressWarnings("removal") AccessControlContext acc) { - this.r = r; - this.acc = acc; - } - @SuppressWarnings("removal") - @Override - public void run() { - PrivilegedAction pa = () -> { r.run(); return null; }; - AccessController.doPrivileged(pa, acc); - } - } - - @Override - public void execute(Runnable r) { - executor.execute(new PrivilegedRunnable(r, acc)); - } -} diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java b/src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java index cfb0a20fe94ca..ecf88eb656619 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/RequestPublishers.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, 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 @@ -27,7 +27,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.io.UncheckedIOException; @@ -37,11 +36,6 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.Permission; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -229,11 +223,6 @@ public void subscribe(Flow.Subscriber subscriber) { /** * Publishes the content of a given file. - *

- * Privileged actions are performed within a limited doPrivileged that only - * asserts the specific, read, file permission that was checked during the - * construction of this FilePublisher. This only applies if the file system - * that created the file provides interoperability with {@code java.io.File}. */ public static class FilePublisher implements BodyPublisher { @@ -241,62 +230,27 @@ public static class FilePublisher implements BodyPublisher { private final long length; private final Function inputStreamSupplier; - private static String pathForSecurityCheck(Path path) { - return path.toFile().getPath(); - } - /** * Factory for creating FilePublisher. - * - * Permission checks are performed here before construction of the - * FilePublisher. Permission checking and construction are deliberately - * and tightly co-located. */ public static FilePublisher create(Path path) throws FileNotFoundException { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - FilePermission filePermission = null; boolean defaultFS = true; try { - String fn = pathForSecurityCheck(path); - if (sm != null) { - FilePermission readPermission = new FilePermission(fn, "read"); - sm.checkPermission(readPermission); - filePermission = readPermission; - } + path.toFile().getPath(); } catch (UnsupportedOperationException uoe) { + // path not associated with the default file system provider defaultFS = false; - // Path not associated with the default file system - // Test early if an input stream can still be obtained - try { - if (sm != null) { - Files.newInputStream(path).close(); - } - } catch (IOException ioe) { - if (ioe instanceof FileNotFoundException) { - throw (FileNotFoundException) ioe; - } else { - var ex = new FileNotFoundException(ioe.getMessage()); - ex.initCause(ioe); - throw ex; - } - } } - // existence check must be after permission checks + // existence check must be after FS checks if (Files.notExists(path)) throw new FileNotFoundException(path + " not found"); - Permission perm = filePermission; - assert perm == null || perm.getActions().equals("read"); - @SuppressWarnings("removal") - AccessControlContext acc = sm != null ? - AccessController.getContext() : null; boolean finalDefaultFS = defaultFS; Function inputStreamSupplier = (p) -> - createInputStream(p, acc, perm, finalDefaultFS); + createInputStream(p, finalDefaultFS); long length; try { @@ -308,41 +262,17 @@ public static FilePublisher create(Path path) return new FilePublisher(path, length, inputStreamSupplier); } - @SuppressWarnings("removal") private static InputStream createInputStream(Path path, - AccessControlContext acc, - Permission perm, boolean defaultFS) { try { - if (acc != null) { - PrivilegedExceptionAction pa = defaultFS - ? () -> new FileInputStream(path.toFile()) - : () -> Files.newInputStream(path); - return perm != null - ? AccessController.doPrivileged(pa, acc, perm) - : AccessController.doPrivileged(pa, acc); - } else { - return defaultFS + return defaultFS ? new FileInputStream(path.toFile()) : Files.newInputStream(path); - } - } catch (PrivilegedActionException pae) { - throw toUncheckedException(pae.getCause()); } catch (IOException io) { throw new UncheckedIOException(io); } } - private static RuntimeException toUncheckedException(Throwable t) { - if (t instanceof RuntimeException) - throw (RuntimeException) t; - if (t instanceof Error) - throw (Error) t; - if (t instanceof IOException) - throw new UncheckedIOException((IOException) t); - throw new UndeclaredThrowableException(t); - } - private FilePublisher(Path name, long length, Function inputStreamSupplier) { diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/ResponseBodyHandlers.java b/src/java.net.http/share/classes/jdk/internal/net/http/ResponseBodyHandlers.java index 22e03238d2140..79b2332ae37cc 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/ResponseBodyHandlers.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/ResponseBodyHandlers.java @@ -25,8 +25,6 @@ package jdk.internal.net.http; -import java.io.File; -import java.io.FilePermission; import java.io.IOException; import java.io.UncheckedIOException; import java.net.URI; @@ -34,10 +32,8 @@ import java.nio.file.OpenOption; import java.nio.file.Path; import java.nio.file.Paths; -import java.security.AccessControlContext; -import java.security.AccessController; import java.util.List; -import java.util.Objects; + import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentMap; import java.util.function.Function; @@ -56,62 +52,31 @@ public final class ResponseBodyHandlers { private ResponseBodyHandlers() { } - private static final String pathForSecurityCheck(Path path) { - return path.toFile().getPath(); - } - /** * A Path body handler. */ public static class PathBodyHandler implements BodyHandler{ private final Path file; private final List openOptions; // immutable list - @SuppressWarnings("removal") - private final AccessControlContext acc; - private final FilePermission filePermission; /** * Factory for creating PathBodyHandler. - * - * Permission checks are performed here before construction of the - * PathBodyHandler. Permission checking and construction are - * deliberately and tightly co-located. */ public static PathBodyHandler create(Path file, List openOptions) { - FilePermission filePermission = null; - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - try { - String fn = pathForSecurityCheck(file); - FilePermission writePermission = new FilePermission(fn, "write"); - sm.checkPermission(writePermission); - filePermission = writePermission; - } catch (UnsupportedOperationException ignored) { - // path not associated with the default file system provider - } - } - assert filePermission == null || filePermission.getActions().equals("write"); - @SuppressWarnings("removal") - var acc = sm != null ? AccessController.getContext() : null; - return new PathBodyHandler(file, openOptions, acc, filePermission); + return new PathBodyHandler(file, openOptions); } private PathBodyHandler(Path file, - List openOptions, - @SuppressWarnings("removal") AccessControlContext acc, - FilePermission filePermission) { + List openOptions) { this.file = file; this.openOptions = openOptions; - this.acc = acc; - this.filePermission = filePermission; } @Override public BodySubscriber apply(ResponseInfo responseInfo) { - return new PathSubscriber(file, openOptions, acc, filePermission); + return new PathSubscriber(file, openOptions); } } @@ -170,44 +135,20 @@ public void applyPushPromise( public static class FileDownloadBodyHandler implements BodyHandler { private final Path directory; private final List openOptions; - @SuppressWarnings("removal") - private final AccessControlContext acc; - private final FilePermission[] filePermissions; // may be null /** * Factory for creating FileDownloadBodyHandler. - * - * Permission checks are performed here before construction of the - * FileDownloadBodyHandler. Permission checking and construction are - * deliberately and tightly co-located. */ public static FileDownloadBodyHandler create(Path directory, List openOptions) { - String fn; try { - fn = pathForSecurityCheck(directory); + directory.toFile().getPath(); } catch (UnsupportedOperationException uoe) { // directory not associated with the default file system provider throw new IllegalArgumentException("invalid path: " + directory, uoe); } - FilePermission filePermissions[] = null; - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - FilePermission writePermission = new FilePermission(fn, "write"); - String writePathPerm = fn + File.separatorChar + "*"; - FilePermission writeInDirPermission = new FilePermission(writePathPerm, "write"); - sm.checkPermission(writeInDirPermission); - FilePermission readPermission = new FilePermission(fn, "read"); - sm.checkPermission(readPermission); - - // read permission is only needed before determine the below checks - // only write permission is required when downloading to the file - filePermissions = new FilePermission[] { writePermission, writeInDirPermission }; - } - - // existence, etc, checks must be after permission checks + // existence, etc, checks must be after FS checks if (Files.notExists(directory)) throw new IllegalArgumentException("non-existent directory: " + directory); if (!Files.isDirectory(directory)) @@ -215,21 +156,13 @@ public static FileDownloadBodyHandler create(Path directory, if (!Files.isWritable(directory)) throw new IllegalArgumentException("non-writable directory: " + directory); - assert filePermissions == null || (filePermissions[0].getActions().equals("write") - && filePermissions[1].getActions().equals("write")); - @SuppressWarnings("removal") - var acc = sm != null ? AccessController.getContext() : null; - return new FileDownloadBodyHandler(directory, openOptions, acc, filePermissions); + return new FileDownloadBodyHandler(directory, openOptions); } private FileDownloadBodyHandler(Path directory, - List openOptions, - @SuppressWarnings("removal") AccessControlContext acc, - FilePermission... filePermissions) { + List openOptions) { this.directory = directory; this.openOptions = openOptions; - this.acc = acc; - this.filePermissions = filePermissions; } /** The "attachment" disposition-type and separator. */ @@ -394,7 +327,7 @@ public BodySubscriber apply(ResponseInfo responseInfo) { "Resulting file, " + file.toString() + ", outside of given directory"); } - return new PathSubscriber(file, openOptions, acc, filePermissions); + return new PathSubscriber(file, openOptions); } } } diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java b/src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java index 09ad87f9205eb..04d019e4c818a 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/ResponseSubscribers.java @@ -26,7 +26,6 @@ package jdk.internal.net.http; import java.io.BufferedReader; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -35,11 +34,6 @@ import java.nio.charset.Charset; import java.nio.file.OpenOption; import java.nio.file.Path; -import java.security.AccessControlContext; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -164,83 +158,31 @@ public void onComplete() { /** * A Subscriber that writes the flow of data to a given file. - * - * Privileged actions are performed within a limited doPrivileged that only - * asserts the specific, write, file permissions that were checked during - * the construction of this PathSubscriber. */ public static class PathSubscriber implements TrustedSubscriber { - - private static final FilePermission[] EMPTY_FILE_PERMISSIONS = new FilePermission[0]; - private final Path file; private final OpenOption[] options; - @SuppressWarnings("removal") - private final AccessControlContext acc; - private final FilePermission[] filePermissions; - private final boolean isDefaultFS; private final CompletableFuture result = new MinimalFuture<>(); private final AtomicBoolean subscribed = new AtomicBoolean(); private volatile Flow.Subscription subscription; private volatile FileChannel out; - private static final String pathForSecurityCheck(Path path) { - return path.toFile().getPath(); - } - /** * Factory for creating PathSubscriber. - * - * Permission checks are performed here before construction of the - * PathSubscriber. Permission checking and construction are deliberately - * and tightly co-located. */ public static PathSubscriber create(Path file, List options) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - FilePermission filePermission = null; - if (sm != null) { - try { - String fn = pathForSecurityCheck(file); - FilePermission writePermission = new FilePermission(fn, "write"); - sm.checkPermission(writePermission); - filePermission = writePermission; - } catch (UnsupportedOperationException ignored) { - // path not associated with the default file system provider - } - } - - assert filePermission == null || filePermission.getActions().equals("write"); - @SuppressWarnings("removal") - AccessControlContext acc = sm != null ? AccessController.getContext() : null; - return new PathSubscriber(file, options, acc, filePermission); + return new PathSubscriber(file, options); } // pp so handler implementations in the same package can construct /*package-private*/ PathSubscriber(Path file, - List options, - @SuppressWarnings("removal") AccessControlContext acc, - FilePermission... filePermissions) { + List options) { this.file = file; this.options = options.stream().toArray(OpenOption[]::new); - this.acc = acc; - this.filePermissions = filePermissions == null || filePermissions[0] == null - ? EMPTY_FILE_PERMISSIONS : filePermissions; - this.isDefaultFS = isDefaultFS(file); - } - - private static boolean isDefaultFS(Path file) { - try { - file.toFile(); - return true; - } catch (UnsupportedOperationException uoe) { - return false; - } } - @SuppressWarnings("removal") @Override public void onSubscribe(Flow.Subscription subscription) { Objects.requireNonNull(subscription); @@ -250,31 +192,12 @@ public void onSubscribe(Flow.Subscription subscription) { } this.subscription = subscription; - if (acc == null) { - try { - out = FileChannel.open(file, options); - } catch (IOException ioe) { - result.completeExceptionally(ioe); - subscription.cancel(); - return; - } - } else { - try { - PrivilegedExceptionAction pa = - () -> FileChannel.open(file, options); - out = isDefaultFS - ? AccessController.doPrivileged(pa, acc, filePermissions) - : AccessController.doPrivileged(pa, acc); - } catch (PrivilegedActionException pae) { - Throwable t = pae.getCause() != null ? pae.getCause() : pae; - result.completeExceptionally(t); - subscription.cancel(); - return; - } catch (Exception e) { - result.completeExceptionally(e); - subscription.cancel(); - return; - } + try { + out = FileChannel.open(file, options); + } catch (IOException ioe) { + result.completeExceptionally(ioe); + subscription.cancel(); + return; } subscription.request(1); } @@ -311,21 +234,8 @@ public CompletionStage getBody() { return result; } - @SuppressWarnings("removal") private void close() { - if (acc == null) { - Utils.close(out); - } else { - PrivilegedAction pa = () -> { - Utils.close(out); - return null; - }; - if (isDefaultFS) { - AccessController.doPrivileged(pa, acc, filePermissions); - } else { - AccessController.doPrivileged(pa, acc); - } - } + Utils.close(out); } } diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java b/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java index bbb63718dc693..f3eedf8fe6e78 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/Stream.java @@ -160,6 +160,10 @@ class Stream extends ExchangeImpl { // send lock: prevent sending DataFrames after reset occurred. private final Lock sendLock = new ReentrantLock(); private final Lock stateLock = new ReentrantLock(); + // inputQ lock: methods that take from the inputQ + // must not run concurrently. + private final Lock inputQLock = new ReentrantLock(); + /** * A reference to this Stream's connection Send Window controller. The * stream MUST acquire the appropriate amount of Send Window before @@ -183,6 +187,8 @@ HttpConnection connection() { private void schedule() { boolean onCompleteCalled = false; HttpResponse.BodySubscriber subscriber = responseSubscriber; + // prevents drainInputQueue() from running concurrently + inputQLock.lock(); try { if (subscriber == null) { // pendingResponseSubscriber will be null until response headers have been received and @@ -199,7 +205,7 @@ private void schedule() { Http2Frame frame = inputQ.peek(); if (frame instanceof ResetFrame rf) { inputQ.remove(); - if (endStreamReceived() && rf.getErrorCode() == ResetFrame.NO_ERROR) { + if (endStreamReceived() && rf.getErrorCode() == ResetFrame.NO_ERROR) { // If END_STREAM is already received, complete the requestBodyCF successfully // and stop sending any request data. requestBodyCF.complete(null); @@ -208,7 +214,7 @@ private void schedule() { } return; } - DataFrame df = (DataFrame)frame; + DataFrame df = (DataFrame) frame; boolean finished = df.getFlag(DataFrame.END_STREAM); List buffers = df.getData(); @@ -256,6 +262,7 @@ private void schedule() { } catch (Throwable throwable) { errorRef.compareAndSet(null, throwable); } finally { + inputQLock.unlock(); if (sched.isStopped()) drainInputQueue(); } @@ -274,26 +281,36 @@ private void schedule() { } catch (Throwable x) { Log.logError("Subscriber::onError threw exception: {0}", t); } finally { + // cancelImpl will eventually call drainInputQueue(); cancelImpl(t); - drainInputQueue(); } } } - // must only be called from the scheduler schedule() loop. - // ensure that all received data frames are accounted for + // Called from the scheduler schedule() loop, + // or after resetting the stream. + // Ensures that all received data frames are accounted for // in the connection window flow control if the scheduler // is stopped before all the data is consumed. + // The inputQLock is used to prevent concurrently taking + // from the queue. private void drainInputQueue() { Http2Frame frame; - while ((frame = inputQ.poll()) != null) { - if (frame instanceof DataFrame df) { - // Data frames that have been added to the inputQ - // must be released using releaseUnconsumed() to - // account for the amount of unprocessed bytes - // tracked by the connection.windowUpdater. - connection.releaseUnconsumed(df); + // will wait until schedule() has finished taking + // from the queue, if needed. + inputQLock.lock(); + try { + while ((frame = inputQ.poll()) != null) { + if (frame instanceof DataFrame df) { + // Data frames that have been added to the inputQ + // must be released using releaseUnconsumed() to + // account for the amount of unprocessed bytes + // tracked by the connection.windowUpdater. + connection.releaseUnconsumed(df); + } } + } finally { + inputQLock.unlock(); } } @@ -405,12 +422,38 @@ private void receiveDataFrame(DataFrame df) { return; } } - inputQ.add(df); + pushDataFrame(len, df); } finally { sched.runOrSchedule(); } } + // Ensures that no data frame is pushed on the inputQ + // after the stream is closed. + // Changes to the `closed` boolean are guarded by the + // stateLock. Contention should be low as only one + // thread at a time adds to the inputQ, and + // we can only contend when closing the stream. + // Note that this method can run concurrently with + // methods holding the inputQLock: that is OK. + // The inputQLock is there to ensure that methods + // taking from the queue are not running concurrently + // with each others, but concurrently adding at the + // end of the queue while peeking/polling at the head + // is OK. + private void pushDataFrame(int len, DataFrame df) { + boolean closed = false; + stateLock.lock(); + try { + if (!(closed = this.closed)) { + inputQ.add(df); + } + } finally { + stateLock.unlock(); + } + if (closed && len > 0) connection.releaseUnconsumed(df); + } + /** Handles a RESET frame. RESET is always handled inline in the queue. */ private void receiveResetFrame(ResetFrame frame) { inputQ.add(frame); @@ -1547,6 +1590,8 @@ void cancelImpl(final Throwable e, final int resetFrameErrCode) { } } catch (Throwable ex) { Log.logError(ex); + } finally { + drainInputQueue(); } } @@ -1770,7 +1815,7 @@ String dbgString() { @Override protected boolean windowSizeExceeded(long received) { onProtocolError(new ProtocolException("stream %s flow control window exceeded" - .formatted(streamid)), ResetFrame.FLOW_CONTROL_ERROR); + .formatted(streamid)), ResetFrame.FLOW_CONTROL_ERROR); return true; } } diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/common/ImmutableExtendedSSLSession.java b/src/java.net.http/share/classes/jdk/internal/net/http/common/ImmutableExtendedSSLSession.java index bb6540e44b95f..2a5f125c0c489 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/common/ImmutableExtendedSSLSession.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/common/ImmutableExtendedSSLSession.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -27,7 +27,6 @@ import java.security.Principal; import java.util.List; -import javax.net.ssl.SSLSession; import javax.net.ssl.ExtendedSSLSession; import javax.net.ssl.SSLSessionContext; import javax.net.ssl.SSLPeerUnverifiedException; diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/common/Utils.java b/src/java.net.http/share/classes/jdk/internal/net/http/common/Utils.java index ef5af764e7609..511b17d7813cb 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/common/Utils.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/common/Utils.java @@ -39,8 +39,6 @@ import java.net.ConnectException; import java.net.InetSocketAddress; import java.net.URI; -import java.net.URLPermission; -import java.net.http.HttpClient; import java.net.http.HttpHeaders; import java.net.http.HttpTimeoutException; import java.nio.ByteBuffer; @@ -51,8 +49,6 @@ import java.nio.charset.Charset; import java.nio.charset.CodingErrorAction; import java.nio.charset.StandardCharsets; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.text.Normalizer; import java.util.Arrays; import java.util.Collection; @@ -100,10 +96,7 @@ public final class Utils { // public static final boolean TESTING; // static { -// if (ASSERTIONSENABLED) { -// PrivilegedAction action = () -> System.getProperty("test.src"); -// TESTING = AccessController.doPrivileged(action) != null; -// } else TESTING = false; +// TESTING = ASSERTIONSENABLED ? System.getProperty("test.src") != null : false; // } public static final LoggerConfig DEBUG_CONFIG = getLoggerConfig(DebugLogger.HTTP_NAME, LoggerConfig.OFF); @@ -120,9 +113,7 @@ public final class Utils { hostnameVerificationDisabledValue(); private static LoggerConfig getLoggerConfig(String loggerName, LoggerConfig def) { - PrivilegedAction action = () -> System.getProperty(loggerName); - @SuppressWarnings("removal") - var prop = AccessController.doPrivileged(action); + var prop = System.getProperty(loggerName); if (prop == null) return def; var config = LoggerConfig.OFF; for (var s : prop.split(",")) { @@ -449,41 +440,6 @@ public static Throwable wrapWithExtraDetail(Throwable t, private Utils() { } - /** - * Returns the security permissions required to connect to the proxy, or - * {@code null} if none is required or applicable. - */ - public static URLPermission permissionForProxy(InetSocketAddress proxyAddress) { - if (proxyAddress == null) - return null; - - StringBuilder sb = new StringBuilder(); - sb.append("socket://") - .append(proxyAddress.getHostString()).append(":") - .append(proxyAddress.getPort()); - String urlString = sb.toString(); - return new URLPermission(urlString, "CONNECT"); - } - - /** - * Returns the security permission required for the given details. - */ - public static URLPermission permissionForServer(URI uri, - String method, - Stream headers) { - String urlString = new StringBuilder() - .append(uri.getScheme()).append("://") - .append(uri.getRawAuthority()) - .append(uri.getRawPath()).toString(); - - StringBuilder actionStringBuilder = new StringBuilder(method); - String collected = headers.collect(joining(",")); - if (!collected.isEmpty()) { - actionStringBuilder.append(":").append(collected); - } - return new URLPermission(urlString, actionStringBuilder.toString()); - } - private static final boolean[] LOWER_CASE_CHARS = new boolean[128]; // ABNF primitives defined in RFC 7230 @@ -587,34 +543,24 @@ public static boolean isValidValue(String token) { return true; } - @SuppressWarnings("removal") public static int getIntegerNetProperty(String name, int defaultValue) { - return AccessController.doPrivileged((PrivilegedAction) () -> - NetProperties.getInteger(name, defaultValue)); + return NetProperties.getInteger(name, defaultValue); } - @SuppressWarnings("removal") public static String getNetProperty(String name) { - return AccessController.doPrivileged((PrivilegedAction) () -> - NetProperties.get(name)); + return NetProperties.get(name); } - @SuppressWarnings("removal") public static boolean getBooleanProperty(String name, boolean def) { - return AccessController.doPrivileged((PrivilegedAction) () -> - Boolean.parseBoolean(System.getProperty(name, String.valueOf(def)))); + return Boolean.parseBoolean(System.getProperty(name, String.valueOf(def))); } - @SuppressWarnings("removal") public static String getProperty(String name) { - return AccessController.doPrivileged((PrivilegedAction) () -> - System.getProperty(name)); + return System.getProperty(name); } - @SuppressWarnings("removal") public static int getIntegerProperty(String name, int defaultValue) { - return AccessController.doPrivileged((PrivilegedAction) () -> - Integer.parseInt(System.getProperty(name, String.valueOf(defaultValue)))); + return Integer.parseInt(System.getProperty(name, String.valueOf(defaultValue))); } public static int getIntegerNetProperty(String property, int min, int max, int defaultValue, boolean log) { diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HPACK.java b/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HPACK.java index abecde7166561..d49b8c391cb57 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HPACK.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/hpack/HPACK.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024, 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 @@ -28,8 +28,6 @@ import jdk.internal.net.http.hpack.HPACK.Logger.Level; import java.nio.ByteBuffer; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Map; import java.util.ResourceBundle; import java.util.function.Supplier; @@ -52,9 +50,7 @@ public final class HPACK { static { String PROPERTY = "jdk.internal.httpclient.hpack.log.level"; - @SuppressWarnings("removal") - String value = AccessController.doPrivileged( - (PrivilegedAction) () -> System.getProperty(PROPERTY)); + String value = System.getProperty(PROPERTY); if (value == null) { LOGGER = new RootLogger(NONE); diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java b/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java index f88ec774dc0e1..c1c0853504c5f 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/websocket/OpeningHandshake.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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,17 +39,13 @@ import jdk.internal.net.http.common.Utils; import java.io.IOException; -import java.net.InetSocketAddress; import java.net.Proxy; import java.net.ProxySelector; import java.net.URI; import java.net.URISyntaxException; -import java.net.URLPermission; import java.nio.charset.StandardCharsets; -import java.security.AccessController; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.security.PrivilegedAction; import java.security.SecureRandom; import java.time.Duration; import java.util.Base64; @@ -61,11 +57,9 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.CompletableFuture; -import java.util.stream.Stream; import static java.lang.String.format; import static jdk.internal.net.http.common.Utils.isValidName; -import static jdk.internal.net.http.common.Utils.permissionForProxy; import static jdk.internal.net.http.common.Utils.stringOf; public class OpeningHandshake { @@ -112,7 +106,6 @@ public class OpeningHandshake { public OpeningHandshake(BuilderImpl b) { checkURI(b.getUri()); Proxy proxy = proxyFor(b.getProxySelector(), b.getUri()); - checkPermissions(b, proxy); this.client = b.getClient(); URI httpURI = createRequestURI(b.getUri()); HttpRequestBuilderImpl requestBuilder = new HttpRequestBuilderImpl(httpURI); @@ -185,12 +178,9 @@ static URI createRequestURI(URI uri) { } } - @SuppressWarnings("removal") public CompletableFuture send() { - PrivilegedAction> pa = () -> - client.sendAsync(this.request, BodyHandlers.ofString()) + return client.sendAsync(this.request, BodyHandlers.ofString()) .thenCompose(this::resultFrom); - return AccessController.doPrivileged(pa); } /* @@ -376,27 +366,4 @@ private static Proxy proxyFor(Optional selector, URI uri) { return proxy; } - /** - * Performs the necessary security permissions checks to connect ( possibly - * through a proxy ) to the builders WebSocket URI. - * - * @throws SecurityException if the security manager denies access - */ - static void checkPermissions(BuilderImpl b, Proxy proxy) { - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm == null) { - return; - } - Stream headers = b.getHeaders().stream().map(p -> p.first).distinct(); - URLPermission perm1 = Utils.permissionForServer(b.getUri(), "", headers); - sm.checkPermission(perm1); - if (proxy == null) { - return; - } - URLPermission perm2 = permissionForProxy((InetSocketAddress) proxy.address()); - if (perm2 != null) { - sm.checkPermission(perm2); - } - } } diff --git a/src/java.se/share/classes/module-info.java b/src/java.se/share/classes/module-info.java index 81b1bd3cb8aa9..9a2704660b7b9 100644 --- a/src/java.se/share/classes/module-info.java +++ b/src/java.se/share/classes/module-info.java @@ -23,6 +23,8 @@ * questions. */ +import jdk.internal.javac.ParticipatesInPreview; + /** * Defines the API of the Java SE Platform. * @@ -38,7 +40,9 @@ * @moduleGraph * @since 9 */ +@ParticipatesInPreview module java.se { + requires transitive java.base; requires transitive java.compiler; requires transitive java.datatransfer; requires transitive java.desktop; diff --git a/src/java.security.sasl/share/classes/com/sun/security/sasl/Provider.java b/src/java.security.sasl/share/classes/com/sun/security/sasl/Provider.java index b61c962bf51c5..c3d4cdcc54b5e 100644 --- a/src/java.security.sasl/share/classes/com/sun/security/sasl/Provider.java +++ b/src/java.security.sasl/share/classes/com/sun/security/sasl/Provider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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,8 +24,6 @@ */ package com.sun.security.sasl; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.security.NoSuchAlgorithmException; import java.security.InvalidParameterException; import java.security.ProviderException; @@ -98,34 +96,28 @@ public Object newInstance(Object ctrParamObj) } } - @SuppressWarnings("removal") public Provider() { super("SunSASL", PROVIDER_VER, info); final Provider p = this; - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - // Client mechanisms - putService(new ProviderService(p, "SaslClientFactory", - "DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl")); - putService(new ProviderService(p, "SaslClientFactory", - "NTLM", "com.sun.security.sasl.ntlm.FactoryImpl")); - putService(new ProviderService(p, "SaslClientFactory", - "EXTERNAL", "com.sun.security.sasl.ClientFactoryImpl")); - putService(new ProviderService(p, "SaslClientFactory", - "PLAIN", "com.sun.security.sasl.ClientFactoryImpl")); - putService(new ProviderService(p, "SaslClientFactory", - "CRAM-MD5", "com.sun.security.sasl.ClientFactoryImpl")); + // Client mechanisms + putService(new ProviderService(p, "SaslClientFactory", + "DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl")); + putService(new ProviderService(p, "SaslClientFactory", + "NTLM", "com.sun.security.sasl.ntlm.FactoryImpl")); + putService(new ProviderService(p, "SaslClientFactory", + "EXTERNAL", "com.sun.security.sasl.ClientFactoryImpl")); + putService(new ProviderService(p, "SaslClientFactory", + "PLAIN", "com.sun.security.sasl.ClientFactoryImpl")); + putService(new ProviderService(p, "SaslClientFactory", + "CRAM-MD5", "com.sun.security.sasl.ClientFactoryImpl")); - // Server mechanisms - putService(new ProviderService(p, "SaslServerFactory", - "CRAM-MD5", "com.sun.security.sasl.ServerFactoryImpl")); - putService(new ProviderService(p, "SaslServerFactory", - "DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl")); - putService(new ProviderService(p, "SaslServerFactory", - "NTLM", "com.sun.security.sasl.ntlm.FactoryImpl")); - return null; - } - }); + // Server mechanisms + putService(new ProviderService(p, "SaslServerFactory", + "CRAM-MD5", "com.sun.security.sasl.ServerFactoryImpl")); + putService(new ProviderService(p, "SaslServerFactory", + "DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl")); + putService(new ProviderService(p, "SaslServerFactory", + "NTLM", "com.sun.security.sasl.ntlm.FactoryImpl")); } } diff --git a/src/java.security.sasl/share/classes/javax/security/sasl/Sasl.java b/src/java.security.sasl/share/classes/javax/security/sasl/Sasl.java index aa6bec486ceaa..79f592fc54a1a 100644 --- a/src/java.security.sasl/share/classes/javax/security/sasl/Sasl.java +++ b/src/java.security.sasl/share/classes/javax/security/sasl/Sasl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2024, 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,8 +26,6 @@ package javax.security.sasl; import javax.security.auth.callback.CallbackHandler; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; @@ -74,10 +72,7 @@ public class Sasl { private static List disabledMechanisms = new ArrayList<>(); static { - @SuppressWarnings("removal") - String prop = AccessController.doPrivileged( - (PrivilegedAction) - () -> Security.getProperty("jdk.sasl.disabledMechanisms")); + String prop = Security.getProperty("jdk.sasl.disabledMechanisms"); if (prop != null) { for (String s : prop.split("\\s*,\\s*")) { @@ -452,9 +447,7 @@ private static Object loadFactory(Service service) * that was used to load the provider. * In order to get the class loader of a class, the * caller's class loader must be the same as or an ancestor of - * the class loader being returned. Otherwise, the caller must - * have "getClassLoader" permission, or a SecurityException - * will be thrown. + * the class loader being returned. */ return service.newInstance(null); } catch (InvalidParameterException | NoSuchAlgorithmException e) { diff --git a/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022.java b/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022.java index 041ab301d641e..2f259bfa19118 100644 --- a/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022.java +++ b/src/jdk.charsets/share/classes/sun/nio/cs/ext/ISO2022.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2024, 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,9 +23,6 @@ * questions. */ -/* - */ - package sun.nio.cs.ext; import java.nio.ByteBuffer; @@ -67,8 +64,6 @@ protected static class Encoder extends CharsetEncoder { public static final byte PLANE2 = (byte)0xA2; public static final byte PLANE3 = (byte)0xA3; - protected final byte maximumDesignatorLength = 4; - protected byte[] SODesig, SS2Desig = null, SS3Desig = null; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java index 3dfbbc1ff528f..9b3a50a035aec 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacScope.java @@ -87,12 +87,26 @@ public JavacScope getEnclosingScope() { } else { // synthesize an outermost "star-import" scope return new JavacScope(env) { - public boolean isStarImportScope() { - return true; + @Override + public ScopeType getScopeType() { + return ScopeType.STAR_IMPORT; } @DefinedBy(Api.COMPILER_TREE) public JavacScope getEnclosingScope() { - return null; + return new JavacScope(env) { + @Override + public ScopeType getScopeType() { + return ScopeType.MODULE_IMPORT; + } + @Override @DefinedBy(Api.COMPILER_TREE) + public JavacScope getEnclosingScope() { + return null; + } + @Override @DefinedBy(Api.COMPILER_TREE) + public Iterable getLocalElements() { + return env.toplevel.moduleImportScope.getSymbols(VALIDATOR); + } + }; } @DefinedBy(Api.COMPILER_TREE) public Iterable getLocalElements() { @@ -122,21 +136,27 @@ public Env getEnv() { return env; } - public boolean isStarImportScope() { - return false; + public ScopeType getScopeType() { + return ScopeType.ORDINARY; } public boolean equals(Object other) { return other instanceof JavacScope javacScope && env.equals(javacScope.env) - && isStarImportScope() == javacScope.isStarImportScope(); + && getScopeType()== javacScope.getScopeType(); } public int hashCode() { - return env.hashCode() + (isStarImportScope() ? 1 : 0); + return env.hashCode() + getScopeType().hashCode(); } public String toString() { - return "JavacScope[env=" + env + ",starImport=" + isStarImportScope() + "]"; + return "JavacScope[env=" + env + ", scope type=" + getScopeType() + "]"; + } + + private enum ScopeType { + ORDINARY, + STAR_IMPORT, + MODULE_IMPORT; } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java index 8f84f5d7fbd45..ce719230455d3 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTrees.java @@ -1402,6 +1402,7 @@ public void putComment(JCTree tree, Comment c) { jcCompilationUnit.namedImportScope = new NamedImportScope(psym); jcCompilationUnit.packge = psym; jcCompilationUnit.starImportScope = new StarImportScope(psym); + jcCompilationUnit.moduleImportScope = new StarImportScope(psym); jcCompilationUnit.toplevelScope = WriteableScope.create(psym); return new TreePath(jcCompilationUnit); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java index e5d9a9e2ac449..2491cd31f0db4 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Kinds.java @@ -70,7 +70,6 @@ public enum Kind { AMBIGUOUS(Category.RESOLUTION_TARGET), // overloaded target HIDDEN(Category.RESOLUTION_TARGET), // not overloaded non-target STATICERR(Category.RESOLUTION_TARGET), // overloaded? target - MISSING_ENCL(Category.RESOLUTION), // not overloaded non-target BAD_RESTRICTED_TYPE(Category.RESOLUTION), // not overloaded non-target ABSENT_VAR(Category.RESOLUTION_TARGET, KindName.VAR), // not overloaded non-target WRONG_MTHS(Category.RESOLUTION_TARGET, KindName.METHOD), // overloaded target diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java index d024dc75225fa..622c13d8b4797 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Lint.java @@ -181,7 +181,7 @@ public enum LintCategory { CLASSFILE("classfile"), /** - * Warn about"dangling" documentation comments, + * Warn about "dangling" documentation comments, * not attached to any declaration. */ DANGLING_DOC_COMMENTS("dangling-doc-comments"), diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java index 5e9a75a0b6b2a..c66e17586161e 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Preview.java @@ -27,6 +27,7 @@ import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Source.Feature; +import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.resources.CompilerProperties.Errors; import com.sun.tools.javac.resources.CompilerProperties.Warnings; @@ -133,11 +134,23 @@ public boolean participatesInPreview(Symtab syms, Symbol s, Symbol previewSymbol return true; } + return participatesInPreview(syms, s.packge().modle); + } + + /** + * Returns true if module {@code m} is deemed to participate in the preview, and + * therefore no warnings or errors will be produced. + * + * @param syms the symbol table + * @param m the module to check + * @return true if {@code m} is participating in the preview of {@code previewSymbol} + */ + public boolean participatesInPreview(Symtab syms, ModuleSymbol m) { // If java.base's jdk.internal.javac package is exported to s's module then // s participates in the preview API return syms.java_base.exports.stream() .filter(ed -> ed.packge.fullname == names.jdk_internal_javac) - .anyMatch(ed -> ed.modules.contains(s.packge().modle)); + .anyMatch(ed -> ed.modules.contains(m)); } /** @@ -211,6 +224,7 @@ public boolean isPreview(Feature feature) { case FLEXIBLE_CONSTRUCTORS -> true; case PRIMITIVE_PATTERNS -> true; case MODULE_IMPORTS -> true; + case JAVA_BASE_TRANSITIVE -> true; //Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing). //When real preview features will be added, this method can be implemented to return 'true' //for those selected features, and 'false' for all the others. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java index 4a226e4de3b97..572a7b126750c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java @@ -262,6 +262,7 @@ public enum Feature { PRIMITIVE_PATTERNS(JDK23, Fragments.FeaturePrimitivePatterns, DiagKind.PLURAL), FLEXIBLE_CONSTRUCTORS(JDK22, Fragments.FeatureFlexibleConstructors, DiagKind.NORMAL), MODULE_IMPORTS(JDK23, Fragments.FeatureModuleImports, DiagKind.PLURAL), + JAVA_BASE_TRANSITIVE(JDK24, Fragments.FeatureJavaBaseTransitive, DiagKind.PLURAL), PRIVATE_MEMBERS_IN_PERMITS_CLAUSE(JDK19), ERASE_POLY_SIG_RETURN_TYPE(JDK24), ; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index 07a136c17003c..f565cff0788d6 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -2590,8 +2590,7 @@ public void visitApply(JCMethodInvocation tree) { } else if (methName == names._super) { // qualifier omitted; check for existence // of an appropriate implicit qualifier. - rs.resolveImplicitThis(tree.meth.pos(), - localEnv, site, true); + checkNewInnerClass(tree.meth.pos(), localEnv, site, true); } } else if (tree.meth.hasTag(SELECT)) { log.error(tree.meth.pos(), @@ -2798,11 +2797,9 @@ public void visitNewClass(final JCNewClass tree) { log.error(tree.encl.pos(), Errors.QualifiedNewOfStaticClass(clazztype.tsym)); } } - } else if (!clazztype.tsym.isInterface() && - (clazztype.tsym.flags_field & NOOUTERTHIS) == 0 && - clazztype.getEnclosingType().hasTag(CLASS)) { + } else { // Check for the existence of an apropos outer instance - rs.resolveImplicitThis(tree.pos(), env, clazztype); + checkNewInnerClass(tree.pos(), env, clazztype, false); } // Attribute constructor arguments. @@ -3067,6 +3064,24 @@ public void report(DiagnosticPosition _unused, JCDiagnostic details) { }; } + void checkNewInnerClass(DiagnosticPosition pos, Env env, Type type, boolean isSuper) { + boolean isLocal = type.tsym.owner.kind == MTH; + if ((type.tsym.flags() & (INTERFACE | ENUM | RECORD)) != 0 || + (!isLocal && !type.tsym.isInner()) || + (isSuper && env.enclClass.sym.isAnonymous())) { + // nothing to check + return; + } + Symbol res = isLocal ? + rs.findLocalClassOwner(env, type.tsym) : + rs.findSelfContaining(pos, env, type.getEnclosingType().tsym, isSuper); + if (res.exists()) { + rs.accessBase(res, pos, env.enclClass.sym.type, names._this, true); + } else { + log.error(pos, Errors.EnclClassRequired(type.tsym)); + } + } + /** Make an attributed null check tree. */ public JCExpression makeNullCheck(JCExpression arg) { @@ -3639,7 +3654,6 @@ public void visitReference(final JCMemberReference that) { boolean targetError; switch (refSym.kind) { case ABSENT_MTH: - case MISSING_ENCL: targetError = false; break; case WRONG_MTH: @@ -3690,11 +3704,7 @@ public void visitReference(final JCMemberReference that) { } if (!env.info.attributionMode.isSpeculative && that.getMode() == JCMemberReference.ReferenceMode.NEW) { - Type enclosingType = exprType.getEnclosingType(); - if (enclosingType != null && enclosingType.hasTag(CLASS)) { - // Check for the existence of an appropriate outer instance - rs.resolveImplicitThis(that.pos(), env, exprType); - } + checkNewInnerClass(that.pos(), env, exprType, false); } if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java index 926be3b6e267d..1042a9747ba36 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java @@ -223,6 +223,7 @@ Env topLevelEnv(JCCompilationUnit tree) { tree.toplevelScope = WriteableScope.create(tree.packge); tree.namedImportScope = new NamedImportScope(tree.packge); tree.starImportScope = new StarImportScope(tree.packge); + tree.moduleImportScope = new StarImportScope(tree.packge); localEnv.info.scope = tree.toplevelScope; localEnv.info.lint = lint; return localEnv; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java index 3d893252218b5..bfad334d1942f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Modules.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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 @@ -64,8 +64,11 @@ import com.sun.tools.javac.code.Directive.UsesDirective; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Flags.Flag; +import com.sun.tools.javac.code.Kinds; +import com.sun.tools.javac.code.Lint; import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.ModuleFinder; +import com.sun.tools.javac.code.Preview; import com.sun.tools.javac.code.Source; import com.sun.tools.javac.code.Source.Feature; import com.sun.tools.javac.code.Symbol; @@ -74,6 +77,7 @@ import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.code.Symbol.MethodSymbol; import com.sun.tools.javac.code.Symbol.ModuleFlags; +import com.sun.tools.javac.code.Symbol.ModuleResolutionFlags; import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.code.Symbol.PackageSymbol; import com.sun.tools.javac.code.Symtab; @@ -99,6 +103,7 @@ import com.sun.tools.javac.tree.TreeInfo; import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; @@ -112,14 +117,9 @@ import static com.sun.tools.javac.code.Flags.PUBLIC; import static com.sun.tools.javac.code.Flags.UNATTRIBUTED; -import com.sun.tools.javac.code.Kinds; - import static com.sun.tools.javac.code.Kinds.Kind.ERR; import static com.sun.tools.javac.code.Kinds.Kind.MDL; import static com.sun.tools.javac.code.Kinds.Kind.MTH; -import com.sun.tools.javac.code.Lint; - -import com.sun.tools.javac.code.Symbol.ModuleResolutionFlags; import static com.sun.tools.javac.code.TypeTag.CLASS; @@ -141,6 +141,7 @@ public class Modules extends JCTree.Visitor { private final Symtab syms; private final Attr attr; private final Check chk; + private final Preview preview; private final DeferredLintHandler deferredLintHandler; private final TypeEnvs typeEnvs; private final Types types; @@ -150,6 +151,7 @@ public class Modules extends JCTree.Visitor { private final Target target; private final boolean allowModules; private final boolean allowAccessIntoSystem; + private final boolean allowRequiresTransitiveJavaBase; public final boolean multiModuleMode; @@ -192,6 +194,7 @@ protected Modules(Context context) { syms = Symtab.instance(context); attr = Attr.instance(context); chk = Check.instance(context); + preview = Preview.instance(context); deferredLintHandler = DeferredLintHandler.instance(context); typeEnvs = TypeEnvs.instance(context); moduleFinder = ModuleFinder.instance(context); @@ -203,6 +206,12 @@ protected Modules(Context context) { Options options = Options.instance(context); allowAccessIntoSystem = options.isUnset(Option.RELEASE); + + Preview preview = Preview.instance(context); + + allowRequiresTransitiveJavaBase = + Feature.JAVA_BASE_TRANSITIVE.allowedInSource(source) && + (!preview.isPreview(Feature.JAVA_BASE_TRANSITIVE) || preview.isEnabled()); lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option); multiModuleMode = fileManager.hasLocation(StandardLocation.MODULE_SOURCE_PATH); @@ -249,7 +258,12 @@ public void initModules(List trees) { public boolean enter(List trees, ClassSymbol c) { Assert.check(rootModules != null || inInitModules || !allowModules); - return enter(trees, modules -> {}, c); + return enter(trees, modules -> { + //make sure java.base is completed in all cases before continuing. + //the next steps may query if the current module participates in preview, + //and that requires a completed java.base: + syms.java_base.complete(); + }, c); } private boolean enter(List trees, Consumer> init, ClassSymbol c) { @@ -807,11 +821,16 @@ public void visitRequires(JCRequires tree) { allRequires.add(msym); Set flags = EnumSet.noneOf(RequiresFlag.class); if (tree.isTransitive) { - if (msym == syms.java_base && source.compareTo(Source.JDK10) >= 0) { - log.error(tree.pos(), Errors.ModifierNotAllowedHere(names.transitive)); - } else { - flags.add(RequiresFlag.TRANSITIVE); + if (msym == syms.java_base && + !allowRequiresTransitiveJavaBase && + !preview.participatesInPreview(syms, sym)) { + if (source.compareTo(Source.JDK10) >= 0) { + log.error(DiagnosticFlag.SOURCE_LEVEL, + tree.pos(), + Feature.JAVA_BASE_TRANSITIVE.error(source.name)); + } } + flags.add(RequiresFlag.TRANSITIVE); } if (tree.isStaticPhase) { if (msym == syms.java_base && source.compareTo(Source.JDK10) >= 0) { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index b6d7e16690283..43a0c61a069bd 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -2149,23 +2149,32 @@ public interface RecoveryLoadClass { return null; }; - private final RecoveryLoadClass starImportScopeRecovery = (env, name) -> { - Scope importScope = env.toplevel.starImportScope; - Symbol existing = importScope.findFirst(Convert.shortName(name), - sym -> sym.kind == TYP && sym.flatName() == name); + private final RecoveryLoadClass starImportScopeRecovery = + onDemandImportScopeRecovery(false); - if (existing != null) { - try { - existing = finder.loadClass(existing.packge().modle, name); + private final RecoveryLoadClass moduleImportScopeRecovery = + onDemandImportScopeRecovery(true); + + private RecoveryLoadClass onDemandImportScopeRecovery(boolean moduleImportScope) { + return (env, name) -> { + Scope importScope = moduleImportScope ? env.toplevel.moduleImportScope + : env.toplevel.starImportScope; + Symbol existing = importScope.findFirst(Convert.shortName(name), + sym -> sym.kind == TYP && sym.flatName() == name); + + if (existing != null) { + try { + existing = finder.loadClass(existing.packge().modle, name); - return new InvisibleSymbolError(env, true, existing); - } catch (CompletionFailure cf) { - //ignore + return new InvisibleSymbolError(env, true, existing); + } catch (CompletionFailure cf) { + //ignore + } } - } - return null; - }; + return null; + }; + } Symbol lookupPackage(Env env, Name name) { PackageSymbol pack = syms.lookupPackage(env.toplevel.modle, name); @@ -2433,6 +2442,11 @@ Symbol findType(Env env, Name name) { sym = findGlobalType(env, env.toplevel.starImportScope, name, starImportScopeRecovery); if (sym.exists()) return sym; else bestSoFar = bestOf(bestSoFar, sym); + + sym = findGlobalType(env, env.toplevel.moduleImportScope, name, moduleImportScopeRecovery); + if (sym.exists()) return sym; + + else bestSoFar = bestOf(bestSoFar, sym); } return bestSoFar; @@ -3730,11 +3744,10 @@ class ConstructorReferenceLookupHelper extends ReferenceLookupHelper { @Override protected Symbol lookup(Env env, MethodResolutionPhase phase) { - Symbol sym = needsInference ? + return needsInference ? findDiamond(env, site, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) : findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()); - return enclosingInstanceMissing(env, site) ? new BadConstructorReferenceError(sym) : sym; } @Override @@ -3779,6 +3792,63 @@ Symbol lookupMethod(Env env, DiagnosticPosition pos, Symbol locatio } } + /** + * Find a "valid" reference to an enclosing 'A.this' such that A is a subclass of the provided class symbol. + * A reference to an enclosing 'A.this' is "valid" if (a) we're not in the early-construction context for A + * and (b) if the current class is not an inner class of A. + */ + Symbol findSelfContaining(DiagnosticPosition pos, + Env env, + TypeSymbol c, + boolean isSuper) { + Env env1 = isSuper ? env.outer : env; + boolean staticOnly = false; + while (env1.outer != null) { + if (isStatic(env1)) staticOnly = true; + if (env1.enclClass.sym.isSubClass(c, types)) { + Symbol sym = env1.info.scope.findFirst(names._this); + if (sym != null) { + if (staticOnly) { + // current class is not an inner class, stop search + return new StaticError(sym); + } else if (env1.info.ctorPrologue && !isAllowedEarlyReference(pos, env1, (VarSymbol)sym)) { + // early construction context, stop search + return new RefBeforeCtorCalledError(sym); + } else { + // found it + return sym; + } + } + } + if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; + env1 = env1.outer; + } + return varNotFound; + } + + /** + * Resolve the (method) owner of a local class. This can fail if the local class + * is referenced from a static context nested inside the local class. Effectively, + * this lookup succeeds if we can access a local variable declared inside the owner + * method from the provided env. + */ + Symbol findLocalClassOwner(Env env, TypeSymbol c) { + Symbol owner = c.owner; + Assert.check(owner.kind == MTH); + Env env1 = env; + boolean staticOnly = false; + while (env1.outer != null) { + if (env1.info.scope.owner == owner) { + return (staticOnly) ? + new BadLocalClassCreation(c) : + owner; + } + if (isStatic(env1)) staticOnly = true; + env1 = env1.outer; + } + return methodNotFound; + } + /** * Resolve `c.name' where name == this or name == super. * @param pos The position to use for error reporting. @@ -3803,15 +3873,15 @@ Symbol resolveSelf(DiagnosticPosition pos, else if (env1.info.ctorPrologue && !isAllowedEarlyReference(pos, env1, (VarSymbol)sym)) sym = new RefBeforeCtorCalledError(sym); return accessBase(sym, pos, env.enclClass.sym.type, - name, true); + name, true); } } if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; } if (c.isInterface() && - name == names._super && !isStatic(env) && - types.isDirectSuperInterface(c, env.enclClass.sym)) { + name == names._super && !isStatic(env) && + types.isDirectSuperInterface(c, env.enclClass.sym)) { //this might be a default super call if one of the superinterfaces is 'c' for (Type t : pruneInterfaces(env.enclClass.type)) { if (t.tsym == c) { @@ -3826,8 +3896,8 @@ else if (env1.info.ctorPrologue && !isAllowedEarlyReference(pos, env1, (VarSymbo for (Type i : types.directSupertypes(env.enclClass.type)) { if (i.tsym.isSubClass(c, types) && i.tsym != c) { log.error(pos, - Errors.IllegalDefaultSuperCall(c, - Fragments.RedundantSupertype(c, i))); + Errors.IllegalDefaultSuperCall(c, + Fragments.RedundantSupertype(c, i))); return syms.errSymbol; } } @@ -3934,76 +4004,6 @@ public boolean isEarlyReference(Env env, JCTree base, VarSymbol v) (base == null || TreeInfo.isExplicitThisReference(types, (ClassType)env.enclClass.type, base)); } - /** - * Resolve `c.this' for an enclosing class c that contains the - * named member. - * @param pos The position to use for error reporting. - * @param env The environment current at the expression. - * @param member The member that must be contained in the result. - */ - Symbol resolveSelfContaining(DiagnosticPosition pos, - Env env, - Symbol member, - boolean isSuperCall) { - Symbol sym = resolveSelfContainingInternal(env, member, isSuperCall); - if (sym == null) { - log.error(pos, Errors.EnclClassRequired(member)); - return syms.errSymbol; - } else { - return accessBase(sym, pos, env.enclClass.sym.type, sym.name, true); - } - } - - boolean enclosingInstanceMissing(Env env, Type type) { - if (type.hasTag(CLASS) && type.getEnclosingType().hasTag(CLASS)) { - Symbol encl = resolveSelfContainingInternal(env, type.tsym, false); - return encl == null || encl.kind.isResolutionError(); - } - return false; - } - - private Symbol resolveSelfContainingInternal(Env env, - Symbol member, - boolean isSuperCall) { - Name name = names._this; - Env env1 = isSuperCall ? env.outer : env; - boolean staticOnly = false; - if (env1 != null) { - while (env1 != null && env1.outer != null) { - if (isStatic(env1)) staticOnly = true; - if (env1.enclClass.sym.isSubClass(member.owner.enclClass(), types)) { - Symbol sym = env1.info.scope.findFirst(name); - if (sym != null) { - if (staticOnly) sym = new StaticError(sym); - return sym; - } - } - if ((env1.enclClass.sym.flags() & STATIC) != 0) - staticOnly = true; - env1 = env1.outer; - } - } - return null; - } - - /** - * Resolve an appropriate implicit this instance for t's container. - * JLS 8.8.5.1 and 15.9.2 - */ - Type resolveImplicitThis(DiagnosticPosition pos, Env env, Type t) { - return resolveImplicitThis(pos, env, t, false); - } - - Type resolveImplicitThis(DiagnosticPosition pos, Env env, Type t, boolean isSuperCall) { - Type thisType = (t.tsym.owner.kind.matches(KindSelector.VAL_MTH) - ? resolveSelf(pos, env, t.getEnclosingType().tsym, names._this) - : resolveSelfContaining(pos, env, t.tsym, isSuperCall)).type; - if (env.info.ctorPrologue && thisType.tsym == env.enclClass.sym) { - log.error(pos, Errors.CantRefBeforeCtorCalled(names._this)); - } - return thisType; - } - /* *************************************************************************** * ResolveError classes, indicating error situations when accessing symbols ****************************************************************************/ @@ -4727,6 +4727,28 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, } } + /** + * Specialization of {@link StaticError} for illegal + * creation of local class instances from a static context. + */ + class BadLocalClassCreation extends StaticError { + BadLocalClassCreation(Symbol sym) { + super(sym, "bad local class creation"); + } + + @Override + JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, + DiagnosticPosition pos, + Symbol location, + Type site, + Name name, + List argtypes, + List typeargtypes) { + return diags.create(dkind, log.currentSource(), pos, + "local.cant.be.inst.static", kindName(sym), sym); + } + } + /** * Specialization of {@link InvalidSymbolError} for illegal * early accesses within a constructor prologue. @@ -4886,23 +4908,6 @@ JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol } } - /** - * BadConstructorReferenceError error class indicating that a constructor reference symbol has been found, - * but pointing to a class for which an enclosing instance is not available. - */ - class BadConstructorReferenceError extends InvalidSymbolError { - - public BadConstructorReferenceError(Symbol sym) { - super(MISSING_ENCL, sym, "BadConstructorReferenceError"); - } - - @Override - JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List argtypes, List typeargtypes) { - return diags.create(dkind, log.currentSource(), pos, - "cant.access.inner.cls.constr", site.tsym.name, argtypes, site.getEnclosingType()); - } - } - class BadClassFileError extends InvalidSymbolError { private final CompletionFailure ex; diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java index b518d7edb4b3a..40dcf854ff91c 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java @@ -220,6 +220,7 @@ void finishImports(JCCompilationUnit toplevel, Runnable resolve) { chk.checkImportedPackagesObservable(toplevel); toplevel.namedImportScope.finalizeScope(); toplevel.starImportScope.finalizeScope(); + toplevel.moduleImportScope.finalizeScope(); } catch (CompletionFailure cf) { chk.completionError(toplevel.pos(), cf); } finally { @@ -331,7 +332,7 @@ private void implicitImports(JCCompilationUnit tree, Env env) { throw new Abort(); } importAll(make.at(tree.pos()).Import(make.Select(make.QualIdent(javaLang.owner), javaLang), false), - javaLang, env); + javaLang, env, false); List defs = tree.getTypeDecls(); boolean isImplicitClass = !defs.isEmpty() && @@ -341,7 +342,7 @@ private void implicitImports(JCCompilationUnit tree, Env env) { doModuleImport(make.ModuleImport(make.QualIdent(syms.java_base))); if (peekTypeExists(syms.ioType.tsym)) { doImport(make.Import(make.Select(make.QualIdent(syms.ioType.tsym), - names.asterisk), true)); + names.asterisk), true), false); } } } @@ -413,7 +414,7 @@ private void handleImports(List imports) { if (imp instanceof JCModuleImport mimp) { doModuleImport(mimp); } else { - doImport((JCImport) imp); + doImport((JCImport) imp, false); } } } @@ -438,7 +439,7 @@ private void checkClassPackageClash(JCPackageDecl tree) { annotate.annotateLater(tree.annotations, env, env.toplevel.packge, tree.pos()); } - private void doImport(JCImport tree) { + private void doImport(JCImport tree, boolean fromModuleImport) { JCFieldAccess imp = tree.qualid; Name name = TreeInfo.name(imp); @@ -450,16 +451,20 @@ private void doImport(JCImport tree) { if (name == names.asterisk) { // Import on demand. chk.checkCanonical(imp.selected); - if (tree.staticImport) + if (tree.staticImport) { + Assert.check(!fromModuleImport); importStaticAll(tree, p, env); - else - importAll(tree, p, env); + } else { + importAll(tree, p, env, fromModuleImport); + } } else { // Named type import. if (tree.staticImport) { + Assert.check(!fromModuleImport); importNamedStatic(tree, p, name, localEnv); chk.checkCanonical(imp.selected); } else { + Assert.check(!fromModuleImport); Type importedType = attribImportType(imp, localEnv); Type originalType = importedType.getOriginalType(); TypeSymbol c = originalType.hasTag(CLASS) ? originalType.tsym : importedType.tsym; @@ -506,7 +511,7 @@ private void doModuleImport(JCModuleImport tree) { JCImport nestedImport = make.at(tree.pos) .Import(make.Select(make.QualIdent(pkg), names.asterisk), false); - doImport(nestedImport); + doImport(nestedImport, true); } for (RequiresDirective requires : currentModule.requires) { @@ -542,8 +547,13 @@ Type attribImportType(JCTree tree, Env env) { */ private void importAll(JCImport imp, final TypeSymbol tsym, - Env env) { - env.toplevel.starImportScope.importAll(types, tsym.members(), typeImportFilter, imp, cfHandler); + Env env, + boolean fromModuleImport) { + StarImportScope targetScope = + fromModuleImport ? env.toplevel.moduleImportScope + : env.toplevel.starImportScope; + + targetScope.importAll(types, tsym.members(), typeImportFilter, imp, cfHandler); } /** Import all static members of a class or package on demand. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 233629e10bb56..f70b96697b37b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -199,6 +199,9 @@ public class ClassReader { /** The minor version number of the class file being read. */ int minorVersion; + /** true if the class file being read is a preview class file. */ + boolean previewClassFile; + /** UTF-8 validation level */ Convert.Validation utf8validation; @@ -1200,7 +1203,9 @@ protected void read(Symbol sym, int attrLen) { ModuleSymbol rsym = poolReader.getModule(nextChar()); Set flags = readRequiresFlags(nextChar()); if (rsym == syms.java_base && majorVersion >= V54.major) { - if (flags.contains(RequiresFlag.TRANSITIVE)) { + if (flags.contains(RequiresFlag.TRANSITIVE) && + (majorVersion != Version.MAX().major || !previewClassFile) && + !preview.participatesInPreview(syms, msym)) { throw badClassFile("bad.requires.flag", RequiresFlag.TRANSITIVE); } if (flags.contains(RequiresFlag.STATIC_PHASE)) { @@ -3185,7 +3190,7 @@ private void readClassBuffer(ClassSymbol c) throws IOException { majorVersion = nextChar(); int maxMajor = Version.MAX().major; int maxMinor = Version.MAX().minor; - boolean previewClassFile = + previewClassFile = minorVersion == ClassFile.PREVIEW_MINOR_VERSION; if (majorVersion > maxMajor || majorVersion * 1000 + minorVersion < diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java index a93f5a9a794b3..0bbcd56293f47 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -667,7 +667,8 @@ void reportDanglingDocComment(Comment c) { var pos = c.getPos(); if (pos != null) { deferredLintHandler.report(lint -> { - if (lint.isEnabled(Lint.LintCategory.DANGLING_DOC_COMMENTS)) { + if (lint.isEnabled(Lint.LintCategory.DANGLING_DOC_COMMENTS) && + !shebang(c, pos)) { log.warning(Lint.LintCategory.DANGLING_DOC_COMMENTS, pos, Warnings.DanglingDocComment); } @@ -675,6 +676,14 @@ void reportDanglingDocComment(Comment c) { } } + /** Returns true for a comment that acts similarly to shebang in UNIX */ + private boolean shebang(Comment c, JCDiagnostic.DiagnosticPosition pos) { + var src = log.currentSource(); + return c.getStyle() == Comment.CommentStyle.JAVADOC_LINE && + c.getPos().getStartPosition() == 0 && + src.getLineNumber(pos.getEndPosition(src.getEndPosTable())) == 1; + } + /** * Ignores any recent documentation comments found by the scanner, * such as those that cannot be associated with a nearby declaration. diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index a24dd2f95bd48..bd666f3427dd7 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -921,10 +921,6 @@ compiler.misc.unexpected.ret.val=\ compiler.err.mod.not.allowed.here=\ modifier {0} not allowed here -# 0: name -compiler.err.modifier.not.allowed.here=\ - modifier {0} not allowed here - compiler.err.intf.not.allowed.here=\ interface not allowed here @@ -1099,11 +1095,6 @@ compiler.misc.not.def.access.class.intf.cant.access.reason=\ {1}.{0} in package {2} is not accessible\n\ ({3}) -# 0: symbol, 1: list of type, 2: type -compiler.misc.cant.access.inner.cls.constr=\ - cannot access constructor {0}({1})\n\ - an enclosing instance of type {2} is not in scope - # 0: symbol, 1: symbol compiler.err.not.def.public.cant.access=\ {0} is not public in {1}; cannot be accessed from outside package @@ -2887,6 +2878,11 @@ compiler.err.abstract.cant.be.accessed.directly=\ compiler.err.non-static.cant.be.ref=\ non-static {0} {1} cannot be referenced from a static context +## The first argument ({0}) is a "kindname". +# 0: symbol kind, 1: symbol +compiler.err.local.cant.be.inst.static=\ + local {0} {1} cannot be instantiated from a static context + # 0: symbol kind, 1: symbol compiler.misc.bad.static.method.in.unbound.lookup=\ unexpected static {0} {1} found in unbound lookup @@ -3252,6 +3248,9 @@ compiler.misc.feature.flexible.constructors=\ compiler.misc.feature.module.imports=\ module imports +compiler.misc.feature.java.base.transitive=\ + transitive modifier for java.base + compiler.warn.underscore.as.identifier=\ as of release 9, ''_'' is a keyword, and may not be used as an identifier diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java index 003f70eeecc2e..a2837013506e4 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java @@ -538,6 +538,8 @@ public static class JCCompilationUnit extends JCTree implements CompilationUnitT public NamedImportScope namedImportScope; /** A scope for all import-on-demands. */ public StarImportScope starImportScope; + /** A scope for all single module imports. */ + public StarImportScope moduleImportScope; /** Line starting positions, defined only if option -g is set. */ public Position.LineMap lineMap = null; /** A table that stores all documentation comments indexed by the tree diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java index b4c6f804a2f40..218099ac6626a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java @@ -1138,26 +1138,17 @@ boolean isUnqualifiable(Symbol sym) { sym.owner.kind == MTH || sym.owner.kind == VAR) { return true; } else if (sym.kind == TYP && toplevel != null) { - Iterator it = toplevel.namedImportScope.getSymbolsByName(sym.name).iterator(); - if (it.hasNext()) { - Symbol s = it.next(); - return - s == sym && - !it.hasNext(); - } - it = toplevel.packge.members().getSymbolsByName(sym.name).iterator(); - if (it.hasNext()) { - Symbol s = it.next(); - return - s == sym && - !it.hasNext(); - } - it = toplevel.starImportScope.getSymbolsByName(sym.name).iterator(); - if (it.hasNext()) { - Symbol s = it.next(); - return - s == sym && - !it.hasNext(); + for (Scope scope : new Scope[] {toplevel.namedImportScope, + toplevel.packge.members(), + toplevel.starImportScope, + toplevel.moduleImportScope}) { + Iterator it = scope.getSymbolsByName(sym.name).iterator(); + if (it.hasNext()) { + Symbol s = it.next(); + return + s == sym && + !it.hasNext(); + } } } return sym.kind == TYP && sym.isImplicit(); diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java index 18ccda542a002..88a74e73edac9 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/Config.java @@ -31,8 +31,6 @@ import java.nio.charset.StandardCharsets; import java.util.*; -import java.security.*; - import sun.security.util.PropertyExpander; import sun.security.pkcs11.wrapper.*; @@ -58,31 +56,16 @@ final class Config { // will accept single threaded modules regardless of the setting in their // config files. private static final boolean staticAllowSingleThreadedModules; - private static final String osName; - private static final String osArch; static { - @SuppressWarnings("removal") - List props = AccessController.doPrivileged( - new PrivilegedAction<>() { - @Override - public List run() { - return List.of( - System.getProperty( - "sun.security.pkcs11.allowSingleThreadedModules", - "true"), - System.getProperty("os.name"), - System.getProperty("os.arch")); - } - } - ); - if ("false".equalsIgnoreCase(props.get(0))) { + String allowSingleThreadedModules = + System.getProperty( + "sun.security.pkcs11.allowSingleThreadedModules", "true"); + if ("false".equalsIgnoreCase(allowSingleThreadedModules)) { staticAllowSingleThreadedModules = false; } else { staticAllowSingleThreadedModules = true; } - osName = props.get(1); - osArch = props.get(2); } private static final boolean DEBUG = false; diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java index 49718e254b3e1..5d83fa106fd90 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java @@ -108,12 +108,9 @@ abstract class P11Key implements Key, Length { * */ static { - PrivilegedAction getKeyExtractionProp = - () -> System.getProperty( - "sun.security.pkcs11.disableKeyExtraction", "false"); - @SuppressWarnings("removal") String disableKeyExtraction = - AccessController.doPrivileged(getKeyExtractionProp); + System.getProperty( + "sun.security.pkcs11.disableKeyExtraction", "false"); DISABLE_NATIVE_KEYS_EXTRACTION = "true".equalsIgnoreCase(disableKeyExtraction); } diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyAgreement.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyAgreement.java index 7a47f147bf44d..6c010a4a5130e 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyAgreement.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyAgreement.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -71,14 +71,8 @@ final class P11KeyAgreement extends KeyAgreementSpi { private static class AllowKDF { - private static final boolean VALUE = getValue(); - - @SuppressWarnings("removal") - private static boolean getValue() { - return AccessController.doPrivileged( - (PrivilegedAction) - () -> Boolean.getBoolean("jdk.crypto.KeyAgreement.legacyKDF")); - } + private static final boolean VALUE = + Boolean.getBoolean("jdk.crypto.KeyAgreement.legacyKDF"); } P11KeyAgreement(Token token, String algorithm, long mechanism) { diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java index 8a2b745fe3855..5c95e381f5cb4 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -130,7 +130,7 @@ static Provider getSunJceProvider() { return p; } - @SuppressWarnings("removal") + @SuppressWarnings("deprecation") private static Provider getProvider(Provider p, String providerName, String className) { if (p != null) { @@ -140,22 +140,8 @@ private static Provider getProvider(Provider p, String providerName, if (p == null) { try { final Class c = Class.forName(className); - p = AccessController.doPrivileged( - new PrivilegedAction() { - public Provider run() { - try { - @SuppressWarnings("deprecation") - Object o = c.newInstance(); - return (Provider) o; - } catch (Exception e) { - throw new ProviderException( - "Could not find provider " + - providerName, e); - } - } - }, null, new RuntimePermission( - "accessClassInPackage." + c.getPackageName())); - } catch (ClassNotFoundException e) { + p = (Provider) c.newInstance(); + } catch (Exception e) { // Unexpected, as className is not a user but a // P11Util-internal value. throw new ProviderException("Could not find provider " + diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java index e77edc98399eb..19d56dec93c30 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java @@ -117,19 +117,13 @@ public SunPKCS11() { poller = null; } - @SuppressWarnings("removal") @Override public Provider configure(String configArg) throws InvalidParameterException { final String newConfigName = checkNull(configArg); try { - return AccessController.doPrivileged(new PrivilegedExceptionAction<>() { - @Override - public SunPKCS11 run() throws Exception { - return new SunPKCS11(new Config(newConfigName)); - } - }); - } catch (PrivilegedActionException pae) { - throw new InvalidParameterException("Error configuring SunPKCS11 provider", pae.getException()); + return new SunPKCS11(new Config(newConfigName)); + } catch (IOException ioe) { + throw new InvalidParameterException("Error configuring SunPKCS11 provider", ioe); } } @@ -1117,7 +1111,6 @@ void disable() { } // create the poller thread, if not already active - @SuppressWarnings("removal") private void createPoller() { if (poller != null) { return; @@ -1197,7 +1190,6 @@ public void run() { } // create the cleaner thread, if not already active - @SuppressWarnings("removal") private void createCleaner() { cleaner = new NativeResourceCleaner(); Thread t = InnocuousThread.newSystemThread( @@ -1210,7 +1202,6 @@ private void createCleaner() { } // destroy the token. Called if we detect that it has been removed - @SuppressWarnings("removal") synchronized void uninitToken(Token token) { if (this.token != token) { // mismatch, our token must already be destroyed @@ -1219,12 +1210,7 @@ synchronized void uninitToken(Token token) { destroyPoller(); this.token = null; // unregister all algorithms - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - clear(); - return null; - } - }); + clear(); // keep polling for token insertion unless configured not to if (removable && !config.getDestroyTokenAfterLogout()) { createPoller(); @@ -1386,36 +1372,29 @@ private void initToken(CK_SLOT_INFO slotInfo) throws PKCS11Exception { } // register algorithms in provider - @SuppressWarnings("removal") - var dummy = AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - for (Map.Entry entry - : supportedAlgs.entrySet()) { - Descriptor d = entry.getKey(); - int mechanism = entry.getValue().intValue(); - Service s = d.service(token, mechanism); - putService(s); - } - if (((token.tokenInfo.flags & CKF_RNG) != 0) - && config.isEnabled(PCKM_SECURERANDOM) - && !token.sessionManager.lowMaxSessions()) { - // do not register SecureRandom if the token does - // not support many sessions. if we did, we might - // run out of sessions in the middle of a - // nextBytes() call where we cannot fail over. - putService(new P11Service(token, SR, "PKCS11", - "sun.security.pkcs11.P11SecureRandom", null, - PCKM_SECURERANDOM)); - } - if (config.isEnabled(PCKM_KEYSTORE)) { - putService(new P11Service(token, KS, "PKCS11", - "sun.security.pkcs11.P11KeyStore", - List.of("PKCS11-" + config.getName()), - PCKM_KEYSTORE)); - } - return null; - } - }); + for (Map.Entry entry : supportedAlgs.entrySet()) { + Descriptor d = entry.getKey(); + int mechanism = entry.getValue().intValue(); + Service s = d.service(token, mechanism); + putService(s); + } + if (((token.tokenInfo.flags & CKF_RNG) != 0) + && config.isEnabled(PCKM_SECURERANDOM) + && !token.sessionManager.lowMaxSessions()) { + // do not register SecureRandom if the token does + // not support many sessions. if we did, we might + // run out of sessions in the middle of a + // nextBytes() call where we cannot fail over. + putService(new P11Service(token, SR, "PKCS11", + "sun.security.pkcs11.P11SecureRandom", null, + PCKM_SECURERANDOM)); + } + if (config.isEnabled(PCKM_KEYSTORE)) { + putService(new P11Service(token, KS, "PKCS11", + "sun.security.pkcs11.P11KeyStore", + List.of("PKCS11-" + config.getName()), + PCKM_KEYSTORE)); + } this.token = token; if (cleaner == null) { @@ -1621,10 +1600,6 @@ public String toString() { * @throws IllegalStateException if the provider requires configuration * and Provider.configure has not been called * @throws LoginException if the login operation fails - * @throws SecurityException if the does not pass a security check for - * SecurityPermission("authProvider.name"), - * where name is the value returned by - * this provider's getName method */ public void login(Subject subject, CallbackHandler handler) throws LoginException { @@ -1633,17 +1608,6 @@ public void login(Subject subject, CallbackHandler handler) throw new IllegalStateException("Configuration is required"); } - // security check - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - if (debug != null) { - debug.println("checking login permission"); - } - sm.checkPermission(new SecurityPermission - ("authProvider." + this.getName())); - } - if (!hasValidToken()) { throw new LoginException("No token present"); @@ -1753,24 +1717,12 @@ public void login(Subject subject, CallbackHandler handler) * @throws IllegalStateException if the provider requires configuration * and Provider.configure has not been called * @throws LoginException if the logout operation fails - * @throws SecurityException if the does not pass a security check for - * SecurityPermission("authProvider.name"), - * where name is the value returned by - * this provider's getName method */ public void logout() throws LoginException { if (!isConfigured()) { throw new IllegalStateException("Configuration is required"); } - // security check - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission - (new SecurityPermission("authProvider." + this.getName())); - } - if (!hasValidToken()) { // app may call logout for cleanup, allow return; @@ -1844,11 +1796,6 @@ public void logout() throws LoginException { * * @throws IllegalStateException if the provider requires configuration * and Provider.configure has not been called - * @throws SecurityException if the caller does not pass a - * security check for - * SecurityPermission("authProvider.name"), - * where name is the value returned by - * this provider's getName method */ public void setCallbackHandler(CallbackHandler handler) { @@ -1856,14 +1803,6 @@ public void setCallbackHandler(CallbackHandler handler) { throw new IllegalStateException("Configuration is required"); } - // security check - @SuppressWarnings("removal") - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission - (new SecurityPermission("authProvider." + this.getName())); - } - synchronized (LOCK_HANDLER) { pHandler = handler; } @@ -1887,60 +1826,51 @@ private CallbackHandler getCallbackHandler(CallbackHandler handler) { return pHandler; } - try { - if (debug != null) { - debug.println("getting default callback handler"); - } - - @SuppressWarnings("removal") - CallbackHandler myHandler = AccessController.doPrivileged - (new PrivilegedExceptionAction() { - public CallbackHandler run() throws Exception { + if (debug != null) { + debug.println("getting default callback handler"); + } - String defaultHandler = - java.security.Security.getProperty - ("auth.login.defaultCallbackHandler"); + String defaultHandler = Security.getProperty + ("auth.login.defaultCallbackHandler"); - if (defaultHandler == null || - defaultHandler.length() == 0) { + if (defaultHandler == null || defaultHandler.length() == 0) { - // ok - if (debug != null) { - debug.println("no default handler set"); - } - return null; - } + // ok + if (debug != null) { + debug.println("no default handler set"); + } + return null; + } - Class c = Class.forName - (defaultHandler, - true, - Thread.currentThread().getContextClassLoader()); - if (!javax.security.auth.callback.CallbackHandler.class.isAssignableFrom(c)) { - // not the right subtype - if (debug != null) { - debug.println("default handler " + defaultHandler + - " is not a CallbackHandler"); - } - return null; - } - @SuppressWarnings("deprecation") - Object result = c.newInstance(); - return (CallbackHandler)result; + try { + Class c = Class.forName + (defaultHandler, + true, + Thread.currentThread().getContextClassLoader()); + if (!CallbackHandler.class.isAssignableFrom(c)) { + // not the right subtype + if (debug != null) { + debug.println("default handler " + defaultHandler + + " is not a CallbackHandler"); } - }); + return null; + } + @SuppressWarnings("deprecation") + Object result = c.newInstance(); + CallbackHandler myHandler = (CallbackHandler)result; // save it pHandler = myHandler; return myHandler; - } catch (PrivilegedActionException pae) { + } catch (ReflectiveOperationException roe) { // ok if (debug != null) { debug.println("Unable to load default callback handler"); - pae.printStackTrace(); + roe.printStackTrace(); } } + return null; } - return null; } private Object writeReplace() throws ObjectStreamException { diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java index f7dfd05500093..6ce50d9d695b3 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java @@ -51,9 +51,6 @@ import java.io.IOException; import java.util.*; -import java.security.AccessController; -import java.security.PrivilegedAction; - import sun.security.util.Debug; import sun.security.pkcs11.P11Util; @@ -80,16 +77,12 @@ public class PKCS11 { private static final String PKCS11_WRAPPER = "j2pkcs11"; static { - // cannot use LoadLibraryAction because that would make the native - // library available to the bootclassloader, but we run in the - // extension classloader. - @SuppressWarnings({"removal", "restricted"}) - var dummy = AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - System.loadLibrary(PKCS11_WRAPPER); - return null; - } - }); + loadAndInitializeLibrary(); + } + + @SuppressWarnings("restricted") + private static void loadAndInitializeLibrary() { + System.loadLibrary(PKCS11_WRAPPER); boolean enableDebug = Debug.getInstance("sunpkcs11") != null; initializeLibrary(enableDebug); } diff --git a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java index c9ffca89ec70f..72861d9c30da9 100644 --- a/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java +++ b/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/HeapHprofBinWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2024, 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 @@ -1005,56 +1005,56 @@ protected void writePrimitiveArray(TypeArray array) throws IOException { private void writeBooleanArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = BOOLEAN_BASE_OFFSET + index * BOOLEAN_SIZE; + long offset = (long) BOOLEAN_BASE_OFFSET + index * BOOLEAN_SIZE; out.writeBoolean(array.getHandle().getJBooleanAt(offset)); } } private void writeByteArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = BYTE_BASE_OFFSET + index * BYTE_SIZE; + long offset = (long) BYTE_BASE_OFFSET + index * BYTE_SIZE; out.writeByte(array.getHandle().getJByteAt(offset)); } } private void writeShortArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = SHORT_BASE_OFFSET + index * SHORT_SIZE; + long offset = (long) SHORT_BASE_OFFSET + index * SHORT_SIZE; out.writeShort(array.getHandle().getJShortAt(offset)); } } private void writeIntArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = INT_BASE_OFFSET + index * INT_SIZE; + long offset = (long) INT_BASE_OFFSET + index * INT_SIZE; out.writeInt(array.getHandle().getJIntAt(offset)); } } private void writeLongArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = LONG_BASE_OFFSET + index * LONG_SIZE; + long offset = (long) LONG_BASE_OFFSET + index * LONG_SIZE; out.writeLong(array.getHandle().getJLongAt(offset)); } } private void writeCharArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = CHAR_BASE_OFFSET + index * CHAR_SIZE; + long offset = (long) CHAR_BASE_OFFSET + index * CHAR_SIZE; out.writeChar(array.getHandle().getJCharAt(offset)); } } private void writeFloatArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = FLOAT_BASE_OFFSET + index * FLOAT_SIZE; + long offset = (long) FLOAT_BASE_OFFSET + index * FLOAT_SIZE; out.writeFloat(array.getHandle().getJFloatAt(offset)); } } private void writeDoubleArray(TypeArray array, int length) throws IOException { for (int index = 0; index < length; index++) { - long offset = DOUBLE_BASE_OFFSET + index * DOUBLE_SIZE; + long offset = (long) DOUBLE_BASE_OFFSET + index * DOUBLE_SIZE; out.writeDouble(array.getHandle().getJDoubleAt(offset)); } } diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java index f36215ffe1235..346b00eda5eea 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ByteVector.java @@ -4101,7 +4101,7 @@ static long booleanArrayAddress(boolean[] a, int index) { @ForceInline static long byteArrayAddress(byte[] a, int index) { - return Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; } // ================================================ diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java index d7fc2cfa97d1c..5b3a25baa58be 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java @@ -3621,7 +3621,7 @@ static long arrayAddress(double[] a, int index) { @ForceInline static long byteArrayAddress(byte[] a, int index) { - return Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; } // ================================================ diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java index 5a7cdb89dde16..f5f5a5a4e7ea7 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/Float16.java @@ -95,8 +95,7 @@ // Currently Float16 is a value-based class and in future it is // expected to be aligned with Value Classes and Object as described in // JEP-401 (https://openjdk.org/jeps/401). -// @jdk.internal.MigratedValueClass -// @jdk.internal.ValueBased +@jdk.internal.ValueBased public final class Float16 extends Number implements Comparable { @@ -323,7 +322,7 @@ public static Float16 valueOf(long value) { * @param f a {@code float} */ public static Float16 valueOf(float f) { - return new Float16(Float.floatToFloat16(f)); + return new Float16(floatToFloat16(f)); } /** diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java index 098eed06095af..a3686d467a746 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/FloatVector.java @@ -3571,7 +3571,7 @@ static long arrayAddress(float[] a, int index) { @ForceInline static long byteArrayAddress(byte[] a, int index) { - return Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; } // ================================================ diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java index 6cb81767cdd60..390c80260831e 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/IntVector.java @@ -3739,7 +3739,7 @@ static long arrayAddress(int[] a, int index) { @ForceInline static long byteArrayAddress(byte[] a, int index) { - return Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; } // ================================================ diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java index a740c9d49cf83..43fedc2693b23 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/LongVector.java @@ -3674,7 +3674,7 @@ static long arrayAddress(long[] a, int index) { @ForceInline static long byteArrayAddress(byte[] a, int index) { - return Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; } // ================================================ diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java index 0e3ff9aaa8776..552967d82e70d 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java @@ -4092,7 +4092,7 @@ static long charArrayAddress(char[] a, int index) { @ForceInline static long byteArrayAddress(byte[] a, int index) { - return Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; } // ================================================ diff --git a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template index b5f3a4b7d8707..7eb1d9810b1e9 100644 --- a/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template +++ b/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template @@ -5310,7 +5310,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> { @ForceInline static long byteArrayAddress(byte[] a, int index) { - return Unsafe.ARRAY_BYTE_BASE_OFFSET + index; + return (long) Unsafe.ARRAY_BYTE_BASE_OFFSET + index; } // ================================================ diff --git a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java index f40b966262541..11de96b7fc339 100644 --- a/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java +++ b/src/jdk.internal.le/share/classes/jdk/internal/org/jline/JdkConsoleProviderImpl.java @@ -98,6 +98,11 @@ public String readln(String prompt) { return getDelegate(true).readln(prompt); } + @Override + public String readln() { + return getDelegate(true).readln(); + } + @Override public JdkConsole format(Locale locale, String format, Object... args) { JdkConsole delegate = getDelegate(false); @@ -224,6 +229,11 @@ public String readln(String prompt) { } } + @Override + public String readln() { + return readLine(); + } + @Override public JdkConsole format(Locale locale, String format, Object ... args) { writer().format(locale, format, args).flush(); @@ -242,7 +252,12 @@ public String readLine(Locale locale, String format, Object ... args) { @Override public String readLine() { - return readLine(Locale.getDefault(Locale.Category.FORMAT), ""); + try { + initJLineIfNeeded(); + return jline.readLine(); + } catch (EndOfFileException eofe) { + return null; + } } @Override diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java index b688420681fd3..30de66b46a678 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/ModuleWriter.java @@ -41,6 +41,7 @@ import com.sun.source.doctree.DeprecatedTree; import com.sun.source.doctree.DocTree; +import java.util.stream.Collectors; import jdk.javadoc.doclet.DocletEnvironment.ModuleMode; import jdk.javadoc.internal.doclets.formats.html.Navigation.PageMode; @@ -52,9 +53,10 @@ import jdk.javadoc.internal.html.Content; import jdk.javadoc.internal.html.ContentBuilder; import jdk.javadoc.internal.html.Entity; +import jdk.javadoc.internal.html.HtmlId; import jdk.javadoc.internal.html.HtmlStyle; -import jdk.javadoc.internal.html.HtmlTag; import jdk.javadoc.internal.html.HtmlTree; +import jdk.javadoc.internal.html.RawHtml; import jdk.javadoc.internal.html.Text; /** @@ -582,10 +584,55 @@ protected void addPackagesSummary(Content summariesList) { TableHeader indirectPackagesHeader = new TableHeader(contents.fromLabel, contents.packagesLabel); if (display(indirectPackages)) { - String aepText = resources.getText("doclet.Indirect_Exports_Summary"); - var aepTable = getTable2(Text.of(aepText), indirectPackagesHeader); - addIndirectPackages(aepTable, indirectPackages); - section.add(aepTable); + ModuleElement javaBase = this.utils.elementUtils.getModuleElement("java.base"); + boolean hasRequiresTransitiveJavaBase = + ElementFilter.requiresIn(mdle.getDirectives()) + .stream() + .anyMatch(rd -> rd.isTransitive() && + javaBase.equals(rd.getDependency())); + if (hasRequiresTransitiveJavaBase) { + Map> filteredIndirectPackages = + indirectPackages.entrySet() + .stream() + .filter(e -> !e.getKey().equals(javaBase)) + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); + String aepText = resources.getText("doclet.Indirect_Exports_Summary"); + var aepTable = getTable2(Text.of(aepText), indirectPackagesHeader); + addIndirectPackages(aepTable, filteredIndirectPackages); + section.add(aepTable); + //add the preview box: + section.add(HtmlTree.BR()); + section.add(HtmlTree.BR()); + HtmlId previewRequiresTransitiveId = HtmlId.of("preview-requires-transitive-java.base"); + var previewDiv = HtmlTree.DIV(HtmlStyles.previewBlock); + previewDiv.setId(previewRequiresTransitiveId); + + Content note = + RawHtml.of(resources.getText("doclet.PreviewJavaSERequiresTransitiveJavaBase")); + + previewDiv.add(HtmlTree.DIV(HtmlStyles.previewComment, note)); + section.add(previewDiv); + + //add the Indirect Exports + filteredIndirectPackages = + indirectPackages.entrySet() + .stream() + .filter(e -> e.getKey().equals(javaBase)) + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); + String aepPreviewText = resources.getText("doclet.Indirect_Exports_Summary"); + ContentBuilder tableCaption = new ContentBuilder( + Text.of(aepPreviewText), + HtmlTree.SUP(links.createLink(previewRequiresTransitiveId, + contents.previewMark))); + var aepPreviewTable = getTable2(tableCaption, indirectPackagesHeader); + addIndirectPackages(aepPreviewTable, filteredIndirectPackages); + section.add(aepPreviewTable); + } else { + String aepText = resources.getText("doclet.Indirect_Exports_Summary"); + var aepTable = getTable2(Text.of(aepText), indirectPackagesHeader); + addIndirectPackages(aepTable, indirectPackages); + section.add(aepTable); + } } if (display(indirectOpenPackages)) { String aopText = resources.getText("doclet.Indirect_Opens_Summary"); diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties index e6faa7bbe1962..44f285f21db52 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/standard.properties @@ -431,6 +431,14 @@ doclet.ReflectivePreviewAPI={0} refers to one or more reflective preview APIs: doclet.UsesDeclaredUsingPreview={0} refers to one or more types which are declared using a preview feature of the Java language: {1}. doclet.PreviewTrailingNote1=Programs can only use {0} when preview features are enabled. doclet.PreviewTrailingNote2=Preview features may be removed in a future release, or upgraded to permanent features of the Java platform. +doclet.PreviewJavaSERequiresTransitiveJavaBase=\ +Indirect exports from the java.base module are associated \ +with the requires transitive java.base directive, which is \ +a preview feature of the Java language.
\ +Programs can only use requires transitive java.base when \ +preview features are enabled.
\ +Preview features may be removed in a future release, or upgraded \ +to permanent features of the Java Platform.
doclet.RestrictedMethod=restricted method doclet.RestrictedLeadingNote={0} is a {1} of the Java platform. doclet.RestrictedTrailingNote1=Programs can only use {0} when access to restricted methods is enabled. diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java index cccbaf14f5399..2335d882ab144 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java @@ -84,7 +84,7 @@ public void write(Attribute a, CodeAttribute lr) { int i = 0; int j = 0; print(" "); - print(attr.attributeName()); + print(attr.attributeName().stringValue()); print(": "); print("length = 0x" + toHex(data.length)); print(" (unknown attribute)"); diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/IOContext.java b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/IOContext.java index 339a3005d7ded..e22d927911c0a 100644 --- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/IOContext.java +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/IOContext.java @@ -67,6 +67,10 @@ public String readUserLine(String prompt) throws IOException { throw new UserInterruptException(""); } + public String readUserLine() throws IOException { + throw new UserInterruptException(""); + } + public Writer userOutput() { throw new UnsupportedOperationException(); } diff --git a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java index 2d06ffc529d45..d2d2ed10e6333 100644 --- a/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java +++ b/src/jdk.jshell/share/classes/jdk/internal/jshell/tool/JShellTool.java @@ -4112,6 +4112,15 @@ public String readLine(String prompt) { } } + @Override + public String readLine() throws IOError { + try { + return input.readUserLine(); + } catch (IOException ex) { + throw new IOError(ex); + } + } + @Override public char[] readPassword(String prompt) { try { diff --git a/src/jdk.jshell/share/classes/jdk/jshell/JShellConsole.java b/src/jdk.jshell/share/classes/jdk/jshell/JShellConsole.java index fe73d6965cb97..014766f9ff7c4 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/JShellConsole.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/JShellConsole.java @@ -28,6 +28,7 @@ import java.io.PrintWriter; import java.io.Reader; import java.nio.charset.Charset; +import jdk.internal.javac.PreviewFeature; /** * An interface providing functionality for {@link java.io.Console} in the user's snippet. @@ -75,6 +76,21 @@ public interface JShellConsole { */ public String readLine(String prompt) throws IOError; + /** + * Reads a single line of text from the console. + * + * @throws IOError + * If an I/O error occurs. + * + * @return A string containing the line read from the console, not + * including any line-termination characters, or {@code null} + * if an end of stream has been reached. + * @see java.io.Console#readLine() + * @since 24 + */ + @PreviewFeature(feature=PreviewFeature.Feature.IMPLICIT_CLASSES) + public String readLine() throws IOError; + /** * Provides a prompt, then reads a password or passphrase from * the console with echoing disabled. diff --git a/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java b/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java index b85b8c9ea0f30..876f61ec85675 100644 --- a/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java +++ b/src/jdk.jshell/share/classes/jdk/jshell/execution/impl/ConsoleImpl.java @@ -233,6 +233,16 @@ public String readln(String prompt) { } } + /** + * {@inheritDoc} + * + * @throws IOError {@inheritDoc} + */ + @Override + public String readln() { + return readLine(); + } + /** * {@inheritDoc} */ @@ -269,7 +279,15 @@ public String readLine(Locale locale, String format, Object... args) { */ @Override public String readLine() { - return readLine(Locale.getDefault(Locale.Category.FORMAT), ""); + try { + return sendAndReceive(() -> { + remoteInput.write(Task.READ_LINE_NO_PROMPT.ordinal()); + char[] line = readChars(); + return new String(line); + }); + } catch (IOException ex) { + throw new IOError(ex); + } } /** @@ -404,6 +422,12 @@ public synchronized void write(int b) throws IOException { bp = 0; } } + case READ_LINE_NO_PROMPT -> { + String line = console.readLine(); + char[] chars = line.toCharArray(); + sendChars(sinkOutput, chars, 0, chars.length); + bp = 0; + } case READ_PASSWORD -> { char[] data = readCharsOrNull(1); if (data != null) { @@ -478,6 +502,7 @@ private enum Task { FLUSH_OUTPUT, READ_CHARS, READ_LINE, + READ_LINE_NO_PROMPT, READ_PASSWORD, FLUSH_CONSOLE, CHARSET, diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java index 20ed86eae4f1b..9ea935551b84b 100644 --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java @@ -44,10 +44,6 @@ import java.nio.file.*; import java.nio.file.attribute.*; import java.nio.file.spi.FileSystemProvider; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.*; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -82,10 +78,8 @@ */ class ZipFileSystem extends FileSystem { // statics - @SuppressWarnings("removal") - private static final boolean isWindows = AccessController.doPrivileged( - (PrivilegedAction)()->System.getProperty("os.name") - .startsWith("Windows")); + private static final boolean isWindows = System.getProperty("os.name") + .startsWith("Windows"); private static final byte[] ROOTPATH = new byte[] { '/' }; private static final String PROPERTY_POSIX = "enablePosixFileAttributes"; private static final String PROPERTY_DEFAULT_OWNER = "defaultOwner"; @@ -168,9 +162,7 @@ class ZipFileSystem extends FileSystem { } // sm and existence check zfpath.getFileSystem().provider().checkAccess(zfpath, AccessMode.READ); - @SuppressWarnings("removal") - boolean writeable = AccessController.doPrivileged( - (PrivilegedAction)()->Files.isWritable(zfpath)); + boolean writeable = Files.isWritable(zfpath); this.readOnly = !writeable; this.zc = ZipCoder.get(nameEncoding); this.rootdir = new ZipPath(this, new byte[]{'/'}); @@ -244,23 +236,14 @@ private static boolean isTrue(Map env, String name) { // If not specified in env, it is the owner of the archive. If no owner can // be determined, we try to go with system property "user.name". If that's not // accessible, we return "". - @SuppressWarnings("removal") private UserPrincipal initOwner(Path zfpath, Map env) throws IOException { Object o = env.get(PROPERTY_DEFAULT_OWNER); if (o == null) { try { - PrivilegedExceptionAction pa = ()->Files.getOwner(zfpath); - return AccessController.doPrivileged(pa); - } catch (UnsupportedOperationException | PrivilegedActionException e) { - if (e instanceof UnsupportedOperationException || - e.getCause() instanceof NoSuchFileException) - { - PrivilegedAction pa = ()->System.getProperty("user.name"); - String userName = AccessController.doPrivileged(pa); - return ()->userName; - } else { - throw new IOException(e); - } + return Files.getOwner(zfpath); + } catch (UnsupportedOperationException | NoSuchFileException e) { + String userName = System.getProperty("user.name"); + return ()->userName; } } if (o instanceof String) { @@ -282,7 +265,6 @@ private UserPrincipal initOwner(Path zfpath, Map env) throws IOExcept // If not specified in env, we try to determine the group of the zip archive itself. // If this is not possible/unsupported, we will return a group principal going by // the same name as the default owner. - @SuppressWarnings("removal") private GroupPrincipal initGroup(Path zfpath, Map env) throws IOException { Object o = env.get(PROPERTY_DEFAULT_GROUP); if (o == null) { @@ -291,16 +273,9 @@ private GroupPrincipal initGroup(Path zfpath, Map env) throws IOExcep if (zfpv == null) { return defaultOwner::getName; } - PrivilegedExceptionAction pa = ()->zfpv.readAttributes().group(); - return AccessController.doPrivileged(pa); - } catch (UnsupportedOperationException | PrivilegedActionException e) { - if (e instanceof UnsupportedOperationException || - e.getCause() instanceof NoSuchFileException) - { - return defaultOwner::getName; - } else { - throw new IOException(e); - } + return zfpv.readAttributes().group(); + } catch (UnsupportedOperationException | NoSuchFileException e) { + return defaultOwner::getName; } } if (o instanceof String) { @@ -462,7 +437,6 @@ public PathMatcher getPathMatcher(String syntaxAndInput) { return (path)->pattern.matcher(path.toString()).matches(); } - @SuppressWarnings("removal") @Override public void close() throws IOException { beginWrite(); @@ -480,13 +454,9 @@ public void close() throws IOException { } beginWrite(); // lock and sync try { - AccessController.doPrivileged((PrivilegedExceptionAction)() -> { - sync(); return null; - }); + sync(); ch.close(); // close the ch just in case no update // and sync didn't close the ch - } catch (PrivilegedActionException e) { - throw (IOException)e.getException(); } finally { endWrite(); } @@ -512,10 +482,8 @@ public void close() throws IOException { synchronized (tmppaths) { for (Path p : tmppaths) { try { - AccessController.doPrivileged( - (PrivilegedExceptionAction)() -> Files.deleteIfExists(p)); - } catch (PrivilegedActionException e) { - IOException x = (IOException)e.getException(); + Files.deleteIfExists(p); + } catch (IOException x) { if (ioe == null) ioe = x; else diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java index 615d2a42e20fa..a8336b0f8f67d 100644 --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2024, 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,9 +39,6 @@ import java.nio.file.attribute.FileAttribute; import java.nio.file.attribute.FileAttributeView; import java.nio.file.spi.FileSystemProvider; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -317,17 +314,9 @@ public void setAttribute(Path path, String attribute, } ////////////////////////////////////////////////////////////// - @SuppressWarnings("removal") void removeFileSystem(Path zfpath, ZipFileSystem zfs) throws IOException { synchronized (filesystems) { - Path tempPath = zfpath; - PrivilegedExceptionAction action = tempPath::toRealPath; - try { - zfpath = AccessController.doPrivileged(action); - } catch (PrivilegedActionException e) { - throw (IOException) e.getException(); - } - filesystems.remove(zfpath, zfs); + filesystems.remove(zfpath.toRealPath(), zfs); } } } diff --git a/test/hotspot/gtest/classfile/test_stringConversion.cpp b/test/hotspot/gtest/classfile/test_stringConversion.cpp new file mode 100644 index 0000000000000..13553464229cf --- /dev/null +++ b/test/hotspot/gtest/classfile/test_stringConversion.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2024, 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. + */ + +#include "precompiled.hpp" +#include "runtime/interfaceSupport.inline.hpp" +#include "unittest.hpp" + +// Tests that string functions (hash code/equals) stay consistant when comparing equal strings and converting between strings types + +// Simple ASCII string "Java(R)!!" +// Same length in both UTF8 and Unicode +static const char static_ascii_utf8_str[] = {0x4A, 0x61, 0x76, 0x61, 0x28, 0x52, 0x29, 0x21, 0x21}; +static const jchar static_ascii_unicode_str[] = {0x004A, 0x0061, 0x0076, 0x0061, 0x0028, 0x0052, 0x0029, 0x0021, 0x0021}; + +// Complex string "Jāvá®!☺☻", UTF8 has character lengths 13122133 = 16 +static const unsigned char static_utf8_str[] = {0x4A, 0x61, 0xCC, 0x84, 0x76, 0xC3, 0xA1, 0xC2, 0xAE, 0x21, 0xE2, 0x98, 0xBA, 0xE2, 0x98, 0xBB}; +static const jchar static_unicode_str[] = { 0x004A, 0x0061, 0x0304, 0x0076, 0x00E1, 0x00AE, 0x0021, 0x263A, 0x263B}; + +static const int ASCII_LENGTH = 9; +static const size_t UTF8_LENGTH = 16; +static const int UNICODE_LENGTH = 9; + +void compare_utf8_utf8(const char* utf8_str1, const char* utf8_str2, size_t utf8_len) { + EXPECT_EQ(java_lang_String::hash_code(utf8_str1, utf8_len), java_lang_String::hash_code(utf8_str2, utf8_len)); + EXPECT_STREQ(utf8_str1, utf8_str2); +} + +void compare_utf8_unicode(const char* utf8_str, const jchar* unicode_str, size_t utf8_len, int unicode_len) { + EXPECT_EQ(java_lang_String::hash_code(utf8_str, utf8_len), java_lang_String::hash_code(unicode_str, unicode_len)); +} + +void compare_utf8_oop(const char* utf8_str, Handle oop_str, size_t utf8_len, int unicode_len) { + EXPECT_EQ(java_lang_String::hash_code(utf8_str, utf8_len), java_lang_String::hash_code(oop_str())); + EXPECT_TRUE(java_lang_String::equals(oop_str(), utf8_str, utf8_len)); +} + +void compare_unicode_unicode(const jchar* unicode_str1, const jchar* unicode_str2, int unicode_len) { + EXPECT_EQ(java_lang_String::hash_code(unicode_str1, unicode_len), java_lang_String::hash_code(unicode_str2, unicode_len)); + for (int i = 0; i < unicode_len; i++) { + EXPECT_EQ(unicode_str1[i], unicode_str2[i]); + } +} + +void compare_unicode_oop(const jchar* unicode_str, Handle oop_str, int unicode_len) { + EXPECT_EQ(java_lang_String::hash_code(unicode_str, unicode_len), java_lang_String::hash_code(oop_str())); + EXPECT_TRUE(java_lang_String::equals(oop_str(), unicode_str, unicode_len)); +} + +void compare_oop_oop(Handle oop_str1, Handle oop_str2) { + EXPECT_EQ(java_lang_String::hash_code(oop_str1()), java_lang_String::hash_code(oop_str2())); + EXPECT_TRUE(java_lang_String::equals(oop_str1(), oop_str2())); +} + +void test_utf8_convert(const char* utf8_str, size_t utf8_len, int unicode_len) { + EXPECT_TRUE(UTF8::is_legal_utf8((unsigned char*)utf8_str, strlen(utf8_str), false)); + + JavaThread* THREAD = JavaThread::current(); + ThreadInVMfromNative ThreadInVMfromNative(THREAD); + ResourceMark rm(THREAD); + HandleMark hm(THREAD); + + jchar* unicode_str_from_utf8 = NEW_RESOURCE_ARRAY(jchar, unicode_len); + UTF8::convert_to_unicode(utf8_str, unicode_str_from_utf8, unicode_len); + Handle oop_str_from_utf8 = java_lang_String::create_from_str(utf8_str, THREAD); + + compare_utf8_unicode(utf8_str, unicode_str_from_utf8, utf8_len, unicode_len); + compare_utf8_oop(utf8_str, oop_str_from_utf8, utf8_len, unicode_len); + + size_t length = unicode_len; + const char* utf8_str_from_unicode = UNICODE::as_utf8(unicode_str_from_utf8, length); + const char* utf8_str_from_oop = java_lang_String::as_utf8_string(oop_str_from_utf8()); + + EXPECT_TRUE(UTF8::is_legal_utf8((unsigned char*)utf8_str_from_unicode, strlen(utf8_str_from_unicode), false)); + EXPECT_TRUE(UTF8::is_legal_utf8((unsigned char*)utf8_str_from_oop, strlen(utf8_str_from_oop), false)); + + compare_utf8_utf8(utf8_str, utf8_str_from_unicode, utf8_len); + compare_utf8_utf8(utf8_str, utf8_str_from_oop, utf8_len); +} + +void test_unicode_convert(const jchar* unicode_str, size_t utf8_len, int unicode_len) { + JavaThread* THREAD = JavaThread::current(); + ThreadInVMfromNative ThreadInVMfromNative(THREAD); + ResourceMark rm(THREAD); + HandleMark hm(THREAD); + + size_t length = unicode_len; + const char* utf8_str_from_unicode = UNICODE::as_utf8(unicode_str, length); + Handle oop_str_from_unicode = java_lang_String::create_from_unicode(unicode_str, unicode_len, THREAD); + + EXPECT_TRUE(UTF8::is_legal_utf8((unsigned char*)utf8_str_from_unicode, strlen(utf8_str_from_unicode), false)); + + compare_utf8_unicode(utf8_str_from_unicode, unicode_str, utf8_len, unicode_len); + compare_unicode_oop(unicode_str, oop_str_from_unicode, unicode_len); + + int _; + jchar* unicode_str_from_utf8 = NEW_RESOURCE_ARRAY(jchar, unicode_len); + UTF8::convert_to_unicode(utf8_str_from_unicode, unicode_str_from_utf8, unicode_len); + const jchar* unicode_str_from_oop = java_lang_String::as_unicode_string(oop_str_from_unicode(), _, THREAD); + + compare_unicode_unicode(unicode_str, unicode_str_from_utf8, unicode_len); + compare_unicode_unicode(unicode_str, unicode_str_from_oop, unicode_len); +} + +void test_utf8_unicode_cross(const char* utf8_str, const jchar* unicode_str, size_t utf8_len, int unicode_len) { + compare_utf8_unicode(utf8_str, unicode_str, utf8_len, unicode_len); + + JavaThread* THREAD = JavaThread::current(); + ThreadInVMfromNative ThreadInVMfromNative(THREAD); + ResourceMark rm(THREAD); + HandleMark hm(THREAD); + + size_t length = unicode_len; + const char* utf8_str_from_unicode = UNICODE::as_utf8(unicode_str, length); + + jchar* unicode_str_from_utf8 = NEW_RESOURCE_ARRAY(jchar, unicode_len); + UTF8::convert_to_unicode(utf8_str, unicode_str_from_utf8, unicode_len); + + Handle oop_str_from_unicode = java_lang_String::create_from_unicode(unicode_str, unicode_len, THREAD); + Handle oop_str_from_utf8 = java_lang_String::create_from_str(utf8_str, THREAD); + + compare_utf8_utf8(utf8_str, utf8_str_from_unicode, utf8_len); + compare_utf8_oop(utf8_str, oop_str_from_unicode, utf8_len, unicode_len); + + compare_unicode_unicode(unicode_str, unicode_str_from_utf8, unicode_len); + compare_unicode_oop(unicode_str, oop_str_from_utf8, unicode_len); + + compare_utf8_oop(utf8_str_from_unicode, oop_str_from_utf8, utf8_len, unicode_len); + compare_unicode_oop(unicode_str_from_utf8, oop_str_from_unicode, unicode_len); + + compare_utf8_unicode(utf8_str_from_unicode, unicode_str_from_utf8, utf8_len, unicode_len); + compare_oop_oop(oop_str_from_utf8, oop_str_from_unicode); +} + +TEST_VM(StringConversion, fromUTF8_ascii) { + const char utf8_str[ASCII_LENGTH + 1] = { }; + memcpy((unsigned char*)utf8_str, static_ascii_utf8_str, ASCII_LENGTH); + test_utf8_convert(utf8_str, ASCII_LENGTH, ASCII_LENGTH); +} + +TEST_VM(StringConversion, fromUTF8_varlen) { + const char utf8_str[UTF8_LENGTH + 1] = { }; + memcpy((unsigned char*)utf8_str, static_utf8_str, UTF8_LENGTH); + test_utf8_convert(utf8_str, UTF8_LENGTH, UNICODE_LENGTH); +} + +TEST_VM(StringConversion, fromUnicode_ascii) { + jchar unicode_str[ASCII_LENGTH] = { }; + memcpy(unicode_str, static_ascii_unicode_str, ASCII_LENGTH * sizeof(jchar)); + test_unicode_convert(unicode_str, ASCII_LENGTH, ASCII_LENGTH); +} + +TEST_VM(StringConversion, fromUnicode_varlen) { + jchar unicode_str[UNICODE_LENGTH] = { }; + memcpy(unicode_str, static_unicode_str, UNICODE_LENGTH * sizeof(jchar)); + test_unicode_convert(unicode_str, UTF8_LENGTH, UNICODE_LENGTH); +} + +TEST_VM(StringConversion, cross_ascii) { + const char utf8_str[ASCII_LENGTH + 1] = { }; + jchar unicode_str[ASCII_LENGTH] = { }; + memcpy((unsigned char*)utf8_str, static_ascii_utf8_str, ASCII_LENGTH); + memcpy(unicode_str, static_ascii_unicode_str, ASCII_LENGTH * sizeof(jchar)); + + test_utf8_unicode_cross(utf8_str, unicode_str, ASCII_LENGTH, ASCII_LENGTH); +} + +TEST_VM(StringConversion, cross_varlen) { + const char utf8_str[UTF8_LENGTH + 1] = { }; + jchar unicode_str[UNICODE_LENGTH] = { }; + memcpy((unsigned char*)utf8_str, static_utf8_str, UTF8_LENGTH); + memcpy(unicode_str, static_unicode_str, UNICODE_LENGTH * sizeof(jchar)); + + test_utf8_unicode_cross(utf8_str, unicode_str, UTF8_LENGTH, UNICODE_LENGTH); +} diff --git a/test/hotspot/gtest/classfile/test_stringIntern.cpp b/test/hotspot/gtest/classfile/test_stringIntern.cpp new file mode 100644 index 0000000000000..69c0a5b2aa472 --- /dev/null +++ b/test/hotspot/gtest/classfile/test_stringIntern.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024, 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. + */ + +#include "precompiled.hpp" +#include "classfile/stringTable.hpp" +#include "classfile/symbolTable.hpp" +#include "runtime/interfaceSupport.inline.hpp" +#include "unittest.hpp" + +// Tests that strings are interned and returns the same string when interning from different string types + +// Simple ASCII string "Java(R)!!" +static const char static_ascii_utf8_str[] = {0x4A, 0x61, 0x76, 0x61, 0x28, 0x52, 0x29, 0x21, 0x21}; +static const size_t ASCII_LENGTH = 9; + +// Complex string "Jāvá®!☺☻", has character lengths 13122133 = 16 +static const unsigned char static_utf8_str[] = {0x4A, 0x61, 0xCC, 0x84, 0x76, 0xC3, 0xA1, 0xC2, 0xAE, 0x21, 0xE2, 0x98, 0xBA, 0xE2, 0x98, 0xBB}; +static const size_t COMPLEX_LENGTH = 16; + +void test_intern(const char* utf8_str, size_t utf8_length) { + JavaThread* THREAD = JavaThread::current(); + ThreadInVMfromNative ThreadInVMfromNative(THREAD); + HandleMark hm(THREAD); + + oop interned_string_from_utf8 = StringTable::intern(utf8_str, THREAD); + + EXPECT_TRUE(java_lang_String::equals(interned_string_from_utf8, utf8_str, utf8_length)); + EXPECT_EQ(java_lang_String::hash_code(utf8_str, utf8_length),java_lang_String::hash_code(interned_string_from_utf8)); + + Symbol* symbol_from_utf8 = SymbolTable::new_symbol(utf8_str, static_cast(utf8_length)); + oop interned_string_from_symbol = StringTable::intern(symbol_from_utf8, THREAD); + + EXPECT_EQ(interned_string_from_utf8, interned_string_from_symbol); + + oop interned_string_from_oop1 = StringTable::intern(interned_string_from_utf8, THREAD); + + EXPECT_EQ(interned_string_from_utf8, interned_string_from_oop1); + +} + +TEST_VM(StringIntern, intern_ascii) { + const char utf8_str[ASCII_LENGTH + 1] = { }; + memcpy((unsigned char*)utf8_str, static_ascii_utf8_str, ASCII_LENGTH); + test_intern(utf8_str, ASCII_LENGTH); +} + +TEST_VM(StringIntern, intern_varlen) { + const char utf8_str[COMPLEX_LENGTH + 1] = { }; + memcpy((unsigned char*)utf8_str, static_utf8_str, COMPLEX_LENGTH); + test_intern(utf8_str, COMPLEX_LENGTH); +} diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index 43f72f0be73db..ba1851708b28e 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -58,7 +58,7 @@ compiler/codecache/jmx/PoolsIndependenceTest.java 8264632 macosx-all compiler/vectorapi/reshape/TestVectorReinterpret.java 8320897 aix-ppc64,linux-ppc64le compiler/vectorapi/VectorLogicalOpIdentityTest.java 8302459 linux-x64,windows-x64 -compiler/vectorapi/VectorRebracket128Test.java#Z 8330538 generic-all +compiler/vectorapi/VectorRebracket128Test.java 8330538 generic-all compiler/jvmci/TestUncaughtErrorInCompileMethod.java 8309073 generic-all compiler/jvmci/jdk.vm.ci.code.test/src/jdk/vm/ci/code/test/DataPatchTest.java 8331704 linux-riscv64 @@ -116,6 +116,7 @@ runtime/cds/appcds/customLoader/HelloCustom_JFR.java 8241075 linux-all,windows-x runtime/Dictionary/CleanProtectionDomain.java 8341916 generic-all runtime/Dictionary/ProtectionDomainCacheTest.java 8341916 generic-all runtime/logging/ProtectionDomainVerificationTest.java 8341916 generic-all +runtime/NMT/VirtualAllocCommitMerge.java 8309698 linux-s390x # Fails with +UseCompactObjectHeaders on aarch64 runtime/cds/appcds/SharedBaseAddress.java 8340212 linux-aarch64,macosx-aarch64 diff --git a/test/hotspot/jtreg/compiler/c2/TestMergeStores.java b/test/hotspot/jtreg/compiler/c2/TestMergeStores.java index c8e8bd337ad4a..3598b8eae7103 100644 --- a/test/hotspot/jtreg/compiler/c2/TestMergeStores.java +++ b/test/hotspot/jtreg/compiler/c2/TestMergeStores.java @@ -340,8 +340,8 @@ public void runTests(RunInfo info) { set_random(aL); set_random(bL); - offset1 = Math.abs(RANDOM.nextInt()) % 100; - offset2 = Math.abs(RANDOM.nextInt()) % 100; + offset1 = RANDOM.nextInt(100); + offset2 = RANDOM.nextInt(100); vB1 = (byte)RANDOM.nextInt(); vB2 = (byte)RANDOM.nextInt(); vS1 = (short)RANDOM.nextInt(); diff --git a/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java b/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java index 3ee8fc8f45bcd..316eb5f3ce6e0 100644 --- a/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java +++ b/test/hotspot/jtreg/compiler/lib/ir_framework/CompilePhase.java @@ -104,6 +104,15 @@ public enum CompilePhase { BEFORE_MATCHING("Before matching"), MATCHING("After matching", RegexType.MACH), GLOBAL_CODE_MOTION("Global code motion", RegexType.MACH), + INITIAL_LIVENESS("Initial liveness", RegexType.MACH), + AGGRESSIVE_COALESCING("Aggressive coalescing", RegexType.MACH), + INITIAL_SPILLING("Initial spilling", RegexType.MACH), + CONSERVATIVE_COALESCING("Conservative coalescing", RegexType.MACH, ActionOnRepeat.KEEP_FIRST), + ITERATIVE_SPILLING("Iterative spilling", RegexType.MACH, ActionOnRepeat.KEEP_FIRST), + AFTER_ITERATIVE_SPILLING("After iterative spilling", RegexType.MACH), + POST_ALLOCATION_COPY_REMOVAL("Post-allocation copy removal", RegexType.MACH), + MERGE_MULTI_DEFS("Merge multiple definitions", RegexType.MACH), + FIX_UP_SPILLS("Fix up spills", RegexType.MACH), REGISTER_ALLOCATION("Register Allocation", RegexType.MACH), BLOCK_ORDERING("Block Ordering", RegexType.MACH), PEEPHOLE("Peephole", RegexType.MACH), diff --git a/test/hotspot/jtreg/compiler/vectorapi/VectorRebracket128Test.java b/test/hotspot/jtreg/compiler/vectorapi/VectorRebracket128Test.java index 4f7f03590dda3..7e6a457d25e61 100644 --- a/test/hotspot/jtreg/compiler/vectorapi/VectorRebracket128Test.java +++ b/test/hotspot/jtreg/compiler/vectorapi/VectorRebracket128Test.java @@ -35,7 +35,7 @@ import jdk.internal.vm.annotation.ForceInline; /* - * @test id=Z + * @test * @bug 8260473 * @requires vm.gc.Z * @modules jdk.incubator.vector diff --git a/test/hotspot/jtreg/runtime/cds/DeterministicDump.java b/test/hotspot/jtreg/runtime/cds/DeterministicDump.java index 6b6431c0e5e92..92643d648b701 100644 --- a/test/hotspot/jtreg/runtime/cds/DeterministicDump.java +++ b/test/hotspot/jtreg/runtime/cds/DeterministicDump.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -27,17 +27,32 @@ * @summary The same JDK build should always generate the same archive file (no randomness). * @requires vm.cds & vm.flagless * @library /test/lib - * @run driver DeterministicDump + * @build jdk.test.whitebox.WhiteBox + * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions + * -XX:+WhiteBoxAPI DeterministicDump */ +import jdk.test.lib.cds.CDSArchiveUtils; import jdk.test.lib.cds.CDSOptions; import jdk.test.lib.cds.CDSTestUtils; import jdk.test.lib.Platform; +import java.io.BufferedReader; +import java.io.File; import java.io.FileInputStream; +import java.io.FileReader; import java.io.IOException; +import java.util.ArrayDeque; import java.util.ArrayList; public class DeterministicDump { + + static long HEADER_SIZE; // Size of header in bytes + static int HEADER_LEN = 106; // Number of lines in CDS map file header + static int LINE_OFFSET = 22; // Offset from address to first word of data + static int NUM_LINES = 5; // Number of lines to be printed + static int WORD_LEN = 16 + 1; // Length of word in map file + public static void main(String[] args) throws Exception { doTest(false); @@ -62,17 +77,19 @@ public static void doTest(boolean compressed) throws Exception { } String baseArchive = dump(baseArgs); + File baseArchiveFile = new File(baseArchive + ".jsa"); + HEADER_SIZE = CDSArchiveUtils.fileHeaderSize(baseArchiveFile); // (1) Dump with the same args. Should produce the same archive. String baseArchive2 = dump(baseArgs); - compare(baseArchive, baseArchive2); + compare(baseArchive, baseArchive2, baseArchiveFile); // (2) This will cause the archive to be relocated during dump time. We should // still get the same bits. This simulates relocation that happens when // Address Space Layout Randomization prevents the archive space to // be mapped at the default location. String relocatedArchive = dump(baseArgs, "-XX:+UnlockDiagnosticVMOptions", "-XX:ArchiveRelocationMode=1"); - compare(baseArchive, relocatedArchive); + compare(baseArchive, relocatedArchive, baseArchiveFile); } static int id = 0; @@ -89,14 +106,14 @@ static String dump(ArrayList args, String... more) throws Exception { .addSuffix(more); CDSTestUtils.createArchiveAndCheck(opts); - return archiveName; + return logName; } - static void compare(String file0, String file1) throws Exception { + static void compare(String file0, String file1, File archiveFile) throws Exception { byte[] buff0 = new byte[4096]; byte[] buff1 = new byte[4096]; - try (FileInputStream in0 = new FileInputStream(file0); - FileInputStream in1 = new FileInputStream(file1)) { + try (FileInputStream in0 = new FileInputStream(file0 + ".jsa"); + FileInputStream in1 = new FileInputStream(file1 + ".jsa")) { int total = 0; while (true) { int n0 = read(in0, buff0); @@ -113,7 +130,12 @@ static void compare(String file0, String file1) throws Exception { byte b0 = buff0[i]; byte b1 = buff1[i]; if (b0 != b1) { - throw new RuntimeException("File content different at byte #" + (total + i) + ", b0 = " + b0 + ", b1 = " + b1); + // The checksums are stored in the header so it should be skipped + // since we want to see the first meaningful diff between the archives + if (total + i > HEADER_SIZE) { + print_diff(file0 + ".map", file1 + ".map", archiveFile, total + i); + throw new RuntimeException("File content different at byte #" + (total + i) + ", b0 = " + b0 + ", b1 = " + b1); + } } } total += n0; @@ -133,4 +155,115 @@ static int read(FileInputStream in, byte[] buff) throws IOException { return total; } + + // CDS map file doesn't print the alignment bytes so they need to be considered + // when mapping the byte number in the archive to the word in the map file + static int archiveByteToMapWord(File archiveFile, int location) throws Exception { + int totalSize = 0; + int word = location; + + long len = HEADER_SIZE; + long aligned = CDSArchiveUtils.fileHeaderSizeAligned(archiveFile); + for (int i = 0; i < CDSArchiveUtils.num_regions(); i++) { + if (i != 0) { + len = CDSArchiveUtils.usedRegionSize(archiveFile, i); + aligned = CDSArchiveUtils.usedRegionSizeAligned(archiveFile, i); + } + totalSize += len; + if (location > totalSize) { + word -= (aligned - len - 16); + } + } + return word/8; + } + + // Read the mapfile and print out the lines associated with the location + static void print_diff(String mapName0, String mapName1, File archiveFile, int location) throws Exception { + FileReader f0 = new FileReader(mapName0); + BufferedReader b0 = new BufferedReader(f0); + + FileReader f1 = new FileReader(mapName1); + BufferedReader b1 = new BufferedReader(f1); + + int word = archiveByteToMapWord(archiveFile, location); + int wordOffset = word % 4; // Each line in the map file prints four words + String region = ""; + + // Skip header text and go to first line + for (int i = 0; i < HEADER_LEN; i++) { + b0.readLine(); + b1.readLine(); + } + + int line_num = HEADER_LEN; + String s0 = ""; + String s1 = ""; + int count = 0; + + // Store lines before and including the diff + ArrayDeque prefix0 = new ArrayDeque(); + ArrayDeque prefix1 = new ArrayDeque(); + + // A line may contain 1-4 words so we iterate by word + do { + s0 = b0.readLine(); + s1 = b1.readLine(); + line_num++; + + if (prefix0.size() >= NUM_LINES / 2 + 1) { + prefix0.removeFirst(); + prefix1.removeFirst(); + } + prefix0.addLast(s0); + prefix1.addLast(s1); + + // Skip lines with headers when counting words e.g. + // [rw region 0x0000000800000000 - 0x00000008005a1f88 5906312 bytes] + // or + // 0x0000000800000b28: @@ TypeArrayU1 16 + if (!s0.contains(": @@") && !s0.contains("bytes]")) { + int words = (s0.length() - LINE_OFFSET - 70) / 8; + count += words; + } else if (s0.contains("bytes]")) { + region = s0; + } + } while (count < word); + + // Print the diff with the region name above it + System.out.println("[First diff: map file #1 (" + mapName0 + ")]"); + System.out.println(region); + String diff0 = print_diff_helper(b0, wordOffset, prefix0); + + System.out.println("\n[First diff: map file #2 (" + mapName1 + ")]"); + System.out.println(region); + String diff1 = print_diff_helper(b1, wordOffset, prefix1); + + System.out.printf("\nByte #%d at line #%d word #%d:\n", location, line_num, wordOffset); + System.out.printf("%s: %s\n%s: %s\n", mapName0, diff0, mapName1, diff1); + + f0.close(); + f1.close(); + } + + static String print_diff_helper(BufferedReader b, int wordOffset, ArrayDeque prefix) throws Exception { + int start = LINE_OFFSET + WORD_LEN * wordOffset; + int end = start + WORD_LEN; + String line = prefix.getLast(); + String diff = line.substring(start, end); + + // Print previous lines + for (String s : prefix) { + if (s.equals(line)) { + System.out.println(">" + s); + } else { + System.out.println(" " + s); + } + } + + // Print extra lines + for (int i = 0; i < NUM_LINES / 2; i++) { + System.out.println(" " + b.readLine()); + } + return diff; + } } diff --git a/test/hotspot/jtreg/runtime/cds/appcds/StaticArchiveWithLambda.java b/test/hotspot/jtreg/runtime/cds/appcds/StaticArchiveWithLambda.java index 9bab98a5d2cc9..76440c81fcf6c 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/StaticArchiveWithLambda.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/StaticArchiveWithLambda.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -53,7 +53,7 @@ public static void main(String[] args) throws Exception { "-Xlog:class+load,cds") .setArchiveName(archiveName); CDSTestUtils.createArchiveAndCheck(opts) - .shouldContain("Skipping java/lang/invoke/BoundMethodHandle$Species_LLLL because it is dynamically generated"); + .shouldHaveExitValue(0); // run with archive CDSOptions runOpts = (new CDSOptions()) diff --git a/test/hotspot/jtreg/runtime/cds/appcds/customLoader/ClassFromSystemModule.java b/test/hotspot/jtreg/runtime/cds/appcds/customLoader/ClassFromSystemModule.java new file mode 100644 index 0000000000000..c50d6f3fab5f8 --- /dev/null +++ b/test/hotspot/jtreg/runtime/cds/appcds/customLoader/ClassFromSystemModule.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024, 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 8343416 + * @summary Test dumping of class from a system module loaded by a custom loader. + * @requires vm.cds + * @requires vm.cds.custom.loaders + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds + * @run driver ClassFromSystemModule + */ + +import java.nio.file.*; + +import jdk.test.lib.process.OutputAnalyzer; + +public class ClassFromSystemModule { + public static void main(String[] args) throws Exception { + Path jrtFs = Paths.get(System.getProperty("java.home"), "lib", "jrt-fs.jar"); + System.out.println("jrtFs: " + jrtFs.toString()); + + String classlist[] = new String[] { + "java/nio/file/spi/FileSystemProvider id: 1000", + "jdk/internal/jrtfs/JrtFileSystemProvider id: 1001 super:1000 source: " + jrtFs.toString(), + }; + + OutputAnalyzer out = TestCommon.testDump(null, classlist, "-Xlog:cds,cds+class=debug"); + out.shouldContain("boot java.nio.file.spi.FileSystemProvider") + .shouldContain("unreg jdk.internal.jrtfs.JrtFileSystemProvider"); + } +} diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/OldClassAndRedefineClass.java b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/OldClassAndRedefineClass.java index 242a78ca024b6..8ca8b7d952e59 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/OldClassAndRedefineClass.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/OldClassAndRedefineClass.java @@ -26,15 +26,15 @@ * @test * @bug 8342303 * @summary Test loading of shared old class when another class has been redefined. - * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes /test/hotspot/jtreg/runtime/cds/appcds/jvmti - * @requires vm.cds.write.archived.java.heap + * @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/test-classes + * @requires vm.cds * @requires vm.jvmti + * @run driver RedefineClassHelper * @build jdk.test.whitebox.WhiteBox * OldClassAndRedefineClassApp * @compile ../../test-classes/OldSuper.jasm * ../../test-classes/ChildOldSuper.java * ../../test-classes/Hello.java - * @run driver RedefineClassHelper * @run driver OldClassAndRedefineClass */ diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineBootClassTest.java b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineBootClassTest.java index bc14ec996f598..eeabce69a366d 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineBootClassTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineBootClassTest.java @@ -29,12 +29,12 @@ * @library /test/lib * /test/hotspot/jtreg/runtime/cds/appcds * /test/hotspot/jtreg/runtime/cds/appcds/test-classes - * /test/hotspot/jtreg/runtime/cds/appcds/jvmti + * @requires vm.cds * @requires vm.jvmti + * @run driver RedefineClassHelper * @build RedefineBootClassTest * RedefineBootClassApp * BootSuper BootChild - * @run driver RedefineClassHelper * @run driver RedefineBootClassTest */ diff --git a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineOldSuperTest.java b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineOldSuperTest.java index a0c8fa7a44849..4518a45651d08 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineOldSuperTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/jvmti/redefineClasses/RedefineOldSuperTest.java @@ -29,13 +29,13 @@ * @library /test/lib * /test/hotspot/jtreg/runtime/cds/appcds * /test/hotspot/jtreg/runtime/cds/appcds/test-classes - * /test/hotspot/jtreg/runtime/cds/appcds/jvmti + * @requires vm.cds * @requires vm.jvmti * @compile ../../test-classes/OldSuper.jasm + * @run driver RedefineClassHelper * @build RedefineOldSuperTest * RedefineOldSuperApp * NewChild - * @run driver RedefineClassHelper * @run driver RedefineOldSuperTest */ diff --git a/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineBasicTest.java b/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineBasicTest.java index fbdec462e095f..acbd0c948bef2 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineBasicTest.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineBasicTest.java @@ -30,7 +30,7 @@ * @requires vm.jvmti * @library /test/lib /test/hotspot/jtreg/serviceability/jvmti/RedefineClasses /test/hotspot/jtreg/runtime/cds/appcds * @run driver RedefineClassHelper - * @build jdk.test.whitebox.WhiteBox jdk.test.lib.compiler.InMemoryJavaCompiler RedefineBasic + * @build jdk.test.whitebox.WhiteBox RedefineBasic * @run driver RedefineBasicTest */ diff --git a/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineRunningMethods_Shared.java b/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineRunningMethods_Shared.java index 62bd62662a053..039aaef11cd13 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineRunningMethods_Shared.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/redefineClass/RedefineRunningMethods_Shared.java @@ -30,7 +30,7 @@ * @requires vm.jvmti * @library /test/lib /test/hotspot/jtreg/serviceability/jvmti/RedefineClasses /test/hotspot/jtreg/runtime/cds/appcds * @run driver RedefineClassHelper - * @build jdk.test.whitebox.WhiteBox jdk.test.lib.compiler.InMemoryJavaCompiler + * @build jdk.test.whitebox.WhiteBox * @compile RedefineRunningMethods_SharedHelper.java * @run driver RedefineRunningMethods_Shared */ diff --git a/test/hotspot/jtreg/runtime/logging/ClassResolutionTest.java b/test/hotspot/jtreg/runtime/logging/ClassResolutionTest.java index 129d34bd2dba0..58891d09e0299 100644 --- a/test/hotspot/jtreg/runtime/logging/ClassResolutionTest.java +++ b/test/hotspot/jtreg/runtime/logging/ClassResolutionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, 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 ClassResolutionTest - * @bug 8144874 + * @bug 8144874 8343633 * @requires vm.flagless * @modules java.base/jdk.internal.misc * @library /test/lib @@ -36,6 +36,10 @@ import java.lang.ref.WeakReference; import java.lang.reflect.Method; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + public class ClassResolutionTest { public static class ClassResolutionTestMain { @@ -57,6 +61,15 @@ public static void main(String... args) throws Exception { } } + public static void checkOutput(String file, String decorators) throws Exception { + List allLines = Files.readAllLines(Path.of(file)); + for (String line : allLines) { + if (!line.contains(decorators)) { + throw new RuntimeException("Logging should contain decorators " + decorators); + } + } + } + public static void main(String... args) throws Exception { // (1) class+resolve should turn on. @@ -74,6 +87,15 @@ public static void main(String... args) throws Exception { o = new OutputAnalyzer(pb.start()); o.shouldHaveExitValue(0); o.shouldNotContain("[class,resolve]"); + + // (3) Test perf+class+link writes to a file, not tty. + pb = ProcessTools.createLimitedTestJavaProcessBuilder("-Xlog:perf+class+link:output.log", + ClassResolutionTestMain.class.getName()); + o = new OutputAnalyzer(pb.start()); + o.shouldHaveExitValue(0); + o.shouldNotContain("[perf,class,link]"); + + checkOutput("output.log", "[perf,class,link]"); }; } diff --git a/test/hotspot/jtreg/runtime/logging/RedefineClasses.java b/test/hotspot/jtreg/runtime/logging/RedefineClasses.java index 714c05174ebb3..34c8900e6162e 100644 --- a/test/hotspot/jtreg/runtime/logging/RedefineClasses.java +++ b/test/hotspot/jtreg/runtime/logging/RedefineClasses.java @@ -30,7 +30,6 @@ * @modules java.compiler * java.instrument * @requires vm.jvmti - * @build jdk.test.lib.compiler.InMemoryJavaCompiler * @run main RedefineClassHelper * @run main/othervm -Xmx256m -XX:MaxMetaspaceSize=64m -javaagent:redefineagent.jar -Xlog:all=trace:file=all.log RedefineClasses */ diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 8e554933bf63a..a87ab372da243 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -823,8 +823,3 @@ java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all java/awt/Checkbox/CheckboxIndicatorSizeTest.java 8340870 windows-all java/awt/Checkbox/CheckboxNullLabelTest.java 8340870 windows-all java/awt/dnd/WinMoveFileToShellTest.java 8341665 windows-all -java/awt/print/PrinterJob/CheckPrivilege.java 8343219 generic-all -javax/print/PrintSE/PrintSE.sh 8343219 generic-all -java/awt/print/PrinterJob/SecurityDialogTest.java 8343219 generic-all -java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java 8343219 generic-all -java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java 8343219 generic-all diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileFrame.java b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileFrame.java deleted file mode 100644 index a117622d57003..0000000000000 --- a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileFrame.java +++ /dev/null @@ -1,40 +0,0 @@ -import java.awt.Button; -import java.awt.FlowLayout; -import java.awt.Frame; -import java.awt.PrintJob; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -class PrintToFileFrame extends Frame implements ActionListener { - Button nativeDlg = new Button("Show print dialog"); - - public PrintToFileFrame() { - this.setLayout(new FlowLayout()); - add(nativeDlg); - nativeDlg.addActionListener(this); - - setSize(300, 300); - } - - @SuppressWarnings("removal") - public void actionPerformed(ActionEvent ae) { - if (System.getSecurityManager() == null) { - throw new RuntimeException("Security manager isn't installed."); - } - - try { - System.getSecurityManager().checkPrintJobAccess(); - System.out.println("checkPrintJobAccess - OK"); - } catch (SecurityException e) { - System.out.println("checkPrintJobAccess - ERROR " + e); - } - - PrintJob printJob = getToolkit().getPrintJob(this, null, null); - - if (printJob != null) { - System.out.println("Print Job: " + printJob); - } else { - System.out.println("Print Job is null."); - } - } -} diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java deleted file mode 100644 index 05d73123d983a..0000000000000 --- a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileGranted.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2005, 2024, 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. - */ - -import java.awt.print.PrinterJob; - -/* - * @test - * @bug 6275359 - * @summary Test to verify system menu of a dialog on win32 - * @requires (os.family == "windows") - * @library /java/awt/regtesthelpers - * @build PassFailJFrame - * @compile PrintToFileFrame.java - * @compile PrintToFileGranted.java - * @run main/manual/policy=granted/othervm PrintToFileGranted - */ - -public class PrintToFileGranted { - public static void main(String[] args) throws Exception { - String INSTRUCTIONS; - if (isPrintSupport()) { - INSTRUCTIONS = """ - 1. Click on 'Show file dialog' button A print dialog will come up - 2. If checkbox 'Print to file' is enabled then the test passed - else the test failed - 3. Close the print dialog before pressing PASS or FAIL buttons - """; - } else { - INSTRUCTIONS = """ - 1. The test requires printer installed in your system, - but there is no printers found - Please install one and re-run the test - """; - } - - PassFailJFrame.builder() - .title("Test Instructions") - .instructions(INSTRUCTIONS) - .rows((int) INSTRUCTIONS.lines().count() + 2) - .columns(35) - .testUI(new PrintToFileFrame()) - .build() - .awaitAndCheck(); - } - - public static boolean isPrintSupport() { - PrinterJob pj = PrinterJob.getPrinterJob(); - return pj.getPrintService() != null; - } -} diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java b/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java deleted file mode 100644 index 7c724e97bed53..0000000000000 --- a/test/jdk/java/awt/Dialog/PrintToFileTest/PrintToFileRevoked.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2005, 2024, 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. - */ - -import java.awt.print.PrinterJob; - -/* - * @test - * @bug 6275359 - * @summary Test to verify Printing ignores Security permissions - * using native dialog - * @requires (os.family == "windows") - * @library /java/awt/regtesthelpers - * @build PassFailJFrame - * @compile PrintToFileRevoked.java - * @run main/manual/policy=revoked/othervm PrintToFileRevoked - */ - -public class PrintToFileRevoked { - public static void main(String[] args) throws Exception { - String INSTRUCTIONS; - if (isPrintSupport()) { - INSTRUCTIONS = """ - 1. Click on 'Show file dialog' button A print dialog will come up - 2. If checkbox 'Print to file' is disabled then the test passed - else the test failed - 3. Close the print dialog before pressing PASS or FAIL buttons - """; - } else { - INSTRUCTIONS = """ - 1. The test requires printer installed in your system, - but there is no printers found - Please install one and re-run the test - """; - } - PassFailJFrame.builder() - .title("Test Instructions") - .instructions(INSTRUCTIONS) - .rows((int) INSTRUCTIONS.lines().count() + 2) - .columns(35) - .testUI(new PrintToFileFrame()) - .build() - .awaitAndCheck(); - } - - public static boolean isPrintSupport() { - PrinterJob pj = PrinterJob.getPrinterJob(); - return pj.getPrintService() != null; - } -} diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/granted b/test/jdk/java/awt/Dialog/PrintToFileTest/granted deleted file mode 100644 index e73b0fdf3cdef..0000000000000 --- a/test/jdk/java/awt/Dialog/PrintToFileTest/granted +++ /dev/null @@ -1,10 +0,0 @@ -/* AUTOMATICALLY GENERATED ON Thu Jan 03 15:48:39 PST 2002*/ -/* DO NOT EDIT */ - -grant { - permission java.lang.RuntimePermission "queuePrintJob"; - permission java.util.PropertyPermission "*", "read"; - permission java.io.FilePermission "<>", "read"; - permission java.io.FilePermission "<>", "write"; - permission java.lang.RuntimePermission "accessClassInPackage.sun.util.locale.provider"; -}; diff --git a/test/jdk/java/awt/Dialog/PrintToFileTest/revoked b/test/jdk/java/awt/Dialog/PrintToFileTest/revoked deleted file mode 100644 index d2545e15e1155..0000000000000 --- a/test/jdk/java/awt/Dialog/PrintToFileTest/revoked +++ /dev/null @@ -1,9 +0,0 @@ -/* AUTOMATICALLY GENERATED ON Thu Jan 03 15:48:39 PST 2002*/ -/* DO NOT EDIT */ - -grant { - permission java.lang.RuntimePermission "queuePrintJob"; - permission java.util.PropertyPermission "*", "read"; - permission java.lang.RuntimePermission "accessClassInPackage.sun.util.locale.provider"; -}; - diff --git a/test/jdk/java/awt/im/memoryleak/InputContextMemoryLeakTest.java b/test/jdk/java/awt/im/memoryleak/InputContextMemoryLeakTest.java index f04b635f9e7bd..2b933d8e2236f 100644 --- a/test/jdk/java/awt/im/memoryleak/InputContextMemoryLeakTest.java +++ b/test/jdk/java/awt/im/memoryleak/InputContextMemoryLeakTest.java @@ -61,10 +61,12 @@ public void run() { button = new JButton("Test"); p1.add(button); frame.add(p1); - text = new WeakReference(new JTextField("Text")); - p = new WeakReference(new JPanel(new FlowLayout())); - p.get().add(text.get()); - frame.add(p.get()); + JTextField tf = new JTextField("Text"); + text = new WeakReference(tf); + JPanel jp = new JPanel(new FlowLayout()); + p = new WeakReference(jp); + jp.add(tf); + frame.add(jp); frame.setBounds(500, 400, 200, 200); frame.setVisible(true); } @@ -79,13 +81,19 @@ public void run() { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { + // after this the JTextField as well as the JPanel + // are eligible to be GC'd frame.remove(p.get()); } }); Util.waitForIdle(null); //After the next caret blink it automatically TextField references - Thread.sleep(text.get().getCaret().getBlinkRate() * 2); + JTextField tf = text.get(); + if (tf != null) { + Thread.sleep(tf.getCaret().getBlinkRate() * 2); + tf = null; // allow to be GCed + } Util.waitForIdle(null); try { diff --git a/test/jdk/java/awt/print/PrinterJob/CheckPrivilege.java b/test/jdk/java/awt/print/PrinterJob/CheckPrivilege.java deleted file mode 100644 index 533516664eddd..0000000000000 --- a/test/jdk/java/awt/print/PrinterJob/CheckPrivilege.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2007, 2017, 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 - * @key printer - * @bug 4151151 - * @summary Confirm that low-level print code does doPrivilege. - * @author Graham Hamilton - * @run main/othervm -Djava.security.manager=allow CheckPrivilege - */ - -import java.awt.print.*; - -public class CheckPrivilege implements Printable { - - static boolean verbose; - - private static void println(String mess) { - if (verbose) { - System.err.println(mess); - } - } - - /** - * SecurityManager that allows print requests, but - * causes things like "exec" to get checked. - */ - static class PrintLover extends SecurityManager { - public void checkPrintJobAccess() { - } - public void checkPackageAccess(String pkg) { - } - public void checkPropertyAccess(String key) { - } - } - - /** - * Internal exception to boucne us out of the print code - */ - class Printing extends RuntimeException { - } - - public static void main(String argv[]) { - - System.out.println( "-----------------------------------------------------------------------"); - System.out.println( "INSTRUCTIONS: You should have a printer configured in your system to do this test. Test fails if you get this error message:"); - System.out.println(" \"Regression: printing causes a NullPointerException\""); - System.out.println( "-----------------------------------------------------------------------"); - - if (argv.length > 0 && argv[0].equals("-v")) { - verbose = true; - } - - // We need to make sure AWT is initialized. This is bug #4162674 - java.awt.Toolkit.getDefaultToolkit(); - - // Try to install our own security manager. - try { - SecurityManager sm = new PrintLover(); - println("Installing PrintLover security manager"); - System.setSecurityManager(sm); - println("Installed security manager OK"); - - } catch (Throwable th) { - System.err.println("Failed to install SecurityManager"); - th.printStackTrace(); - throw new RuntimeException("Failed to install SecurityManager"); - } - - try { - println("calling getPrinterJob"); - PrinterJob pj = PrinterJob.getPrinterJob(); - if ((pj == null) || (pj.getPrintService() == null)){ - return; - } - - println("PrinterJob class is " + pj.getClass()); - println("calling pj.setPrintable"); - pj.setPrintable(new CheckPrivilege()); - println("calling pj.print"); - pj.print(); - println("done pj.print"); - - } catch (Printing ex) { - // We get here if the print request started OK. - println("Caught \"Printing\" exception OK"); - - } catch (PrinterException ex) { - System.err.println("Caught " + ex); - throw new RuntimeException("" + ex); - - } catch (NullPointerException ex) { - // This is the bug: - System.err.println("Caught " + ex); - System.err.println("Regression: printing causes a NullPointerException"); - throw ex; - } - - //System.exit(0); - - } - - // Back-call from the new print APIs. - // We always say we have bothing to print. - public int print(java.awt.Graphics g, PageFormat pf, int index) { - println("Started printing " + index); - return Printable.NO_SUCH_PAGE; - } - - -} diff --git a/test/jdk/java/awt/print/PrinterJob/SecurityDialogTest.java b/test/jdk/java/awt/print/PrinterJob/SecurityDialogTest.java deleted file mode 100644 index dc103dc6f56b9..0000000000000 --- a/test/jdk/java/awt/print/PrinterJob/SecurityDialogTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2007, 2024, 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. - */ - -import java.awt.Frame; -import java.awt.print.PageFormat; -import java.awt.print.PrinterJob; -import java.lang.reflect.InvocationTargetException; - -import javax.print.PrintService; -import javax.print.attribute.HashPrintRequestAttributeSet; -import javax.print.attribute.PrintRequestAttributeSet; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.SwingUtilities; - -/* - * @test - * @bug 4937672 5100706 6252456 - * @key printer - * @summary Verifies "Print to file" option is disable if reading/writing files - * is not allowed by Security Manager. - * @library /java/awt/regtesthelpers - * @build PassFailJFrame - * @run main/manual/othervm -Djava.security.manager=allow SecurityDialogTest - */ -public class SecurityDialogTest { - private static final String INSTRUCTIONS = - "This test brings up a native and cross-platform page and print dialogs.\n" + - "\n" + - "If the dialog has an option to save to file, the option ought " + - "to be disabled.\n" + - "\n" + - "Press the Pass button if the \"Print to file\" option was disabled in\n" + - "all the dialogs where it was present.\n" + - "Otherwise, press the Fail button.\n" + - "\n" + - "The dialogs should be displayed even when " + - "there is no queuePrintJob permission."; - - private static JLabel dialogType; - - public static void main(String[] args) throws Exception { - if (PrinterJob.lookupPrintServices().length == 0) { - throw new RuntimeException("Printer not configured or available."); - } - - PassFailJFrame passFailJFrame = PassFailJFrame.builder() - .instructions(INSTRUCTIONS) - .splitUIBottom(SecurityDialogTest::createTestUI) - .rows((int) INSTRUCTIONS.lines().count() + 1) - .columns(45) - .build(); - - displayDialogs(); - - passFailJFrame.awaitAndCheck(); - } - - private static JComponent createTestUI() { - dialogType = new JLabel(" "); - - Box main = Box.createVerticalBox(); - main.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); - main.add(new JLabel("Current Dialog:")); - main.add(Box.createVerticalStrut(4)); - main.add(dialogType); - return main; - } - - private static void displayDialogs() - throws InterruptedException, InvocationTargetException { - final PrinterJob pj = PrinterJob.getPrinterJob(); - - // Install a security manager which does not allow reading and - // writing of files. - SecurityManager ptsm = new SecurityManager(); - System.setSecurityManager(ptsm); - - PrintService[] services = PrinterJob.lookupPrintServices(); - for (int i = 0; i < services.length; i++) { - System.out.println("SecurityDialogTest service " + i + " : " + services[i]); - } - - System.out.println("SecurityDialogTest default service : " + pj.getPrintService()); - - setDialogType("Native Page Dialog"); - pj.pageDialog(new PageFormat()); - - setDialogType("Swing Page Dialog"); - PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); - pj.pageDialog(attributes); - - // With the security manager installed, save to file should now - // be denied. - setDialogType("Native Print Dialog"); - pj.printDialog(); - - setDialogType("Swing Print Dialog"); - pj.printDialog(attributes); - - setDialogType("Test completed"); - } - - private static void setDialogType(String type) - throws InterruptedException, InvocationTargetException { - SwingUtilities.invokeAndWait(() -> dialogType.setText(type)); - } -} diff --git a/test/jdk/java/foreign/largestub/TestLargeStub.java b/test/jdk/java/foreign/largestub/TestLargeStub.java index e4dcb325c8f5a..13b635c73430a 100644 --- a/test/jdk/java/foreign/largestub/TestLargeStub.java +++ b/test/jdk/java/foreign/largestub/TestLargeStub.java @@ -33,10 +33,14 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import java.lang.foreign.Arena; import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.Linker; import java.lang.foreign.MemoryLayout; +import java.lang.foreign.MemorySegment; import java.lang.foreign.ValueLayout; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.util.stream.Stream; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -76,9 +80,17 @@ public void testDowncallAllowHeap() { @MethodSource("layouts") public void testUpcall(ValueLayout layout, int numSlots) { // Link a handle with a large number of arguments, to try and overflow the code buffer - Linker.nativeLinker().downcallHandle( - FunctionDescriptor.of(STRUCT_LL, - Stream.generate(() -> layout).limit(UPCALL_AVAILABLE_SLOTS / numSlots).toArray(MemoryLayout[]::new))); + try (Arena arena = Arena.ofConfined()) { + Linker.nativeLinker().upcallStub( + MethodHandles.empty(MethodType.methodType(MemorySegment.class, + Stream.generate(() -> layout).limit(UPCALL_AVAILABLE_SLOTS / numSlots) + .map(ValueLayout::carrier) + .toArray(Class[]::new))), + FunctionDescriptor.of(STRUCT_LL, + Stream.generate(() -> layout).limit(UPCALL_AVAILABLE_SLOTS / numSlots) + .toArray(MemoryLayout[]::new)), + arena); + } } private static Stream layouts() { diff --git a/test/jdk/java/io/IO/IO.java b/test/jdk/java/io/IO/IO.java index 328c189fb2f7b..e4da174203039 100644 --- a/test/jdk/java/io/IO/IO.java +++ b/test/jdk/java/io/IO/IO.java @@ -21,6 +21,7 @@ * questions. */ +import java.io.Writer; import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; @@ -33,6 +34,7 @@ import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.extension.AfterTestExecutionCallback; @@ -48,7 +50,7 @@ /* * @test - * @bug 8305457 + * @bug 8305457 8342936 * @summary java.io.IO tests * @library /test/lib * @run junit IO @@ -131,22 +133,26 @@ public void inputTestInteractive(String console, String prompt) throws Exception var testSrc = System.getProperty("test.src", "."); var command = new ArrayList(); command.add(expect.toString()); - command.add(Path.of(testSrc, "input.exp").toAbsolutePath().toString()); + String expectInputName = PROMPT_NONE.equals(prompt) ? "input-no-prompt" + : "input"; + command.add(Path.of(testSrc, expectInputName + ".exp").toAbsolutePath().toString()); command.add(System.getProperty("test.jdk") + "/bin/java"); command.add("--enable-preview"); if (console != null) command.add("-Djdk.console=" + console); command.add(Path.of(testSrc, "Input.java").toAbsolutePath().toString()); - command.add(prompt == null ? "0" : "1"); + command.add(prompt == null ? "0" : PROMPT_NONE.equals(prompt) ? "2" : "1"); command.add(String.valueOf(prompt)); OutputAnalyzer output = ProcessTools.executeProcess(command.toArray(new String[]{})); output.reportDiagnosticSummary(); assertEquals(0, output.getExitValue()); } + private static final String PROMPT_NONE = "prompt-none"; + public static Stream args() { // cross product: consoles x prompts - return Stream.of(null, "gibberish").flatMap(console -> Stream.of(null, "?", "%s") + return Stream.of(null, "gibberish").flatMap(console -> Stream.of(null, "?", "%s", PROMPT_NONE) .map(prompt -> new String[]{console, prompt}).map(Arguments::of)); } } @@ -172,6 +178,33 @@ public void printTest(String mode) throws Exception { out.substring(out.length() / 2)); } + @Test //JDK-8342936 + public void printlnNoParamsTest() throws Exception { + var file = Path.of("PrintlnNoParams.java"); + try (Writer w = Files.newBufferedWriter(file)) { + w.write(""" + void main() { + print("1 "); + print("2 "); + print("3 "); + println(); + System.console().print("1 "); + System.console().print("2 "); + System.console().print("3 "); + System.console().println(); + } + """); + } + var pb = ProcessTools.createTestJavaProcessBuilder("--enable-preview", file.toString()); + OutputAnalyzer output = ProcessTools.executeProcess(pb); + assertEquals(0, output.getExitValue()); + assertTrue(output.getStderr().isEmpty()); + output.reportDiagnosticSummary(); + String out = output.getStdout(); + String nl = System.getProperty("line.separator"); + assertEquals("1 2 3 " + nl + "1 2 3 " + nl, out); + } + @ParameterizedTest @ValueSource(strings = {"println", "print", "input"}) diff --git a/test/jdk/java/io/IO/Input.java b/test/jdk/java/io/IO/Input.java index 1bc03c8bb8a54..1a62fb771666a 100644 --- a/test/jdk/java/io/IO/Input.java +++ b/test/jdk/java/io/IO/Input.java @@ -28,9 +28,11 @@ public class Input { public static void main(String[] args) throws IOException { - if (args[0].equals("0")) - System.out.print(readln(null)); - else - System.out.print(readln(args[1])); + switch (args[0]) { + case "0" -> System.out.print(readln(null)); + case "1" -> System.out.print(readln(args[1])); + case "2" -> System.out.print(readln()); + default -> throw new AssertionError("Unknown command: " + args[0]); + } } } diff --git a/test/jdk/java/io/IO/input-no-prompt.exp b/test/jdk/java/io/IO/input-no-prompt.exp new file mode 100644 index 0000000000000..20cd481912b83 --- /dev/null +++ b/test/jdk/java/io/IO/input-no-prompt.exp @@ -0,0 +1,30 @@ +# +# Copyright (c) 2024, 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. +# + +set prompt [lindex $argv $argc-1] +set stty_init "rows 24 cols 80" +set timeout -1 + +spawn {*}$argv +send "hello\r" +expect eof diff --git a/test/jdk/java/lang/ProcessBuilder/Basic.java b/test/jdk/java/lang/ProcessBuilder/Basic.java index e1e2cef9a8a67..68b3ab56b6da6 100644 --- a/test/jdk/java/lang/ProcessBuilder/Basic.java +++ b/test/jdk/java/lang/ProcessBuilder/Basic.java @@ -32,7 +32,6 @@ * @summary Basic tests for Process and Environment Variable code * @modules java.base/java.lang:open * java.base/java.io:open - * java.base/jdk.internal.misc * @requires !vm.musl * @requires vm.flagless * @library /test/lib @@ -2676,17 +2675,6 @@ static void THROWS(Class k, Fun... fs) { else unexpected(t);}} static boolean isLocked(BufferedInputStream bis) throws Exception { - Field lockField = BufferedInputStream.class.getDeclaredField("lock"); - lockField.setAccessible(true); - var lock = (jdk.internal.misc.InternalLock) lockField.get(bis); - if (lock != null) { - if (lock.tryLock()) { - lock.unlock(); - return false; - } else { - return true; - } - } return new Thread() { volatile boolean unlocked; diff --git a/test/jdk/java/lang/invoke/lambda/LambdaHiddenCaller.java b/test/jdk/java/lang/invoke/lambda/LambdaHiddenCaller.java new file mode 100644 index 0000000000000..aed19e6ca1753 --- /dev/null +++ b/test/jdk/java/lang/invoke/lambda/LambdaHiddenCaller.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2024, 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. + */ + +import java.io.Serializable; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.function.IntSupplier; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/* + * @test + * @bug 8343064 + * @summary Test about when lambda caller/target class is a hidden class + * @run junit LambdaHiddenCaller + */ +public class LambdaHiddenCaller { + static Hooks hiddenCaller; + + @BeforeAll + static void setup() throws Throwable { + byte[] bytes; + try (var in = LambdaHiddenCaller.class.getResourceAsStream("HiddenHooks.class")) { + bytes = in.readAllBytes(); + } + var hiddenClassLookup = MethodHandles.lookup().defineHiddenClass(bytes, true); + hiddenCaller = (Hooks) hiddenClassLookup.findConstructor(hiddenClassLookup.lookupClass(), MethodType.methodType(void.class)) + .asType(MethodType.methodType(Hooks.class)).invokeExact(); + } + + @Test + void testStaticMethod() { + var is = hiddenCaller.callStaticMethodLambda(); + assertEquals(42, is.getAsInt()); + } + + @Test + void testSerializableLambda() { + var is = hiddenCaller.callSerializableLambda(); + assertEquals(42, is.getAsInt()); + assertTrue(Serializable.class.isAssignableFrom(is.getClass())); + // We do not guarantee serialization functionalities yet + } +} + +/** + * Hooks to call hidden class methods easily. + */ +interface Hooks { + IntSupplier callStaticMethodLambda(); + + IntSupplier callSerializableLambda(); +} + +class HiddenHooks implements Hooks { + private static int compute() { + return 42; + } + + @Override + public IntSupplier callStaticMethodLambda() { + return HiddenHooks::compute; + } + + @Override + public IntSupplier callSerializableLambda() { + return (IntSupplier & Serializable) HiddenHooks::compute; + } +} \ No newline at end of file diff --git a/test/jdk/java/lang/module/ClassFileVersionsTest.java b/test/jdk/java/lang/module/ClassFileVersionsTest.java index 849a56301a103..1ffc587865108 100644 --- a/test/jdk/java/lang/module/ClassFileVersionsTest.java +++ b/test/jdk/java/lang/module/ClassFileVersionsTest.java @@ -31,10 +31,13 @@ * @summary Test parsing of module-info.class with different class file versions */ +import java.lang.classfile.ClassFile; import java.lang.module.InvalidModuleDescriptorException; import java.lang.module.ModuleDescriptor; import java.lang.module.ModuleDescriptor.Requires.Modifier; import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; import java.util.Set; import static java.lang.module.ModuleDescriptor.Requires.Modifier.*; @@ -46,6 +49,8 @@ import static org.testng.Assert.*; public class ClassFileVersionsTest { + private static final int PREVIEW_MINOR_VERSION = + ClassFile.PREVIEW_MINOR_VERSION; private static final int FEATURE; static { FEATURE = Runtime.version().feature(); @@ -56,26 +61,34 @@ public class ClassFileVersionsTest { @DataProvider(name = "supported") public Object[][] supported() { /* - * There are four test cases for JDK 9 and then one test case + * There are four test cases for JDK 9, one test case * for each subsequent JDK version from JDK 10 to the current - * feature release for a total of (4 + (FEATURE - 9) ) => - * (feature - 5) rows. + * feature release, and two tests for the current release with + * a preview flag set, for a total of (4 + (FEATURE - 9) + 2) + * rows. */ - Object[][] result = new Object[(FEATURE - 5)][]; + List result = new ArrayList<>(4 + (FEATURE - 9) + 2); // Class file version of JDK 9 is 53.0 - result[0] = new Object[]{ 53, 0, Set.of()}; - result[1] = new Object[]{ 53, 0, Set.of(STATIC) }; - result[2] = new Object[]{ 53, 0, Set.of(TRANSITIVE) }; - result[3] = new Object[]{ 53, 0, Set.of(STATIC, TRANSITIVE) }; + result.add(new Object[]{ 53, 0, Set.of()}); + result.add(new Object[]{ 53, 0, Set.of(STATIC) }); + result.add(new Object[]{ 53, 0, Set.of(TRANSITIVE) }); + result.add(new Object[]{ 53, 0, Set.of(STATIC, TRANSITIVE) }); // Major class file version of JDK N is 44 + n. Create rows // for JDK 10 through FEATURE. - for (int i = 4; i < (FEATURE - 5) ; i++) { - result[i] = new Object[]{i + 50, 0, Set.of()}; + for (int i = 10; i <= FEATURE; i++) { + result.add(new Object[]{ 44 + i, 0, Set.of()}); } - return result; + result.add(new Object[]{ 44 + FEATURE, + PREVIEW_MINOR_VERSION, + Set.of()}); + result.add(new Object[]{ 44 + FEATURE, + PREVIEW_MINOR_VERSION, + Set.of(TRANSITIVE) }); + + return result.toArray(s -> new Object[s][]); } // major, minor, modifiers for requires java.base @@ -84,27 +97,34 @@ public Object[][] unsupported() { /* * There are three test cases for releases prior to JDK 9, * three test cases for each JDK version from JDK 10 to the - * current feature release, plus one addition test case for - * the next release for a total of (3 + (FEATURE - 9) * 3 + 1) + * current feature release, two tests for the current release with + * the preview flag set, plus one addition test case for + * the next release for a total of (3 + (FEATURE - 9) * 3 + 2 + 1) * rows. */ - int unsupportedCount = 3 + (FEATURE - 9)*3 + 1; - Object[][] result = new Object[unsupportedCount][]; + List result = new ArrayList<>(3 + (FEATURE - 9) * 3 + 2 + 1); - result[0] = new Object[]{50, 0, Set.of()}; // JDK 6 - result[1] = new Object[]{51, 0, Set.of()}; // JDK 7 - result[2] = new Object[]{52, 0, Set.of()}; // JDK 8 + result.add(new Object[]{50, 0, Set.of()}); // JDK 6 + result.add(new Object[]{51, 0, Set.of()}); // JDK 7 + result.add(new Object[]{52, 0, Set.of()}); // JDK 8 for (int i = 10; i <= FEATURE ; i++) { - int base = 3 + (i-10)*3; // Major class file version of JDK N is 44+n - result[base] = new Object[]{i + 44, 0, Set.of(STATIC)}; - result[base + 1] = new Object[]{i + 44, 0, Set.of(TRANSITIVE)}; - result[base + 2] = new Object[]{i + 44, 0, Set.of(STATIC, TRANSITIVE)}; + result.add(new Object[]{i + 44, 0, Set.of(STATIC)}); + result.add(new Object[]{i + 44, 0, Set.of(TRANSITIVE)}); + result.add(new Object[]{i + 44, 0, Set.of(STATIC, TRANSITIVE)}); } - result[unsupportedCount - 1] = new Object[]{FEATURE+1+44, 0, Set.of()}; - return result; + result.add(new Object[]{FEATURE + 44, + PREVIEW_MINOR_VERSION, + Set.of(STATIC)}); + result.add(new Object[]{FEATURE + 44, + PREVIEW_MINOR_VERSION, + Set.of(STATIC, TRANSITIVE)}); + + result.add(new Object[]{FEATURE+1+44, 0, Set.of()}); + + return result.toArray(s -> new Object[s][]); } @Test(dataProvider = "supported") diff --git a/test/jdk/java/lang/module/ModuleDescriptorTest.java b/test/jdk/java/lang/module/ModuleDescriptorTest.java index c9267f3db3d64..c46bb4a1e9e94 100644 --- a/test/jdk/java/lang/module/ModuleDescriptorTest.java +++ b/test/jdk/java/lang/module/ModuleDescriptorTest.java @@ -61,6 +61,8 @@ import jdk.internal.access.JavaLangModuleAccess; import jdk.internal.access.SharedSecrets; import java.lang.classfile.ClassFile; +import java.lang.classfile.ClassFileVersion; +import java.lang.classfile.ClassTransform; import java.lang.classfile.attribute.ModuleAttribute; import java.lang.constant.PackageDesc; import java.lang.constant.ModuleDesc; @@ -1522,4 +1524,68 @@ public void testToString() { assertTrue(s.contains("p1")); } + @Test(expectedExceptions = InvalidModuleDescriptorException.class) + public void testRequiresTransitiveJavaBaseNotPermitted1() throws Exception { + ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo") + .requires(Set.of(Modifier.TRANSITIVE), "java.base") + .build(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ModuleInfoWriter.write(descriptor, baos); + ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); + + ModuleDescriptor.read(bb, () -> Set.of("p", "q")); + } + + @Test(expectedExceptions = InvalidModuleDescriptorException.class) + public void testRequiresTransitiveJavaBaseNotPermitted2() throws Exception { + ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo") + .requires(Set.of(Modifier.TRANSITIVE), "java.base") + .build(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ModuleInfoWriter.write(descriptor, baos); + byte[] bytecode = baos.toByteArray(); + ByteBuffer bb = ByteBuffer.wrap(bytecode); + setClassFileVersion(bb, ClassFile.JAVA_21_VERSION, -1); + + ModuleDescriptor.read(bb, () -> Set.of("p", "q")); + } + + public void testRequiresTransitiveJavaBasePermitted() throws Exception { + ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo") + .requires(Set.of(Modifier.TRANSITIVE), "java.base") + .build(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ModuleInfoWriter.write(descriptor, baos); + byte[] bytecode = baos.toByteArray(); + ByteBuffer bb = ByteBuffer.wrap(bytecode); + setClassFileVersion(bb, -1, ClassFile.PREVIEW_MINOR_VERSION); + + descriptor = ModuleDescriptor.read(bb, () -> Set.of("p", "q")); + + assertEquals(descriptor.requires().size(), 1); + Requires javaBase = descriptor.requires().iterator().next(); + assertEquals(javaBase.name(), "java.base"); + assertEquals(javaBase.modifiers(), Set.of(Modifier.TRANSITIVE)); + } + + /**Change the classfile versions of the provided classfile to the provided + * values. + * + * @param bytecode the classfile content to modify + * @param major the major classfile version to set, + * -1 if the existing version should be kept + * @param minor the minor classfile version to set, + * -1 if the existing version should be kept + */ + private void setClassFileVersion(ByteBuffer bb, int major, int minor) { + if (minor != (-1)) { + bb.putShort(4, (short) minor); + } + if (major != (-1)) { + bb.putShort(6, (short) major); + } + } } diff --git a/test/jdk/java/net/Socket/asyncClose/Socket_getInputStream_read.java b/test/jdk/java/net/Socket/asyncClose/Socket_getInputStream_read.java index f2082fcf3748a..812541c9daaec 100644 --- a/test/jdk/java/net/Socket/asyncClose/Socket_getInputStream_read.java +++ b/test/jdk/java/net/Socket/asyncClose/Socket_getInputStream_read.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -60,7 +60,7 @@ public void run() { } latch.countDown(); int n = in.read(); - failed("Socket.getInputStream().read() returned unexpectedly!!"); + failed("Socket.getInputStream().read() returned unexpectedly, n=" + n); } catch (SocketException se) { if (latch.getCount() != 1) { closed(); @@ -77,20 +77,22 @@ public void run() { public AsyncCloseTest go() { try { InetAddress lh = InetAddress.getLocalHost(); - ServerSocket ss = new ServerSocket(0, 0, lh); - s.connect( new InetSocketAddress(lh, ss.getLocalPort()) ); - Socket s2 = ss.accept(); - Thread thr = new Thread(this); - thr.start(); - latch.await(); - Thread.sleep(5000); //sleep, so Socket.getInputStream().read() can block - s.close(); - thr.join(); + try (ServerSocket ss = new ServerSocket(0, 0, lh)) { + s.connect(new InetSocketAddress(lh, ss.getLocalPort())); + try (Socket s2 = ss.accept()) { + Thread thr = new Thread(this); + thr.start(); + latch.await(); + Thread.sleep(5000); //sleep, so Socket.getInputStream().read() can block + s.close(); + thr.join(); + } - if (isClosed()) { - return passed(); - } else { - return failed("Socket.getInputStream().read() wasn't preempted"); + if (isClosed()) { + return passed(); + } else { + return failed("Socket.getInputStream().read() wasn't preempted"); + } } } catch (Exception x) { failed(x.getMessage()); diff --git a/test/jdk/java/net/Socket/asyncClose/Socket_getOutputStream_write.java b/test/jdk/java/net/Socket/asyncClose/Socket_getOutputStream_write.java index dc5eda0607855..6a967ebcf8df8 100644 --- a/test/jdk/java/net/Socket/asyncClose/Socket_getOutputStream_write.java +++ b/test/jdk/java/net/Socket/asyncClose/Socket_getOutputStream_write.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -66,20 +66,22 @@ public void run() { public AsyncCloseTest go() { try { InetAddress lh = InetAddress.getLocalHost(); - ServerSocket ss = new ServerSocket(0, 0, lh); - s.connect( new InetSocketAddress(lh, ss.getLocalPort()) ); - Socket s2 = ss.accept(); - Thread thr = new Thread(this); - thr.start(); - latch.await(); - Thread.sleep(1000); - s.close(); - thr.join(); + try (ServerSocket ss = new ServerSocket(0, 0, lh)) { + s.connect(new InetSocketAddress(lh, ss.getLocalPort())); + try (Socket s2 = ss.accept()) { + Thread thr = new Thread(this); + thr.start(); + latch.await(); + Thread.sleep(1000); + s.close(); + thr.join(); + } - if (isClosed()) { - return passed(); - } else { - return failed("Socket.getOutputStream().write() wasn't preempted"); + if (isClosed()) { + return passed(); + } else { + return failed("Socket.getOutputStream().write() wasn't preempted"); + } } } catch (Exception x) { failed(x.getMessage()); diff --git a/test/jdk/java/net/httpclient/DebugLoggerTest.java b/test/jdk/java/net/httpclient/DebugLoggerTest.java index ec36d62e38e2b..8d81e5cbe695a 100644 --- a/test/jdk/java/net/httpclient/DebugLoggerTest.java +++ b/test/jdk/java/net/httpclient/DebugLoggerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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 @@ -213,7 +213,7 @@ public void publish(LogRecord record) { public void flush() { } @Override - public void close() throws SecurityException { + public void close() { } } diff --git a/test/jdk/java/net/httpclient/FilePublisher/FilePublisherPermsTest.java b/test/jdk/java/net/httpclient/FilePublisher/FilePublisherPermsTest.java index 29976edec9a9e..bafe1496a8680 100644 --- a/test/jdk/java/net/httpclient/FilePublisher/FilePublisherPermsTest.java +++ b/test/jdk/java/net/httpclient/FilePublisher/FilePublisherPermsTest.java @@ -40,7 +40,6 @@ import javax.net.ssl.SSLContext; import java.io.FileNotFoundException; -import java.io.FilePermission; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -211,9 +210,6 @@ public void handle(HttpServerAdapters.HttpTestExchange t) throws IOException { @BeforeTest public void setup() throws Exception { - policyFile = System.getProperty("java.security.policy"); - out.println(policyFile); - sslContext = new SimpleSSLContext().get(); if (sslContext == null) throw new AssertionError("Unexpected null sslContext"); diff --git a/test/jdk/java/net/httpclient/FilePublisher/SecureZipFSProvider.java b/test/jdk/java/net/httpclient/FilePublisher/SecureZipFSProvider.java index 333996496cda1..00f532ba47c8c 100644 --- a/test/jdk/java/net/httpclient/FilePublisher/SecureZipFSProvider.java +++ b/test/jdk/java/net/httpclient/FilePublisher/SecureZipFSProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -92,13 +92,6 @@ public Path getPath(URI uri) { public InputStream newInputStream(Path path, OpenOption... options) throws IOException { Path p = toTestPath(path).unwrap(); - - // Added permission checks before opening the file - SecurityManager sm = System.getSecurityManager(); - if (sm != null) { - sm.checkPermission(new RuntimePermission("customPermission")); - sm.checkRead(p.toString()); - } return defaultProvider.newInputStream(p, options); } diff --git a/test/jdk/java/net/httpclient/ProxyServer.java b/test/jdk/java/net/httpclient/ProxyServer.java index 7de14a79225a5..747a20772d11b 100644 --- a/test/jdk/java/net/httpclient/ProxyServer.java +++ b/test/jdk/java/net/httpclient/ProxyServer.java @@ -27,10 +27,8 @@ import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.util.*; -import java.security.*; import java.util.concurrent.CopyOnWriteArrayList; -import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.util.Arrays.asList; @@ -49,9 +47,9 @@ public class ProxyServer extends Thread implements Closeable { // build it. Let's keep it simple. static final boolean IS_WINDOWS; static { - PrivilegedAction action = - () -> System.getProperty("os.name", "unknown"); - String osName = AccessController.doPrivileged(action); + // Parses os.name directly in order to avoid depending on test + // libraries in an auxiliary test class + String osName = System.getProperty("os.name", "unknown"); IS_WINDOWS = osName.toLowerCase(Locale.ROOT).startsWith("win"); } @@ -151,20 +149,6 @@ public void close() throws IOException { volatile boolean done; public void run() { - if (System.getSecurityManager() == null) { - execute(); - } else { - // so calling domain does not need to have socket permission - AccessController.doPrivileged(new PrivilegedAction() { - public Void run() { - execute(); - return null; - } - }); - } - } - - public void execute() { int id = 0; try { while (!done) { diff --git a/test/jdk/java/net/httpclient/http2/ConnectionFlowControlTest.java b/test/jdk/java/net/httpclient/http2/ConnectionFlowControlTest.java index 6b0b3727ee25c..30cc9122d9dcb 100644 --- a/test/jdk/java/net/httpclient/http2/ConnectionFlowControlTest.java +++ b/test/jdk/java/net/httpclient/http2/ConnectionFlowControlTest.java @@ -171,7 +171,11 @@ void test(String uri) throws Exception { var response = responses.get(keys[i]); String ckey = response.headers().firstValue("X-Connection-Key").get(); if (label == null) label = ckey; - assertEquals(ckey, label, "Unexpected key for " + query); + if (i < max - 1) { + // the connection window might be exceeded at i == max - 2, which + // means that the last request could go on a new connection. + assertEquals(ckey, label, "Unexpected key for " + query); + } int wait = uri.startsWith("https://") ? 500 : 250; try (InputStream is = response.body()) { Thread.sleep(Utils.adjustTimeout(wait)); diff --git a/test/jdk/java/net/httpclient/http2/StreamFlowControlTest.java b/test/jdk/java/net/httpclient/http2/StreamFlowControlTest.java index 36b727e3a22d3..39768b68dc564 100644 --- a/test/jdk/java/net/httpclient/http2/StreamFlowControlTest.java +++ b/test/jdk/java/net/httpclient/http2/StreamFlowControlTest.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8342075 + * @bug 8342075 8343855 * @library /test/lib /test/jdk/java/net/httpclient/lib * @build jdk.httpclient.test.lib.http2.Http2TestServer jdk.test.lib.net.SimpleSSLContext * @run testng/othervm -Djdk.internal.httpclient.debug=true @@ -40,7 +40,6 @@ import java.net.http.HttpClient; import java.net.http.HttpHeaders; import java.net.http.HttpRequest; -import java.net.http.HttpRequest.BodyPublishers; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.nio.charset.StandardCharsets; @@ -53,6 +52,7 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; +import jdk.httpclient.test.lib.common.HttpServerAdapters.HttpHeadOrGetHandler; import jdk.httpclient.test.lib.common.HttpServerAdapters.HttpTestServer; import jdk.httpclient.test.lib.http2.BodyOutputStream; import jdk.httpclient.test.lib.http2.Http2Handler; @@ -69,6 +69,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import static java.util.concurrent.TimeUnit.NANOSECONDS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.fail; @@ -92,6 +93,19 @@ public Object[][] variants() { }; } + static void sleep(long wait) throws InterruptedException { + if (wait <= 0) return; + long remaining = Utils.adjustTimeout(wait); + long start = System.nanoTime(); + while (remaining > 0) { + Thread.sleep(remaining); + long end = System.nanoTime(); + remaining = remaining - NANOSECONDS.toMillis(end - start); + } + System.out.printf("Waited %s ms%n", + NANOSECONDS.toMillis(System.nanoTime() - start)); + } + @Test(dataProvider = "variants") void test(String uri, @@ -115,7 +129,7 @@ void test(String uri, CompletableFuture sent = new CompletableFuture<>(); responseSent.put(query, sent); HttpRequest request = HttpRequest.newBuilder(uriWithQuery) - .POST(BodyPublishers.ofString("Hello there!")) + .GET() .build(); System.out.println("\nSending request:" + uriWithQuery); final HttpClient cc = client; @@ -130,9 +144,9 @@ void test(String uri, // we have to pull to get the exception, but slow enough // so that DataFrames are buffered up to the point that // the window is exceeded... - int wait = uri.startsWith("https://") ? 500 : 350; + long wait = uri.startsWith("https://") ? 800 : 350; try (InputStream is = response.body()) { - Thread.sleep(Utils.adjustTimeout(wait)); + sleep(wait); is.readAllBytes(); } // we could fail here if we haven't waited long enough @@ -174,7 +188,7 @@ void testAsync(String uri, CompletableFuture sent = new CompletableFuture<>(); responseSent.put(query, sent); HttpRequest request = HttpRequest.newBuilder(uriWithQuery) - .POST(BodyPublishers.ofString("Hello there!")) + .GET() .build(); System.out.println("\nSending request:" + uriWithQuery); final HttpClient cc = client; @@ -188,9 +202,9 @@ void testAsync(String uri, assertEquals(key, label, "Unexpected key for " + query); } sent.join(); - int wait = uri.startsWith("https://") ? 600 : 300; + long wait = uri.startsWith("https://") ? 800 : 350; try (InputStream is = response.body()) { - Thread.sleep(Utils.adjustTimeout(wait)); + sleep(wait); is.readAllBytes(); } // we could fail here if we haven't waited long enough @@ -252,7 +266,9 @@ public void setup() throws Exception { var https2TestServer = new Http2TestServer("localhost", true, sslContext); https2TestServer.addHandler(new Http2TestHandler(), "/https2/"); this.https2TestServer = HttpTestServer.of(https2TestServer); + this.https2TestServer.addHandler(new HttpHeadOrGetHandler(), "/https2/head/"); https2URI = "https://" + this.https2TestServer.serverAuthority() + "/https2/x"; + String h2Head = "https://" + this.https2TestServer.serverAuthority() + "/https2/head/z"; // Override the default exchange supplier with a custom one to enable // particular test scenarios @@ -261,6 +277,13 @@ public void setup() throws Exception { this.http2TestServer.start(); this.https2TestServer.start(); + + // warmup to eliminate delay due to SSL class loading and initialization. + try (var client = HttpClient.newBuilder().sslContext(sslContext).build()) { + var request = HttpRequest.newBuilder(URI.create(h2Head)).HEAD().build(); + var resp = client.send(request, BodyHandlers.discarding()); + assertEquals(resp.statusCode(), 200); + } } @AfterTest @@ -279,11 +302,19 @@ public void handle(Http2TestExchange t) throws IOException { OutputStream os = t.getResponseBody()) { byte[] bytes = is.readAllBytes(); - System.out.println("Server " + t.getLocalAddress() + " received:\n" - + t.getRequestURI() + ": " + new String(bytes, StandardCharsets.UTF_8)); + if (bytes.length != 0) { + System.out.println("Server " + t.getLocalAddress() + " received:\n" + + t.getRequestURI() + ": " + new String(bytes, StandardCharsets.UTF_8)); + } else { + System.out.println("No request body for " + t.getRequestMethod()); + } + t.getResponseHeaders().setHeader("X-Connection-Key", t.getConnectionKey()); - if (bytes.length == 0) bytes = "no request body!".getBytes(StandardCharsets.UTF_8); + if (bytes.length == 0) { + bytes = "no request body!" + .repeat(100).getBytes(StandardCharsets.UTF_8); + } int window = Integer.getInteger("jdk.httpclient.windowsize", 2 * 16 * 1024); final int maxChunkSize; if (t instanceof FCHttp2TestExchange fct) { @@ -307,13 +338,22 @@ public void handle(Http2TestExchange t) throws IOException { // ignore and continue... } } - ((BodyOutputStream) os).writeUncontrolled(resp, 0, resp.length); + try { + ((BodyOutputStream) os).writeUncontrolled(resp, 0, resp.length); + } catch (IOException x) { + if (t instanceof FCHttp2TestExchange fct) { + fct.conn.updateConnectionWindow(resp.length); + } + } + } + } finally { + if (t instanceof FCHttp2TestExchange fct) { + fct.responseSent(query); + } else { + fail("Exchange is not %s but %s" + .formatted(FCHttp2TestExchange.class.getName(), t.getClass().getName())); } } - if (t instanceof FCHttp2TestExchange fct) { - fct.responseSent(query); - } else fail("Exchange is not %s but %s" - .formatted(FCHttp2TestExchange.class.getName(), t.getClass().getName())); } } diff --git a/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java b/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java index 27dbe637b94ef..4b00c0eea7bfd 100644 --- a/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java +++ b/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java @@ -49,6 +49,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.net.http.HttpHeaders; +import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.List; import java.util.ListIterator; @@ -66,6 +67,9 @@ import javax.net.ssl.SSLContext; +import static java.net.http.HttpClient.Version.HTTP_1_1; +import static java.net.http.HttpClient.Version.HTTP_2; + /** * Defines an adaptation layers so that a test server handlers and filters * can be implemented independently of the underlying server version. @@ -268,9 +272,9 @@ private static final class Http1TestExchange extends HttpTestExchange { this.exchange = exch; } @Override - public Version getServerVersion() { return Version.HTTP_1_1; } + public Version getServerVersion() { return HTTP_1_1; } @Override - public Version getExchangeVersion() { return Version.HTTP_1_1; } + public Version getExchangeVersion() { return HTTP_1_1; } @Override public InputStream getRequestBody() { return exchange.getRequestBody(); @@ -330,9 +334,9 @@ private static final class H2ExchangeImpl extends HttpTestExchange { this.exchange = exch; } @Override - public Version getServerVersion() { return Version.HTTP_2; } + public Version getServerVersion() { return HTTP_2; } @Override - public Version getExchangeVersion() { return Version.HTTP_2; } + public Version getExchangeVersion() { return HTTP_2; } @Override public InputStream getRequestBody() { return exchange.getRequestBody(); @@ -421,6 +425,53 @@ private void doHandle(HttpTestExchange t) throws IOException { } } + /** + * An {@link HttpTestHandler} that handles only HEAD and GET + * requests. If another method is used 405 is returned with + * an empty body. + * The response is always returned with fixed length. + */ + public static class HttpHeadOrGetHandler implements HttpTestHandler { + final String responseBody; + public HttpHeadOrGetHandler() { + this("pâté de tête persillé"); + } + public HttpHeadOrGetHandler(String responseBody) { + this.responseBody = Objects.requireNonNull(responseBody); + } + + @Override + public void handle(HttpTestExchange t) throws IOException { + try (var exchg = t) { + exchg.getRequestBody().readAllBytes(); + String method = exchg.getRequestMethod(); + switch (method) { + case "HEAD" -> { + byte[] resp = responseBody.getBytes(StandardCharsets.UTF_8); + if (exchg.getExchangeVersion() != HTTP_1_1) { + // with HTTP/2 or HTTP/3 the server will not send content-length + exchg.getResponseHeaders() + .addHeader("Content-Length", String.valueOf(resp.length)); + } + exchg.sendResponseHeaders(200, resp.length); + exchg.getResponseBody().close(); + } + case "GET" -> { + byte[] resp = responseBody.getBytes(StandardCharsets.UTF_8); + exchg.sendResponseHeaders(200, resp.length); + try (var os = exchg.getResponseBody()) { + os.write(resp); + } + } + default -> { + exchg.sendResponseHeaders(405, 0); + exchg.getResponseBody().close(); + } + } + } + } + } + public static class HttpTestEchoHandler implements HttpTestHandler { @Override @@ -877,7 +928,7 @@ public InetSocketAddress getAddress() { return new InetSocketAddress(InetAddress.getLoopbackAddress(), impl.getAddress().getPort()); } - public Version getVersion() { return Version.HTTP_1_1; } + public Version getVersion() { return HTTP_1_1; } @Override public void setRequestApprover(final Predicate approver) { @@ -902,7 +953,7 @@ public void addFilter(HttpTestFilter filter) { public void setAuthenticator(com.sun.net.httpserver.Authenticator authenticator) { context.setAuthenticator(authenticator); } - @Override public Version getVersion() { return Version.HTTP_1_1; } + @Override public Version getVersion() { return HTTP_1_1; } } private static class Http2TestServerImpl extends HttpTestServer { @@ -933,7 +984,7 @@ public InetSocketAddress getAddress() { return new InetSocketAddress(InetAddress.getLoopbackAddress(), impl.getAddress().getPort()); } - public Version getVersion() { return Version.HTTP_2; } + public Version getVersion() { return HTTP_2; } @Override public void setRequestApprover(final Predicate approver) { @@ -971,7 +1022,7 @@ public void setAuthenticator(final Authenticator authenticator) { "only BasicAuthenticator is supported on HTTP/2 context"); } } - @Override public Version getVersion() { return Version.HTTP_2; } + @Override public Version getVersion() { return HTTP_2; } } } diff --git a/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/TestServerConfigurator.java b/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/TestServerConfigurator.java index 5d16ac2415565..a471f3ce07f14 100644 --- a/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/TestServerConfigurator.java +++ b/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/TestServerConfigurator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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,8 +23,6 @@ package jdk.httpclient.test.lib.common; import java.net.InetAddress; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.List; import javax.net.ssl.SNIMatcher; @@ -59,14 +57,8 @@ public TestServerConfigurator(final InetAddress serverAddr, final SSLContext con @Override public void configure(final HttpsParameters params) { final SSLParameters sslParams = getSSLContext().getDefaultSSLParameters(); - @SuppressWarnings("removal") final SecurityManager sm = System.getSecurityManager(); - final String hostname; - if (sm == null) { - hostname = serverAddr.getHostName(); - } else { - final PrivilegedAction action = () -> serverAddr.getHostName(); - hostname = AccessController.doPrivileged(action); - } + final String hostname = serverAddr.getHostName(); + final List sniMatchers = List.of(new ServerNameMatcher(hostname)); sslParams.setSNIMatchers(sniMatchers); // configure the server with these custom SSLParameters diff --git a/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/http2/Http2TestServerConnection.java b/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/http2/Http2TestServerConnection.java index 068d2a49e576b..fb0ce92cd1da3 100644 --- a/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/http2/Http2TestServerConnection.java +++ b/test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/http2/Http2TestServerConnection.java @@ -1384,7 +1384,7 @@ public synchronized void obtainConnectionWindow(int amount) throws InterruptedEx } } - void updateConnectionWindow(int amount) { + public void updateConnectionWindow(int amount) { System.out.printf("sendWindow (window=%s, amount=%s) is now: %s%n", sendWindow, amount, sendWindow + amount); synchronized (this) { diff --git a/test/jdk/java/net/httpclient/security/filePerms/FileProcessorPermissionTest.java b/test/jdk/java/net/httpclient/security/filePerms/FileProcessorPermissionTest.java index 3c857ba1b4809..c892077172700 100644 --- a/test/jdk/java/net/httpclient/security/filePerms/FileProcessorPermissionTest.java +++ b/test/jdk/java/net/httpclient/security/filePerms/FileProcessorPermissionTest.java @@ -29,7 +29,6 @@ import java.nio.file.Path; import java.nio.file.Paths; -import java.security.PrivilegedExceptionAction; import java.util.List; import java.net.http.HttpRequest; import java.net.http.HttpResponse.BodyHandlers; @@ -43,11 +42,14 @@ public class FileProcessorPermissionTest { static final Path fromFilePath = Paths.get(testSrc, "FileProcessorPermissionTest.java"); static final Path asFilePath = Paths.get(testSrc, "asFile.txt"); static final Path CWD = Paths.get("."); - static final Class SE = SecurityException.class; + + interface ExceptionAction { + T run() throws Exception; + } @Test public void test() throws Exception { - List> list = List.of( + List> list = List.of( () -> HttpRequest.BodyPublishers.ofFile(fromFilePath), () -> BodyHandlers.ofFile(asFilePath), @@ -59,7 +61,7 @@ public void test() throws Exception { () -> BodyHandlers.ofFileDownload(CWD, CREATE, WRITE) ); - for (PrivilegedExceptionAction pa : list) { + for (ExceptionAction pa : list) { pa.run(); } diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java index 7a960892aec59..415caeb11961e 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/AuthenticationFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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,7 +38,6 @@ import java.net.http.HttpHeaders; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; -import java.security.AccessController; import java.util.Arrays; import java.util.Base64; import java.util.Collections; @@ -196,8 +195,7 @@ private void doTestAuthentication(String uri, Version v, String proxy) throws Ex HttpRequestImpl origReq = new HttpRequestImpl(reqBuilder); HttpRequestImpl req = new HttpRequestImpl(origReq, ps); MultiExchange multi = new MultiExchange(origReq, req, client, - BodyHandlers.replacing(null), - null, AccessController.getContext()); + BodyHandlers.replacing(null), null); Exchange exchange = new Exchange<>(req, multi); out.println("\nSimulating unauthenticated request to " + uri); filter.request(req, multi); @@ -266,8 +264,7 @@ private void doTestAuthentication(String uri, Version v, String proxy) throws Ex HttpRequestImpl origReq2 = new HttpRequestImpl(reqBuilder2); HttpRequestImpl req2 = new HttpRequestImpl(origReq2, ps); MultiExchange multi2 = new MultiExchange(origReq2, req2, client, - HttpResponse.BodyHandlers.replacing(null), - null, AccessController.getContext()); + HttpResponse.BodyHandlers.replacing(null), null); filter.request(req2, multi2); out.println("Check that filter has added credentials from cache for " + reqURI2 + " with proxy " + req2.proxy()); @@ -298,8 +295,7 @@ && isNullOrEmpty(reqURI.getFragment()) HttpRequestImpl origReq3 = new HttpRequestImpl(reqBuilder3); HttpRequestImpl req3 = new HttpRequestImpl(origReq3, ps); MultiExchange multi3 = new MultiExchange(origReq3, req3, client, - HttpResponse.BodyHandlers.replacing(null), - null, AccessController.getContext()); + HttpResponse.BodyHandlers.replacing(null), null); filter.request(req3, multi3); HttpHeaders h3 = req3.getSystemHeadersBuilder().build(); if (proxy == null) { @@ -342,8 +338,7 @@ && isNullOrEmpty(reqURI.getFragment()) HttpRequestImpl origReq4 = new HttpRequestImpl(reqBuilder4); HttpRequestImpl req4 = new HttpRequestImpl(origReq4, fakeProxy); MultiExchange multi4 = new MultiExchange(origReq4, req4, client, - HttpResponse.BodyHandlers.replacing(null), null, - AccessController.getContext()); + HttpResponse.BodyHandlers.replacing(null), null); out.println("Simulating new request to " + reqURI4 + " with a proxy " + req4.proxy()); assertTrue((req4.proxy() == null) == (proxy != null), "(req4.proxy() == null) == (proxy != null) should be true"); @@ -383,8 +378,7 @@ && isNullOrEmpty(reqURI.getFragment()) HttpRequestImpl origReq5 = new HttpRequestImpl(reqBuilder5); HttpRequestImpl req5 = new HttpRequestImpl(origReq5, NO_PROXY); MultiExchange multi5 = new MultiExchange(origReq5, req5, client, - HttpResponse.BodyHandlers.replacing(null), null, - AccessController.getContext()); + HttpResponse.BodyHandlers.replacing(null), null); out.println("Simulating new request to " + reqURI + " with a proxy " + req5.proxy()); assertTrue(req5.proxy() == null, "req5.proxy() should be null"); Exchange exchange5 = new Exchange<>(req5, multi5); @@ -437,8 +431,7 @@ && isNullOrEmpty(reqURI.getFragment()) HttpRequestImpl origReq6 = new HttpRequestImpl(reqBuilder6); HttpRequestImpl req6 = new HttpRequestImpl(origReq6, ps); MultiExchange multi6 = new MultiExchange(origReq6, req6, client, - HttpResponse.BodyHandlers.replacing(null), null, - AccessController.getContext()); + HttpResponse.BodyHandlers.replacing(null), null); out.println("Simulating new request to " + reqURI + " with a proxy " + req6.proxy()); assertTrue(req6.proxy() != null, "req6.proxy() should not be null"); Exchange exchange6 = new Exchange<>(req6, multi6); @@ -461,8 +454,7 @@ && isNullOrEmpty(reqURI.getFragment()) HttpRequestImpl origReq7 = new HttpRequestImpl(reqBuilder7); HttpRequestImpl req7 = new HttpRequestImpl(origReq7, ps); MultiExchange multi7 = new MultiExchange(origReq7, req7, client, - HttpResponse.BodyHandlers.replacing(null), null, - AccessController.getContext()); + HttpResponse.BodyHandlers.replacing(null), null); out.println("Simulating new request to " + reqURI7 + " with a proxy " + req7.proxy()); assertTrue(req7.proxy() == null, "req7.proxy() should be null"); Exchange exchange7 = new Exchange<>(req7, multi7); diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java index 6619eff008a08..9b5764735b216 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/RawChannelTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024, 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 @@ -221,7 +221,6 @@ private static RawChannel channelOf(int port) throws Exception { requestImpl, clientImpl, discarding(), - null, null); HttpResponse r = mex.responseAsync(clientImpl.theExecutor()) .get(30, SECONDS); diff --git a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SimpleSSLContext.java b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SimpleSSLContext.java index 5277eed3ac07a..e6897a83de449 100644 --- a/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SimpleSSLContext.java +++ b/test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/SimpleSSLContext.java @@ -42,13 +42,6 @@ /** * Creates a simple usable SSLContext for SSLSocketFactory * or a HttpsServer using a default keystore in the test tree. - *

- * Using this class with a security manager requires the following - * permissions to be granted: - *

- * permission "java.util.PropertyPermission" "test.src.path", "read"; - * permission java.io.FilePermission "/path/to/test/lib/jdk/test/lib/testkeys", "read"; - * The exact path above depends on the location of the test. */ public class SimpleSSLContext { @@ -60,27 +53,17 @@ public class SimpleSSLContext { public SimpleSSLContext() throws IOException { String paths = System.getProperty("test.src.path"); StringTokenizer st = new StringTokenizer(paths, File.pathSeparator); - boolean securityExceptions = false; SSLContext sslContext = null; while (st.hasMoreTokens()) { String path = st.nextToken(); - try { - File f = new File(path, "../../../../../lib/jdk/test/lib/net/testkeys"); - if (f.exists()) { - try (FileInputStream fis = new FileInputStream(f)) { - sslContext = init(fis); - break; - } + File f = new File(path, "../../../../../lib/jdk/test/lib/net/testkeys"); + if (f.exists()) { + try (FileInputStream fis = new FileInputStream(f)) { + sslContext = init(fis); + break; } - } catch (SecurityException e) { - // catch and ignore because permission only required - // for one entry on path (at most) - securityExceptions = true; } } - if (securityExceptions) { - System.out.println("SecurityExceptions thrown on loading testkeys"); - } ssl = sslContext; } diff --git a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/SetTimesNanos.java b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/SetTimesNanos.java index d71b9407bbce3..acdff69260166 100644 --- a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/SetTimesNanos.java +++ b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/SetTimesNanos.java @@ -24,7 +24,6 @@ /* @test * @bug 8181493 8231174 8343417 * @summary Verify that nanosecond precision is maintained for file timestamps - * @requires (os.family == "linux") | (os.family == "mac") | (os.family == "windows") * @library ../.. /test/lib * @build jdk.test.lib.Platform * @modules java.base/sun.nio.fs:+open @@ -51,18 +50,6 @@ public class SetTimesNanos { public static void main(String[] args) throws Exception { - if (!Platform.isWindows()) { - // Check whether futimens() system call is supported - Class unixNativeDispatcherClass = - Class.forName("sun.nio.fs.UnixNativeDispatcher"); - Method futimensSupported = - unixNativeDispatcherClass.getDeclaredMethod("futimensSupported"); - futimensSupported.setAccessible(true); - if (!(boolean)futimensSupported.invoke(null)) { - throw new SkippedException("futimens() not supported"); - } - } - Path dirPath = Path.of("test"); Path dir = Files.createDirectory(dirPath); FileStore store = Files.getFileStore(dir); @@ -80,10 +67,8 @@ public static void main(String[] args) throws Exception { Path file = Files.createFile(dir.resolve("test.dat")); testNanos(file); - if (Platform.isLinux()) { - testNanosLink(false); - testNanosLink(true); - } + testNanosLink(false); + testNanosLink(true); } private static void testNanos(Path path) throws IOException { @@ -130,7 +115,14 @@ private static void testNanosLink(boolean absolute) throws IOException { Files.createFile(target); Files.createSymbolicLink(symlink, target); - var newTime = FileTime.from(1730417633157646106L, NANOSECONDS); + long timeNanos = 1730417633157646106L; + + // Windows file time resolution is 100ns so truncate + if (Platform.isWindows()) { + timeNanos = 100L*(timeNanos/100L); + } + + var newTime = FileTime.from(timeNanos, NANOSECONDS); System.out.println("newTime: " + newTime.to(NANOSECONDS)); for (Path p : List.of(target, symlink)) { diff --git a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListMapTest.java b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListMapTest.java index 044f126dd9e88..5560b9ed4fe00 100644 --- a/test/jdk/java/util/concurrent/tck/ConcurrentSkipListMapTest.java +++ b/test/jdk/java/util/concurrent/tck/ConcurrentSkipListMapTest.java @@ -1323,6 +1323,37 @@ private int lastAscending() { } } + /** + * Spliterators.trySplit() returns null with an empty map and non-null when + * it is not empty. + */ + public void testSpliterators() { + // To test JDK-8343426 + ConcurrentSkipListMap map = new ConcurrentSkipListMap<>(); + for (int i = 1; i <= 1000; i++) map.put(i, i); + // ensure that the splits do happen + assertNotNull(map.keySet().spliterator().trySplit()); + assertNotNull(map.entrySet().spliterator().trySplit()); + assertNotNull(map.values().spliterator().trySplit()); + // ensure that the splits return *all* the items in the set + assertEquals(500_500, map.keySet() + .parallelStream() + .mapToInt(Integer::valueOf) + .sum()); + assertEquals(500_500, map.values() + .parallelStream() + .mapToInt(Integer::valueOf) + .sum()); + assertEquals(500_500 * 2, map.entrySet() + .parallelStream() + .mapToInt(entry -> entry.getKey() + entry.getValue()) + .sum()); + map.clear(); + assertNull(map.keySet().spliterator().trySplit()); + assertNull(map.entrySet().spliterator().trySplit()); + assertNull(map.values().spliterator().trySplit()); + } + static void assertEq(Item i, int j) { if (i == null) mustEqual(j, -1); diff --git a/test/jdk/javax/print/PrintSE/PrintSE.sh b/test/jdk/javax/print/PrintSE/PrintSE.sh deleted file mode 100644 index 7d9144b959cba..0000000000000 --- a/test/jdk/javax/print/PrintSE/PrintSE.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/sh - -# -# Copyright (c) 2008, 2017, 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 -# @key printer -# @bug 6662775 -# @summary Tests queuePrintJob is sufficient permission for printing. This test -# prints a page to a printer. If a document printer is installed, a -# popup can appear (to select the file location). -# @run clean PrintSE -# @run build PrintSE -# @run compile PrintSE.java -# @run shell/timeout=300 PrintSE.sh - -echo ------------------------------------------------------------- -echo Launching test for `basename $0 .sh` -echo ------------------------------------------------------------- - -createJavaPolicyFile() -{ - cat << EOF > ${TESTCLASSES}/print.policy -grant { - permission java.lang.RuntimePermission "queuePrintJob"; -}; -EOF -} - -createJavaPolicyFile - -${TESTJAVA}/bin/java ${TESTVMOPTS} \ - -Djava.security.manager \ - -Djava.security.policy=${TESTCLASSES}/print.policy \ - -cp ${TESTCLASSES} PrintSE - -exit $? diff --git a/test/jdk/jdk/classfile/BoundAttributeTest.java b/test/jdk/jdk/classfile/BoundAttributeTest.java index 6a164bec2f9d7..e8f12356128d0 100644 --- a/test/jdk/jdk/classfile/BoundAttributeTest.java +++ b/test/jdk/jdk/classfile/BoundAttributeTest.java @@ -41,6 +41,7 @@ import java.lang.classfile.attribute.MethodParameterInfo; import java.lang.classfile.attribute.MethodParametersAttribute; import java.lang.classfile.constantpool.ConstantPoolException; +import java.lang.classfile.constantpool.Utf8Entry; import java.lang.constant.ClassDesc; import java.lang.constant.ConstantDescs; import java.lang.constant.MethodTypeDesc; @@ -89,6 +90,11 @@ public void writeBody(BufWriterImpl b) { b.writeIndex(oneClass); b.writeIndex(oneClassString); } + + @Override + public Utf8Entry attributeName() { + return cp.utf8Entry(Attributes.NAME_NEST_MEMBERS); + } }); }); diff --git a/test/jdk/jdk/classfile/CorpusTest.java b/test/jdk/jdk/classfile/CorpusTest.java index 631e2f8afaa1b..513005370e74c 100644 --- a/test/jdk/jdk/classfile/CorpusTest.java +++ b/test/jdk/jdk/classfile/CorpusTest.java @@ -93,6 +93,11 @@ public void writeBody(BufWriterImpl b) { b.writeU2(curPc); b.writeU2(ln.line()); } + + @Override + public Utf8Entry attributeName() { + return cob.constantPool().utf8Entry(Attributes.NAME_LINE_NUMBER_TABLE); + } }); case LocalVariable lv -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTable()) { @Override @@ -100,6 +105,11 @@ public void writeBody(BufWriterImpl b) { b.writeU2(1); Util.writeLocalVariable(b, lv); } + + @Override + public Utf8Entry attributeName() { + return cob.constantPool().utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + } }); case LocalVariableType lvt -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.localVariableTypeTable()) { @Override @@ -107,6 +117,11 @@ public void writeBody(BufWriterImpl b) { b.writeU2(1); Util.writeLocalVariable(b, lvt); } + + @Override + public Utf8Entry attributeName() { + return cob.constantPool().utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TYPE_TABLE); + } }); default -> cob.with(coe); } diff --git a/test/jdk/jdk/classfile/LimitsTest.java b/test/jdk/jdk/classfile/LimitsTest.java index a1899ac1c842b..6f3dc04c6651b 100644 --- a/test/jdk/jdk/classfile/LimitsTest.java +++ b/test/jdk/jdk/classfile/LimitsTest.java @@ -41,6 +41,7 @@ import java.lang.classfile.constantpool.ConstantPoolBuilder; import java.lang.classfile.constantpool.ConstantPoolException; import java.lang.classfile.constantpool.IntegerEntry; +import java.lang.classfile.constantpool.Utf8Entry; import java.util.List; import jdk.internal.classfile.impl.BufWriterImpl; @@ -49,6 +50,7 @@ import jdk.internal.classfile.impl.LabelContext; import jdk.internal.classfile.impl.UnboundAttribute; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class LimitsTest { @@ -145,7 +147,13 @@ public void writeBody(BufWriterImpl b) { b.writeInt(-2); //npairs to jump back and cause OOME if not checked b.writeU2(0);//exception handlers b.writeU2(0);//attributes - }})))).methods().get(0).code().get().elementList()); + } + + @Override + public Utf8Entry attributeName() { + return mb.constantPool().utf8Entry(Attributes.NAME_CODE); + } + })))).methods().get(0).code().get().elementList()); } @Test @@ -167,7 +175,13 @@ public void writeBody(BufWriterImpl b) { b.writeInt(-5); //high to jump back and cause OOME if not checked b.writeU2(0);//exception handlers b.writeU2(0);//attributes - }})))).methods().get(0).code().get().elementList()); + } + + @Override + public Utf8Entry attributeName() { + return mb.constantPool().utf8Entry(Attributes.NAME_CODE); + } + })))).methods().get(0).code().get().elementList()); assertThrows(IllegalArgumentException.class, () -> ClassFile.of().parse(ClassFile.of().build(ClassDesc.of("TableSwitchClass"), cb -> cb.withMethod( "tableSwitchMethod", MethodTypeDesc.of(ConstantDescs.CD_void), 0, mb -> @@ -189,7 +203,13 @@ public void writeBody(BufWriterImpl b) { b.writeInt(Integer.MAX_VALUE - 4); //high to jump back and cause infinite loop b.writeU2(0);//exception handlers b.writeU2(0);//attributes - }})))).methods().get(0).code().get().elementList()); + } + + @Override + public Utf8Entry attributeName() { + return mb.constantPool().utf8Entry(Attributes.NAME_CODE); + } + })))).methods().get(0).code().get().elementList()); } @Test diff --git a/test/jdk/jdk/classfile/LowJCovAttributeTest.java b/test/jdk/jdk/classfile/LowJCovAttributeTest.java index 858b9c90416d1..ed29a05735793 100644 --- a/test/jdk/jdk/classfile/LowJCovAttributeTest.java +++ b/test/jdk/jdk/classfile/LowJCovAttributeTest.java @@ -76,7 +76,7 @@ void testRead() { private void testRead0() { int[] mask = new int[1]; for (Attribute attr : classLow.attributes()) { - switch (attr.attributeName()) { + switch (attr.attributeName().stringValue()) { case Attributes.NAME_COMPILATION_ID: { CompilationIDAttribute cid = (CompilationIDAttribute) attr; Utf8Entry v = cid.compilationId(); diff --git a/test/jdk/jdk/classfile/LowModuleTest.java b/test/jdk/jdk/classfile/LowModuleTest.java index e78eff74d1d4c..b017fe8475661 100644 --- a/test/jdk/jdk/classfile/LowModuleTest.java +++ b/test/jdk/jdk/classfile/LowModuleTest.java @@ -77,7 +77,7 @@ void testRead(Path path, TestInfo test) throws Exception { private void testRead0(ClassModel classLow) { for (Attribute attr : classLow.attributes()) { - switch (attr.attributeName()) { + switch (attr.attributeName().stringValue()) { case Attributes.NAME_SOURCE_FILE: { SourceFileAttribute sfa = (SourceFileAttribute) attr; Utf8Entry sf = sfa.sourceFile(); diff --git a/test/jdk/jdk/classfile/VerifierSelfTest.java b/test/jdk/jdk/classfile/VerifierSelfTest.java index b6a2f08c9ecd7..1f9f199a33bcc 100644 --- a/test/jdk/jdk/classfile/VerifierSelfTest.java +++ b/test/jdk/jdk/classfile/VerifierSelfTest.java @@ -31,7 +31,9 @@ import java.io.IOException; import java.lang.classfile.constantpool.PoolEntry; import java.lang.constant.ClassDesc; + import static java.lang.constant.ConstantDescs.*; + import java.lang.invoke.MethodHandleInfo; import java.net.URI; import java.nio.file.FileSystem; @@ -47,12 +49,14 @@ import java.lang.classfile.*; import java.lang.classfile.attribute.*; import java.lang.classfile.components.ClassPrinter; +import java.lang.classfile.constantpool.Utf8Entry; import java.lang.constant.ModuleDesc; import jdk.internal.classfile.impl.BufWriterImpl; import jdk.internal.classfile.impl.DirectClassBuilder; import jdk.internal.classfile.impl.UnboundAttribute; import org.junit.jupiter.api.Test; + import static org.junit.jupiter.api.Assertions.*; class VerifierSelfTest { @@ -109,6 +113,11 @@ void testInvalidAttrLocation() { public void writeBody(BufWriterImpl b) { b.writeU2(0); } + + @Override + public Utf8Entry attributeName() { + return cb.constantPool().utf8Entry(Attributes.NAME_LOCAL_VARIABLE_TABLE); + } })); assertTrue(cc.verify(bytes).stream().anyMatch(e -> e.getMessage().contains("Invalid LocalVariableTable attribute location"))); } @@ -366,7 +375,7 @@ private static class CloneAttribute extends CustomAttribute { super(new AttributeMapper(){ @Override public String name() { - return a.attributeName(); + return a.attributeName().stringValue(); } @Override diff --git a/test/jdk/jdk/classfile/helpers/ClassRecord.java b/test/jdk/jdk/classfile/helpers/ClassRecord.java index e7a239015f605..c663721ec9f00 100644 --- a/test/jdk/jdk/classfile/helpers/ClassRecord.java +++ b/test/jdk/jdk/classfile/helpers/ClassRecord.java @@ -234,7 +234,7 @@ public record AttributesRecord( public static AttributesRecord ofStreamingElements(Supplier> elements, ConstantPool cp, CompatibilityFilter... cf) { Map> attrs = elements.get().filter(e -> e instanceof Attribute) .map(e -> (Attribute) e) - .collect(toMap(Attribute::attributeName, e -> e)); + .collect(toMap(a -> a.attributeName().stringValue(), e -> e)); return new AttributesRecord( mapAttr(attrs, annotationDefault(), a -> ElementValueRecord.ofElementValue(a.defaultValue())), cp == null ? null : IntStream.range(0, cp.bootstrapMethodCount()).mapToObj(i -> BootstrapMethodRecord.ofBootstrapMethodEntry(cp.bootstrapMethodEntry(i))).collect(toSetOrNull()), diff --git a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java index c1d9781b6ce65..b0e1d6c312d20 100644 --- a/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java +++ b/test/jdk/jdk/classfile/helpers/RebuildingTransformation.java @@ -59,8 +59,8 @@ static byte[] transform(ClassModel clm) { case RuntimeVisibleTypeAnnotationsAttribute a -> fb.with(RuntimeVisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(a.annotations(), null, null))); case SignatureAttribute a -> fb.with(SignatureAttribute.of(Signature.parseFrom(a.asTypeSignature().signatureString()))); case SyntheticAttribute a -> fb.with(SyntheticAttribute.of()); - case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); - case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName()); + case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); + case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName().stringValue()); } } }); @@ -91,8 +91,8 @@ static byte[] transform(ClassModel clm) { case RuntimeVisibleTypeAnnotationsAttribute a -> mb.with(RuntimeVisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(a.annotations(), null, null))); case SignatureAttribute a -> mb.with(SignatureAttribute.of(MethodSignature.parseFrom(a.asMethodSignature().signatureString()))); case SyntheticAttribute a -> mb.with(SyntheticAttribute.of()); - case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); - case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName()); + case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); + case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName().stringValue()); } } }); @@ -131,7 +131,7 @@ static byte[] transform(ClassModel clm) { case RuntimeVisibleAnnotationsAttribute rvaa -> rcac.accept(RuntimeVisibleAnnotationsAttribute.of(transformAnnotations(rvaa.annotations()))); case RuntimeVisibleTypeAnnotationsAttribute rvtaa -> rcac.accept(RuntimeVisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(rvtaa.annotations(), null, null))); case SignatureAttribute sa -> rcac.accept(SignatureAttribute.of(Signature.parseFrom(sa.asTypeSignature().signatureString()))); - default -> throw new AssertionError("Unexpected record component attribute: " + rca.attributeName()); + default -> throw new AssertionError("Unexpected record component attribute: " + rca.attributeName().stringValue()); }}).toArray(Attribute[]::new))).toArray(RecordComponentInfo[]::new))); case RuntimeInvisibleAnnotationsAttribute a -> clb.with(RuntimeInvisibleAnnotationsAttribute.of(transformAnnotations(a.annotations()))); case RuntimeInvisibleTypeAnnotationsAttribute a -> clb.with(RuntimeInvisibleTypeAnnotationsAttribute.of(transformTypeAnnotations(a.annotations(), null, null))); @@ -142,8 +142,8 @@ static byte[] transform(ClassModel clm) { case SourceFileAttribute a -> clb.with(SourceFileAttribute.of(a.sourceFile().stringValue())); case SourceIDAttribute a -> clb.with(SourceIDAttribute.of(a.sourceId().stringValue())); case SyntheticAttribute a -> clb.with(SyntheticAttribute.of()); - case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); - case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName()); + case CustomAttribute a -> throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); + case UnknownAttribute a -> throw new AssertionError("Unexpected unknown attribute: " + a.attributeName().stringValue()); } } }); @@ -595,7 +595,7 @@ else switch (i.constantValue()) { transformFrameTypeInfos(fr.locals(), cob, labels), transformFrameTypeInfos(fr.stack(), cob, labels))).toList())); case CustomAttribute a -> - throw new AssertionError("Unexpected custom attribute: " + a.attributeName()); + throw new AssertionError("Unexpected custom attribute: " + a.attributeName().stringValue()); } } } diff --git a/test/jdk/jdk/internal/math/FloatingDecimal/TestFDBigInteger.java b/test/jdk/jdk/internal/math/FloatingDecimal/TestFDBigInteger.java index 9eb8cfe784460..04be8efa38c75 100644 --- a/test/jdk/jdk/internal/math/FloatingDecimal/TestFDBigInteger.java +++ b/test/jdk/jdk/internal/math/FloatingDecimal/TestFDBigInteger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024, 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 @@ -22,13 +22,13 @@ */ import java.math.BigInteger; -import java.util.Random; +import java.nio.charset.StandardCharsets; import jdk.internal.math.FDBigInteger; /** * @test - * @bug 7032154 - * @summary unit testys of FDBigInteger + * @bug 7032154 8342693 + * @summary unit tests of FDBigInteger * @modules java.base/jdk.internal.math * @author Dmitry Nadezhin */ @@ -52,7 +52,7 @@ public class TestFDBigInteger { } private static FDBigInteger mutable(String hex, int offset) { - char[] chars = new BigInteger(hex, 16).toString().toCharArray(); + byte[] chars = new BigInteger(hex, 16).toString().getBytes(StandardCharsets.US_ASCII); return new FDBigInteger(0, chars, 0, chars.length).multByPow52(0, offset * 32); } diff --git a/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java b/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java index 6dff95000f075..ee4d2021b8770 100644 --- a/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java +++ b/test/jdk/jdk/internal/reflect/CallerSensitive/CheckCSMs.java @@ -73,7 +73,6 @@ public class CheckCSMs { Set.of("java/io/ObjectStreamField#getType ()Ljava/lang/Class;", "java/lang/Runtime#load (Ljava/lang/String;)V", "java/lang/Runtime#loadLibrary (Ljava/lang/String;)V", - "java/lang/Thread#getContextClassLoader ()Ljava/lang/ClassLoader;", "javax/sql/rowset/serial/SerialJavaObject#getFields ()[Ljava/lang/reflect/Field;" ); @@ -81,7 +80,6 @@ public class CheckCSMs { // methods that takes an additional caller class parameter. private static Set UNSUPPORTED_VIRTUAL_METHODS = Set.of("java/io/ObjectStreamField#getType (Ljava/lang/Class;)Ljava/lang/Class;", - "java/lang/Thread#getContextClassLoader (Ljava/lang/Class;)Ljava/lang/ClassLoader;", "javax/sql/rowset/serial/SerialJavaObject#getFields (Ljava/lang/Class;)[Ljava/lang/reflect/Field;" ); diff --git a/test/jdk/jdk/jfr/event/oldobject/TestClassLoaderLeak.java b/test/jdk/jdk/jfr/event/oldobject/TestClassLoaderLeak.java index aa74c63138961..6f7337d37777d 100644 --- a/test/jdk/jdk/jfr/event/oldobject/TestClassLoaderLeak.java +++ b/test/jdk/jdk/jfr/event/oldobject/TestClassLoaderLeak.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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,6 +40,8 @@ * @test * @key jfr * @requires vm.hasJFR + * @requires vm.flagless + * @comment Marked as flagless until JDK-8322597 is fixed * @library /test/lib /test/jdk * @modules jdk.jfr/jdk.jfr.internal.test * @run main/othervm -XX:TLABSize=2k -Xmx64m jdk.jfr.event.oldobject.TestClassLoaderLeak diff --git a/test/jdk/jdk/jfr/event/oldobject/TestObjectDescription.java b/test/jdk/jdk/jfr/event/oldobject/TestObjectDescription.java index d62b20bc995bd..447d2bb9cecf4 100644 --- a/test/jdk/jdk/jfr/event/oldobject/TestObjectDescription.java +++ b/test/jdk/jdk/jfr/event/oldobject/TestObjectDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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,7 +41,9 @@ * @test * @key jfr * @requires vm.hasJFR - * @requires vm.gc != "Z" & vm.gc != "Shenandoah" + * @requires vm.gc != "Shenandoah" + * @requires vm.flagless + * @comment Marked as flagless until JDK-8344015 is fixed * @library /test/lib /test/jdk * @modules jdk.jfr/jdk.jfr.internal.test * @run main/othervm -XX:TLABSize=2k jdk.jfr.event.oldobject.TestObjectDescription diff --git a/test/jdk/jdk/jfr/threading/TestDeepVirtualStackTrace.java b/test/jdk/jdk/jfr/threading/TestDeepVirtualStackTrace.java index d754d9cb59800..3fecd91ea62c2 100644 --- a/test/jdk/jdk/jfr/threading/TestDeepVirtualStackTrace.java +++ b/test/jdk/jdk/jfr/threading/TestDeepVirtualStackTrace.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -42,7 +42,7 @@ * @requires vm.hasJFR & vm.continuations * @library /test/lib /test/jdk * @modules jdk.jfr/jdk.jfr.internal - * @run main/othervm -XX:FlightRecorderOptions:stackdepth=2048 + * @run main/othervm -XX:MaxNewSize=40M -XX:FlightRecorderOptions:stackdepth=2048 * jdk.jfr.threading.TestDeepVirtualStackTrace */ public class TestDeepVirtualStackTrace { @@ -80,6 +80,8 @@ private static void testNativeEvent() throws Exception { private static void deepsleep(int depth) { if (depth == 0) { + // The TLAB max size is not limited explicitly + // So the test limit max size of young generation to allocate outside TLAB allocated = new Object[10_000_000]; System.out.println("Emitted ObjectAllocationOutsideTLAB event"); return; diff --git a/test/jdk/jdk/nio/zipfs/TestPosix.java b/test/jdk/jdk/nio/zipfs/TestPosix.java index f63f091c32e92..420c1618e12a9 100644 --- a/test/jdk/jdk/nio/zipfs/TestPosix.java +++ b/test/jdk/jdk/nio/zipfs/TestPosix.java @@ -29,10 +29,6 @@ import java.nio.ByteOrder; import java.nio.file.*; import java.nio.file.attribute.*; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; import java.time.Instant; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @@ -219,35 +215,28 @@ static interface Executor { private static String expectedDefaultOwner(Path zf) { try { - try { - PrivilegedExceptionAction pa = ()->Files.getOwner(zf).getName(); - return AccessController.doPrivileged(pa); - } catch (UnsupportedOperationException e) { - // if we can't get the owner of the file, we fall back to system property user.name - PrivilegedAction pa = ()->System.getProperty("user.name"); - return AccessController.doPrivileged(pa); - } - } catch (PrivilegedActionException | SecurityException e) { + return Files.getOwner(zf).getName(); + } catch (UnsupportedOperationException e) { + // if we can't get the owner of the file, we fall back to system property user.name + return System.getProperty("user.name"); + } catch (IOException e) { System.out.println("Caught " + e.getClass().getName() + "(" + e.getMessage() + - ") when running a privileged operation to get the default owner."); + ") when getting the default owner."); return null; } } private static String expectedDefaultGroup(Path zf, String defaultOwner) { try { - try { - PosixFileAttributeView zfpv = Files.getFileAttributeView(zf, PosixFileAttributeView.class); - if (zfpv == null) { - return defaultOwner; - } - PrivilegedExceptionAction pa = ()->zfpv.readAttributes().group().getName(); - return AccessController.doPrivileged(pa); - } catch (UnsupportedOperationException e) { + PosixFileAttributeView zfpv = Files.getFileAttributeView(zf, PosixFileAttributeView.class); + if (zfpv == null) { return defaultOwner; } - } catch (PrivilegedActionException | SecurityException e) { - System.out.println("Caught an exception when running a privileged operation to get the default group."); + return zfpv.readAttributes().group().getName(); + } catch (UnsupportedOperationException e) { + return defaultOwner; + } catch (IOException e) { + System.out.println("Caught an exception when getting the default group."); e.printStackTrace(); return null; } diff --git a/test/jdk/sun/security/ssl/CipherSuite/AbstractDisableCipherSuites.java b/test/jdk/sun/security/ssl/CipherSuite/AbstractDisableCipherSuites.java new file mode 100644 index 0000000000000..3f428e458ca55 --- /dev/null +++ b/test/jdk/sun/security/ssl/CipherSuite/AbstractDisableCipherSuites.java @@ -0,0 +1,295 @@ +/* + * Copyright (c) 2018, 2024, 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. + */ + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLEngineResult; +import javax.net.ssl.SSLEngineResult.HandshakeStatus; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLSession; + +/** + * This is not a test. Actual tests are implemented by concrete subclasses. + * The abstract class AbstractDisableCipherSuites provides a base framework + * for testing cipher suite disablement. + */ +public abstract class AbstractDisableCipherSuites { + + private static final byte RECTYPE_HS = 0x16; + private static final byte HSMSG_CLIHELLO = 0x01; + private static final ByteBuffer CLIOUTBUF = + ByteBuffer.wrap("Client Side".getBytes()); + + /** + * Create an engine with the default set of cipher suites enabled and make + * sure none of the disabled suites are present in the client hello. + * + * @param disabledSuiteIds the {@code List} of disabled cipher suite IDs + * to be checked for. + * + * @return true if the test passed (No disabled suites), false otherwise + */ + protected boolean testDefaultCase(List disabledSuiteIds) + throws Exception { + System.err.println("\nTest: Default SSLEngine suite set"); + SSLEngine ssle = makeEngine(); + if (getDebug()) { + listCiphers("Suite set upon creation", ssle); + } + SSLEngineResult clientResult; + ByteBuffer cTOs = makeClientBuf(ssle); + clientResult = ssle.wrap(CLIOUTBUF, cTOs); + if (getDebug()) { + dumpResult("ClientHello: ", clientResult); + } + cTOs.flip(); + boolean foundSuite = areSuitesPresentCH(cTOs, disabledSuiteIds); + if (foundSuite) { + System.err.println("FAIL: Found disabled suites!"); + return false; + } else { + System.err.println("PASS: No disabled suites found."); + return true; + } + } + + /** + * Create an engine and set only disabled cipher suites. + * The engine should not create the client hello message since the only + * available suites to assert in the client hello are disabled ones. + * + * @param disabledSuiteNames an array of cipher suite names that + * should be disabled cipher suites. + * + * @return true if the engine throws SSLHandshakeException during client + * hello creation, false otherwise. + */ + protected boolean testEngOnlyDisabled(String[] disabledSuiteNames) + throws Exception { + System.err.println( + "\nTest: SSLEngine configured with only disabled suites"); + try { + SSLEngine ssle = makeEngine(); + ssle.setEnabledCipherSuites(disabledSuiteNames); + if (getDebug()) { + listCiphers("Suite set upon creation", ssle); + } + SSLEngineResult clientResult; + ByteBuffer cTOs = makeClientBuf(ssle); + clientResult = ssle.wrap(CLIOUTBUF, cTOs); + if (getDebug()) { + dumpResult("ClientHello: ", clientResult); + } + cTOs.flip(); + } catch (SSLHandshakeException shse) { + System.err.println("PASS: Caught expected exception: " + shse); + return true; + } + System.err.println("FAIL: Expected SSLHandshakeException not thrown"); + return false; + } + + /** + * Create an engine and add some disabled suites to the default + * set of cipher suites. Make sure none of the disabled suites show up + * in the client hello even though they were explicitly added. + * + * @param disabledNames an array of cipher suite names that + * should be disabled cipher suites. + * @param disabledIds the {@code List} of disabled cipher suite IDs + * to be checked for. + * + * @return true if the test passed (No disabled suites), false otherwise + */ + protected boolean testEngAddDisabled(String[] disabledNames, + List disabledIds) throws Exception { + System.err.println("\nTest: SSLEngine with disabled suites added"); + SSLEngine ssle = makeEngine(); + + // Add disabled suites to the existing engine's set of enabled suites + String[] initialSuites = ssle.getEnabledCipherSuites(); + String[] plusDisSuites = Arrays.copyOf(initialSuites, + initialSuites.length + disabledNames.length); + System.arraycopy(disabledNames, 0, plusDisSuites, + initialSuites.length, disabledNames.length); + ssle.setEnabledCipherSuites(plusDisSuites); + + if (getDebug()) { + listCiphers("Suite set upon creation", ssle); + } + SSLEngineResult clientResult; + ByteBuffer cTOs = makeClientBuf(ssle); + clientResult = ssle.wrap(CLIOUTBUF, cTOs); + if (getDebug()) { + dumpResult("ClientHello: ", clientResult); + } + cTOs.flip(); + boolean foundDisabled = areSuitesPresentCH(cTOs, disabledIds); + if (foundDisabled) { + System.err.println("FAIL: Found disabled suites!"); + return false; + } else { + System.err.println("PASS: No disabled suites found."); + return true; + } + } + + protected String getProtocol() { + return "TLSv1.2"; + } + + private SSLEngine makeEngine() throws GeneralSecurityException { + SSLContext ctx = SSLContext.getInstance(getProtocol()); + ctx.init(null, null, null); + return ctx.createSSLEngine(); + } + + private static ByteBuffer makeClientBuf(SSLEngine ssle) { + ssle.setUseClientMode(true); + ssle.setNeedClientAuth(false); + SSLSession sess = ssle.getSession(); + ByteBuffer cTOs = ByteBuffer.allocateDirect(sess.getPacketBufferSize()); + return cTOs; + } + + private static void listCiphers(String prefix, SSLEngine ssle) { + System.err.println(prefix + "\n---------------"); + String[] suites = ssle.getEnabledCipherSuites(); + for (String suite : suites) { + System.err.println(suite); + } + System.err.println("---------------"); + } + + /** + * Walk a TLS 1.2 or earlier ClientHello looking for any of the suites + * in the suiteIdList. + * + * @param clientHello a ByteBuffer containing the ClientHello message as + * a complete TLS record. The position of the buffer should be + * at the first byte of the TLS record header. + * @param suiteIdList a List of integer values corresponding to + * TLS cipher suite identifiers. + * + * @return true if at least one of the suites in {@code suiteIdList} + * is found in the ClientHello's cipher suite list + * + * @throws IOException if the data in the {@code clientHello} + * buffer is not a TLS handshake message or is not a client hello. + */ + private boolean areSuitesPresentCH(ByteBuffer clientHello, + List suiteIdList) throws IOException { + byte val; + + // Process the TLS Record + val = clientHello.get(); + if (val != RECTYPE_HS) { + throw new IOException( + "Not a handshake record, type = " + val); + } + + // Just skip over the version and length + clientHello.position(clientHello.position() + 4); + + // Check the handshake message type + val = clientHello.get(); + if (val != HSMSG_CLIHELLO) { + throw new IOException( + "Not a ClientHello handshake message, type = " + val); + } + + // Skip over the length + clientHello.position(clientHello.position() + 3); + + // Skip over the protocol version (2) and random (32); + clientHello.position(clientHello.position() + 34); + + // Skip past the session ID (variable length <= 32) + int len = Byte.toUnsignedInt(clientHello.get()); + if (len > 32) { + throw new IOException("Session ID is too large, len = " + len); + } + clientHello.position(clientHello.position() + len); + + // Finally, we are at the cipher suites. Walk the list and place them + // into a List. + int csLen = Short.toUnsignedInt(clientHello.getShort()); + if (csLen % 2 != 0) { + throw new IOException("CipherSuite length is invalid, len = " + + csLen); + } + int csCount = csLen / 2; + List csSuiteList = new ArrayList<>(csCount); + log("Found following suite IDs in hello:"); + for (int i = 0; i < csCount; i++) { + int curSuite = Short.toUnsignedInt(clientHello.getShort()); + log(String.format("Suite ID: 0x%04x", curSuite)); + csSuiteList.add(curSuite); + } + + // Now check to see if any of the suites passed in match what is in + // the suite list. + boolean foundMatch = false; + for (Integer cs : suiteIdList) { + if (csSuiteList.contains(cs)) { + System.err.format("Found match for suite ID 0x%04x\n", cs); + foundMatch = true; + break; + } + } + + // We don't care about the rest of the ClientHello message. + // Rewind and return whether we found a match or not. + clientHello.rewind(); + return foundMatch; + } + + private static void dumpResult(String str, SSLEngineResult result) { + System.err.println("The format of the SSLEngineResult is: \n" + + "\t\"getStatus() / getHandshakeStatus()\" +\n" + + "\t\"bytesConsumed() / bytesProduced()\"\n"); + HandshakeStatus hsStatus = result.getHandshakeStatus(); + System.err.println(str + result.getStatus() + "/" + hsStatus + ", " + + result.bytesConsumed() + "/" + result.bytesProduced() + " bytes"); + if (hsStatus == HandshakeStatus.FINISHED) { + System.err.println("\t...ready for application data"); + } + } + + private void log(String str) { + if (getDebug()) { + System.err.println(str); + } + } + + protected boolean getDebug() { + return false; + } +} diff --git a/test/jdk/sun/security/ssl/CipherSuite/NoDesRC4DesEdeCiphSuite.java b/test/jdk/sun/security/ssl/CipherSuite/NoDesRC4DesEdeCiphSuite.java index c9861324237c1..6b86dacc6401a 100644 --- a/test/jdk/sun/security/ssl/CipherSuite/NoDesRC4DesEdeCiphSuite.java +++ b/test/jdk/sun/security/ssl/CipherSuite/NoDesRC4DesEdeCiphSuite.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2024, 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 @@ -34,21 +34,11 @@ */ import java.security.Security; -import javax.net.ssl.*; -import javax.net.ssl.SSLEngineResult.HandshakeStatus; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.security.GeneralSecurityException; -import java.util.List; -import java.util.ArrayList; import java.util.Arrays; +import java.util.List; -public class NoDesRC4DesEdeCiphSuite { - - private static final boolean DEBUG = false; +public class NoDesRC4DesEdeCiphSuite extends AbstractDisableCipherSuites { - private static final byte RECTYPE_HS = 0x16; - private static final byte HSMSG_CLIHELLO = 0x01; // These are some groups of Cipher Suites by names and IDs private static final List DES_CS_LIST = Arrays.asList( @@ -93,28 +83,27 @@ public class NoDesRC4DesEdeCiphSuite { "SSL_RSA_WITH_3DES_EDE_CBC_SHA" }; - private static final ByteBuffer CLIOUTBUF = - ByteBuffer.wrap("Client Side".getBytes()); public static void main(String[] args) throws Exception { boolean allGood = true; String disAlg = Security.getProperty("jdk.tls.disabledAlgorithms"); System.err.println("Disabled Algs: " + disAlg); + NoDesRC4DesEdeCiphSuite test = new NoDesRC4DesEdeCiphSuite(); // Disabled DES tests - allGood &= testDefaultCase(DES_CS_LIST); - allGood &= testEngAddDisabled(DES_CS_LIST_NAMES, DES_CS_LIST); - allGood &= testEngOnlyDisabled(DES_CS_LIST_NAMES); + allGood &= test.testDefaultCase(DES_CS_LIST); + allGood &= test.testEngAddDisabled(DES_CS_LIST_NAMES, DES_CS_LIST); + allGood &= test.testEngOnlyDisabled(DES_CS_LIST_NAMES); // Disabled RC4 tests - allGood &= testDefaultCase(RC4_CS_LIST); - allGood &= testEngAddDisabled(RC4_CS_LIST_NAMES, RC4_CS_LIST); - allGood &= testEngOnlyDisabled(RC4_CS_LIST_NAMES); + allGood &= test.testDefaultCase(RC4_CS_LIST); + allGood &= test.testEngAddDisabled(RC4_CS_LIST_NAMES, RC4_CS_LIST); + allGood &= test.testEngOnlyDisabled(RC4_CS_LIST_NAMES); // Disabled 3DES tests - allGood &= testDefaultCase(DESEDE_CS_LIST); - allGood &= testEngAddDisabled(DESEDE_CS_LIST_NAMES, DESEDE_CS_LIST); - allGood &= testEngOnlyDisabled(DESEDE_CS_LIST_NAMES); + allGood &= test.testDefaultCase(DESEDE_CS_LIST); + allGood &= test.testEngAddDisabled(DESEDE_CS_LIST_NAMES, DESEDE_CS_LIST); + allGood &= test.testEngOnlyDisabled(DESEDE_CS_LIST_NAMES); if (allGood) { System.err.println("All tests passed"); @@ -122,242 +111,4 @@ public static void main(String[] args) throws Exception { throw new RuntimeException("One or more tests failed"); } } - - /** - * Create an engine with the default set of cipher suites enabled and make - * sure none of the disabled suites are present in the client hello. - * - * @param disabledSuiteIds the {@code List} of disabled cipher suite IDs - * to be checked for. - * - * @return true if the test passed (No disabled suites), false otherwise - */ - private static boolean testDefaultCase(List disabledSuiteIds) - throws Exception { - System.err.println("\nTest: Default SSLEngine suite set"); - SSLEngine ssle = makeEngine(); - if (DEBUG) { - listCiphers("Suite set upon creation", ssle); - } - SSLEngineResult clientResult; - ByteBuffer cTOs = makeClientBuf(ssle); - clientResult = ssle.wrap(CLIOUTBUF, cTOs); - if (DEBUG) { - dumpResult("ClientHello: ", clientResult); - } - cTOs.flip(); - boolean foundSuite = areSuitesPresentCH(cTOs, disabledSuiteIds); - if (foundSuite) { - System.err.println("FAIL: Found disabled suites!"); - return false; - } else { - System.err.println("PASS: No disabled suites found."); - return true; - } - } - - /** - * Create an engine and set only disabled cipher suites. - * The engine should not create the client hello message since the only - * available suites to assert in the client hello are disabled ones. - * - * @param disabledSuiteNames an array of cipher suite names that - * should be disabled cipher suites. - * - * @return true if the engine throws SSLHandshakeException during client - * hello creation, false otherwise. - */ - private static boolean testEngOnlyDisabled(String[] disabledSuiteNames) - throws Exception { - System.err.println( - "\nTest: SSLEngine configured with only disabled suites"); - try { - SSLEngine ssle = makeEngine(); - ssle.setEnabledCipherSuites(disabledSuiteNames); - if (DEBUG) { - listCiphers("Suite set upon creation", ssle); - } - SSLEngineResult clientResult; - ByteBuffer cTOs = makeClientBuf(ssle); - clientResult = ssle.wrap(CLIOUTBUF, cTOs); - if (DEBUG) { - dumpResult("ClientHello: ", clientResult); - } - cTOs.flip(); - } catch (SSLHandshakeException shse) { - System.err.println("PASS: Caught expected exception: " + shse); - return true; - } - System.err.println("FAIL: Expected SSLHandshakeException not thrown"); - return false; - } - - /** - * Create an engine and add some disabled suites to the default - * set of cipher suites. Make sure none of the disabled suites show up - * in the client hello even though they were explicitly added. - * - * @param disabledSuiteNames an array of cipher suite names that - * should be disabled cipher suites. - * @param disabledIds the {@code List} of disabled cipher suite IDs - * to be checked for. - * - * @return true if the test passed (No disabled suites), false otherwise - */ - private static boolean testEngAddDisabled(String[] disabledNames, - List disabledIds) throws Exception { - System.err.println("\nTest: SSLEngine with disabled suites added"); - SSLEngine ssle = makeEngine(); - - // Add disabled suites to the existing engine's set of enabled suites - String[] initialSuites = ssle.getEnabledCipherSuites(); - String[] plusDisSuites = Arrays.copyOf(initialSuites, - initialSuites.length + disabledNames.length); - System.arraycopy(disabledNames, 0, plusDisSuites, - initialSuites.length, disabledNames.length); - ssle.setEnabledCipherSuites(plusDisSuites); - - if (DEBUG) { - listCiphers("Suite set upon creation", ssle); - } - SSLEngineResult clientResult; - ByteBuffer cTOs = makeClientBuf(ssle); - clientResult = ssle.wrap(CLIOUTBUF, cTOs); - if (DEBUG) { - dumpResult("ClientHello: ", clientResult); - } - cTOs.flip(); - boolean foundDisabled = areSuitesPresentCH(cTOs, disabledIds); - if (foundDisabled) { - System.err.println("FAIL: Found disabled suites!"); - return false; - } else { - System.err.println("PASS: No disabled suites found."); - return true; - } - } - - private static SSLEngine makeEngine() throws GeneralSecurityException { - SSLContext ctx = SSLContext.getInstance("TLSv1.2"); - ctx.init(null, null, null); - return ctx.createSSLEngine(); - } - - private static ByteBuffer makeClientBuf(SSLEngine ssle) { - ssle.setUseClientMode(true); - ssle.setNeedClientAuth(false); - SSLSession sess = ssle.getSession(); - ByteBuffer cTOs = ByteBuffer.allocateDirect(sess.getPacketBufferSize()); - return cTOs; - } - - private static void listCiphers(String prefix, SSLEngine ssle) { - System.err.println(prefix + "\n---------------"); - String[] suites = ssle.getEnabledCipherSuites(); - for (String suite : suites) { - System.err.println(suite); - } - System.err.println("---------------"); - } - - /** - * Walk a TLS 1.2 or earlier ClientHello looking for any of the suites - * in the suiteIdList. - * - * @param clientHello a ByteBuffer containing the ClientHello message as - * a complete TLS record. The position of the buffer should be - * at the first byte of the TLS record header. - * @param suiteIdList a List of integer values corresponding to - * TLS cipher suite identifiers. - * - * @return true if at least one of the suites in {@code suiteIdList} - * is found in the ClientHello's cipher suite list - * - * @throws IOException if the data in the {@code clientHello} - * buffer is not a TLS handshake message or is not a client hello. - */ - private static boolean areSuitesPresentCH(ByteBuffer clientHello, - List suiteIdList) throws IOException { - byte val; - - // Process the TLS Record - val = clientHello.get(); - if (val != RECTYPE_HS) { - throw new IOException( - "Not a handshake record, type = " + val); - } - - // Just skip over the version and length - clientHello.position(clientHello.position() + 4); - - // Check the handshake message type - val = clientHello.get(); - if (val != HSMSG_CLIHELLO) { - throw new IOException( - "Not a ClientHello handshake message, type = " + val); - } - - // Skip over the length - clientHello.position(clientHello.position() + 3); - - // Skip over the protocol version (2) and random (32); - clientHello.position(clientHello.position() + 34); - - // Skip past the session ID (variable length <= 32) - int len = Byte.toUnsignedInt(clientHello.get()); - if (len > 32) { - throw new IOException("Session ID is too large, len = " + len); - } - clientHello.position(clientHello.position() + len); - - // Finally, we are at the cipher suites. Walk the list and place them - // into a List. - int csLen = Short.toUnsignedInt(clientHello.getShort()); - if (csLen % 2 != 0) { - throw new IOException("CipherSuite length is invalid, len = " + - csLen); - } - int csCount = csLen / 2; - List csSuiteList = new ArrayList<>(csCount); - log("Found following suite IDs in hello:"); - for (int i = 0; i < csCount; i++) { - int curSuite = Short.toUnsignedInt(clientHello.getShort()); - log(String.format("Suite ID: 0x%04x", curSuite)); - csSuiteList.add(curSuite); - } - - // Now check to see if any of the suites passed in match what is in - // the suite list. - boolean foundMatch = false; - for (Integer cs : suiteIdList) { - if (csSuiteList.contains(cs)) { - System.err.format("Found match for suite ID 0x%04x\n", cs); - foundMatch = true; - break; - } - } - - // We don't care about the rest of the ClientHello message. - // Rewind and return whether we found a match or not. - clientHello.rewind(); - return foundMatch; - } - - private static void dumpResult(String str, SSLEngineResult result) { - System.err.println("The format of the SSLEngineResult is: \n" + - "\t\"getStatus() / getHandshakeStatus()\" +\n" + - "\t\"bytesConsumed() / bytesProduced()\"\n"); - HandshakeStatus hsStatus = result.getHandshakeStatus(); - System.err.println(str + result.getStatus() + "/" + hsStatus + ", " + - result.bytesConsumed() + "/" + result.bytesProduced() + " bytes"); - if (hsStatus == HandshakeStatus.FINISHED) { - System.err.println("\t...ready for application data"); - } - } - - private static void log(String str) { - if (DEBUG) { - System.err.println(str); - } - } } diff --git a/test/jdk/sun/security/ssl/CipherSuite/TLSCipherSuiteWildCardMatchingDisablePartsOfCipherSuite.java b/test/jdk/sun/security/ssl/CipherSuite/TLSCipherSuiteWildCardMatchingDisablePartsOfCipherSuite.java new file mode 100644 index 0000000000000..57919da9a5ab8 --- /dev/null +++ b/test/jdk/sun/security/ssl/CipherSuite/TLSCipherSuiteWildCardMatchingDisablePartsOfCipherSuite.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2024, 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 8341964 + * @summary Add mechanism to disable different parts of TLS cipher suite + * @run testng/othervm TLSCipherSuiteWildCardMatchingDisablePartsOfCipherSuite + */ + +import static org.testng.AssertJUnit.assertTrue; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.security.Security; +import java.util.List; + +public class TLSCipherSuiteWildCardMatchingDisablePartsOfCipherSuite extends + AbstractDisableCipherSuites { + + private static final String SECURITY_PROPERTY = "jdk.tls.disabledAlgorithms"; + private static final String TEST_ALGORITHMS = + "TLS_RSA_*," + + " TLS_ECDH*WITH_AES_256_GCM_*," + + " TLS_*_anon_WITH_AES_*_SHA," + + " TLS_.*"; // This pattern should not disable anything + private static final String[] CIPHER_SUITES = new String[] { + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA256", + "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_DH_anon_WITH_AES_128_CBC_SHA", + "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" + }; + static final List CIPHER_SUITES_IDS = List.of( + 0x009D, + 0x009C, + 0x003D, + 0xC02E, + 0xC02C, + 0x0034, + 0xC018 + ); + + @BeforeTest + void setUp() throws Exception { + Security.setProperty(SECURITY_PROPERTY, TEST_ALGORITHMS); + } + + @Test + public void testDefault() throws Exception { + assertTrue(testDefaultCase(CIPHER_SUITES_IDS)); + } + + @Test + public void testAddDisabled() throws Exception { + assertTrue(testEngAddDisabled(CIPHER_SUITES, CIPHER_SUITES_IDS)); + } + + @Test + public void testOnlyDisabled() throws Exception { + assertTrue(testEngOnlyDisabled(CIPHER_SUITES)); + } +} diff --git a/test/jdk/sun/security/ssl/CipherSuite/TLSCipherSuiteWildCardMatchingIllegalArgument.java b/test/jdk/sun/security/ssl/CipherSuite/TLSCipherSuiteWildCardMatchingIllegalArgument.java new file mode 100644 index 0000000000000..d9894868337c6 --- /dev/null +++ b/test/jdk/sun/security/ssl/CipherSuite/TLSCipherSuiteWildCardMatchingIllegalArgument.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024, 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 8341964 + * @summary Add mechanism to disable different parts of TLS cipher suite + * @run testng/othervm TLSCipherSuiteWildCardMatchingIllegalArgument + */ + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.fail; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import java.security.Security; + +import javax.net.ssl.SSLContext; + +/** + * SSLContext loads "jdk.tls.disabledAlgorithms" system property statically + * when it's being loaded into memory, so we can't call + * Security.setProperty("jdk.tls.disabledAlgorithms") more than once per test + * class. Thus, we need a separate test class each time we need to modify + * "jdk.tls.disabledAlgorithms" config value for testing. + */ +public class TLSCipherSuiteWildCardMatchingIllegalArgument { + + private static final String SECURITY_PROPERTY = + "jdk.tls.disabledAlgorithms"; + private static final String TEST_ALGORITHMS = "ECDHE_*_WITH_AES_256_GCM_*"; + + @BeforeTest + void setUp() throws Exception { + Security.setProperty(SECURITY_PROPERTY, TEST_ALGORITHMS); + } + + @Test + public void testChainedBefore() throws Exception { + try { + SSLContext.getInstance("TLS"); + fail("No IllegalArgumentException was thrown"); + } catch (ExceptionInInitializerError e) { + assertEquals(IllegalArgumentException.class, + e.getCause().getClass()); + assertEquals("Wildcard pattern must start with \"TLS_\"", + e.getCause().getMessage()); + } + } +} diff --git a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/DirectoryContentVerifierTest.java b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/DirectoryContentVerifierTest.java index 1d2b2e3f498e9..79af67d3e9a3e 100644 --- a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/DirectoryContentVerifierTest.java +++ b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/DirectoryContentVerifierTest.java @@ -39,15 +39,6 @@ import jdk.jpackage.test.TKit.DirectoryContentVerifier; import static jdk.jpackage.test.TKit.assertAssert; -/* - * @test - * @summary Test TKit.DirectoryContentVerifier from jpackage test library - * @library /test/jdk/tools/jpackage/helpers - * @build jdk.jpackage.test.* - * @compile DirectoryContentVerifierTest.java - * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main - * --jpt-run=jdk.jpackage.test.DirectoryContentVerifierTest - */ public class DirectoryContentVerifierTest { enum AssertType { diff --git a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/JavaAppDescTest.java b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/JavaAppDescTest.java new file mode 100644 index 0000000000000..a2cde44f00951 --- /dev/null +++ b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/JavaAppDescTest.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024, 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. + */ +package jdk.jpackage.test; + +import java.nio.file.Path; +import java.util.List; +import java.util.function.UnaryOperator; +import jdk.jpackage.test.Annotations.Parameter; +import jdk.jpackage.test.Annotations.Test; +import jdk.jpackage.test.Annotations.Parameters; + +public class JavaAppDescTest { + + public JavaAppDescTest(JavaAppDesc expectedAppDesc, JavaAppDesc actualAppDesc) { + this.expectedAppDesc = expectedAppDesc; + this.actualAppDesc = actualAppDesc; + } + + @Test + public void test() { + TKit.assertEquals(expectedAppDesc.toString(), actualAppDesc.toString(), null); + TKit.assertTrue(expectedAppDesc.equals(actualAppDesc), null); + } + + @Test + @Parameter({"Foo", "Foo.class"}) + @Parameter({"com.bar.A", "com/bar/A.class"}) + @Parameter({"module/com.bar.A", "com/bar/A.class"}) + public static void testClassFilePath(String... args) { + var appDesc = args[0]; + var expectedClassFilePath = Path.of(args[1]); + TKit.assertEquals(expectedClassFilePath.toString(), JavaAppDesc.parse( + appDesc).classFilePath().toString(), null); + } + + @Parameters + public static List input() { + return List.of(new Object[][] { + createTestCase("", "hello.jar:Hello"), + createTestCase("foo.jar*", "foo.jar*hello.jar:Hello"), + createTestCase("Bye", "hello.jar:Bye"), + createTestCase("bye.jar:", "bye.jar:Hello"), + createTestCase("duke.jar:com.other/com.other.foo.bar.Buz!@3.7", appDesc -> { + return appDesc + .setBundleFileName("duke.jar") + .setModuleName("com.other") + .setClassName("com.other.foo.bar.Buz") + .setWithMainClass(true) + .setModuleVersion("3.7"); + }), + }); + } + + private static JavaAppDesc[] createTestCase(String inputAppDesc, String expectedAppDescStr) { + return createTestCase(inputAppDesc, appDesc -> { + return stripDefaultSrcJavaPath(JavaAppDesc.parse(expectedAppDescStr)); + }); + } + + private static JavaAppDesc stripDefaultSrcJavaPath(JavaAppDesc appDesc) { + var defaultAppDesc = HelloApp.createDefaltAppDesc(); + if (appDesc.srcJavaPath().equals(defaultAppDesc.srcJavaPath())) { + appDesc.setSrcJavaPath(null); + } + return appDesc; + } + + private static JavaAppDesc[] createTestCase(String appDesc, UnaryOperator config) { + var actualAppDesc = stripDefaultSrcJavaPath(JavaAppDesc.parse(appDesc)); + + var expectedAppDesc = config.apply(stripDefaultSrcJavaPath(HelloApp.createDefaltAppDesc())); + + return new JavaAppDesc[] {expectedAppDesc, actualAppDesc}; + } + + private final JavaAppDesc expectedAppDesc; + private final JavaAppDesc actualAppDesc; +} diff --git a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TKitTest.java b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TKitTest.java new file mode 100644 index 0000000000000..3f55c3c50aea9 --- /dev/null +++ b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TKitTest.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2024, 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. + */ +package jdk.jpackage.test; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; +import jdk.jpackage.test.Annotations.Parameters; +import jdk.jpackage.test.Annotations.Test; +import jdk.jpackage.test.Functional.ThrowingRunnable; +import static jdk.jpackage.test.Functional.ThrowingRunnable.toRunnable; +import static jdk.jpackage.test.Functional.ThrowingSupplier.toSupplier; + +public class TKitTest { + + @Parameters + public static Collection assertTestsData() { + List data = new ArrayList<>(); + + var assertFunc = MethodCallConfig.build("assertTrue", boolean.class, String.class); + data.addAll(List.of(assertFunc.args(true).pass().expectLog("assertTrue()").createForMessage("Catbird"))); + data.addAll(List.of(assertFunc.args(false).fail().expectLog("Failed").createForMessage("Catbird"))); + + assertFunc = MethodCallConfig.build("assertFalse", boolean.class, String.class); + data.addAll(List.of(assertFunc.args(false).pass().expectLog("assertFalse()").createForMessage("Stork"))); + data.addAll(List.of(assertFunc.args(true).fail().expectLog("Failed").createForMessage("Stork"))); + + assertFunc = MethodCallConfig.build("assertEquals", String.class, String.class, String.class); + data.addAll(List.of(assertFunc.args("a", "a").pass().expectLog("assertEquals(a)").createForMessage("Crow"))); + data.addAll(List.of(assertFunc.args("a", "b").fail().expectLog("Expected [a]. Actual [b]").createForMessage("Crow"))); + + assertFunc = MethodCallConfig.build("assertEquals", long.class, long.class, String.class); + data.addAll(List.of(assertFunc.args(7, 7).pass().expectLog("assertEquals(7)").createForMessage("Owl"))); + data.addAll(List.of(assertFunc.args(7, 10).fail().expectLog("Expected [7]. Actual [10]").createForMessage("Owl"))); + + assertFunc = MethodCallConfig.build("assertNotEquals", String.class, String.class, String.class); + data.addAll(List.of(assertFunc.args("a", "b").pass().expectLog("assertNotEquals(a, b)").createForMessage("Tit"))); + data.addAll(List.of(assertFunc.args("a", "a").fail().expectLog("Unexpected [a] value").createForMessage("Tit"))); + + assertFunc = MethodCallConfig.build("assertNotEquals", long.class, long.class, String.class); + data.addAll(List.of(assertFunc.args(7, 10).pass().expectLog("assertNotEquals(7, 10)").createForMessage("Duck"))); + data.addAll(List.of(assertFunc.args(7, 7).fail().expectLog("Unexpected [7] value").createForMessage("Duck"))); + + assertFunc = MethodCallConfig.build("assertNull", Object.class, String.class); + data.addAll(List.of(assertFunc.args((Object) null).pass().expectLog("assertNull()").createForMessage("Ibis"))); + data.addAll(List.of(assertFunc.args("v").fail().expectLog("Unexpected not null value [v]").createForMessage("Ibis"))); + + assertFunc = MethodCallConfig.build("assertNotNull", Object.class, String.class); + data.addAll(List.of(assertFunc.args("v").pass().expectLog("assertNotNull(v)").createForMessage("Pigeon"))); + data.addAll(List.of(assertFunc.args((Object) null).fail().expectLog("Unexpected null value").createForMessage("Pigeon"))); + + assertFunc = MethodCallConfig.build("assertStringListEquals", List.class, List.class, String.class); + data.addAll(List.of(assertFunc.args(List.of(), List.of()).pass().expectLog( + "assertStringListEquals()").createForMessage("Gull"))); + + data.addAll(List.of(assertFunc.args(List.of("a", "b"), List.of("a", "b")).pass().expectLog( + "assertStringListEquals()", + "assertStringListEquals(1, a)", + "assertStringListEquals(2, b)").createForMessage("Pelican"))); + + assertFunc.fail().withAutoExpectLogPrefix(false); + for (var msg : new String[] { "Raven", null }) { + data.addAll(List.of(assertFunc.args(List.of("a"), List.of("a", "b"), msg).expectLog( + concatMessages("TRACE: assertStringListEquals()", msg), + "TRACE: assertStringListEquals(1, a)", + concatMessages("ERROR: Actual list is longer than expected by 1 elements", msg) + ).create())); + + data.addAll(List.of(assertFunc.args(List.of("n", "m"), List.of("n"), msg).expectLog( + concatMessages("TRACE: assertStringListEquals()", msg), + "TRACE: assertStringListEquals(1, n)", + concatMessages("ERROR: Actual list is shorter than expected by 1 elements", msg) + ).create())); + + data.addAll(List.of(assertFunc.args(List.of("a", "b"), List.of("n", "m"), msg).expectLog( + concatMessages("TRACE: assertStringListEquals()", msg), + concatMessages("ERROR: (1) Expected [a]. Actual [n]", msg) + ).create())); + } + + return data.stream().map(v -> { + return new Object[]{v}; + }).toList(); + } + + public record MethodCallConfig(Method method, Object[] args, boolean expectFail, String[] expectLog) { + @Override + public String toString() { + return String.format("%s%s%s", method.getName(), Arrays.toString(args), expectFail ? "!" : ""); + } + + static Builder build(String name, Class ... parameterTypes) { + return new Builder(name, parameterTypes); + } + + private static class Builder { + Builder(Method method) { + Objects.requireNonNull(method); + this.method = method; + } + + Builder(String name, Class ... parameterTypes) { + method = toSupplier(() -> TKit.class.getMethod(name, parameterTypes)).get(); + } + + MethodCallConfig create() { + String[] effectiveExpectLog; + if (!withAutoExpectLogPrefix) { + effectiveExpectLog = expectLog; + } else { + var prefix = expectFail ? "ERROR: " : "TRACE: "; + effectiveExpectLog = Stream.of(expectLog).map(line -> { + return prefix + line; + }).toArray(String[]::new); + } + return new MethodCallConfig(method, args, expectFail, effectiveExpectLog); + } + + MethodCallConfig[] createForMessage(String msg) { + return Arrays.asList(msg, null).stream().map(curMsg -> { + var builder = new Builder(method); + builder.expectFail = expectFail; + builder.withAutoExpectLogPrefix = withAutoExpectLogPrefix; + builder.args = Stream.concat(Stream.of(args), Stream.of(curMsg)).toArray(); + builder.expectLog = Arrays.copyOf(expectLog, expectLog.length); + builder.expectLog[0] = concatMessages(builder.expectLog[0], curMsg); + return builder.create(); + }).toArray(MethodCallConfig[]::new); + } + + Builder fail() { + expectFail = true; + return this; + } + + Builder pass() { + expectFail = false; + return this; + } + + Builder args(Object ... v) { + args = v; + return this; + } + + Builder expectLog(String expectLogFirstStr, String ... extra) { + expectLog = Stream.concat(Stream.of(expectLogFirstStr), Stream.of(extra)).toArray(String[]::new); + return this; + } + + Builder withAutoExpectLogPrefix(boolean v) { + withAutoExpectLogPrefix = v; + return this; + } + + private final Method method; + private Object[] args = new Object[0]; + private boolean expectFail; + private String[] expectLog; + private boolean withAutoExpectLogPrefix = true; + } + } + + public TKitTest(MethodCallConfig methodCall) { + this.methodCall = methodCall; + } + + @Test + public void test() { + runAssertWithExpectedLogOutput(() -> { + methodCall.method.invoke(null, methodCall.args); + }, methodCall.expectFail, methodCall.expectLog); + } + + private static void runAssertWithExpectedLogOutput(ThrowingRunnable action, + boolean expectFail, String... expectLogStrings) { + runWithExpectedLogOutput(() -> { + TKit.assertAssert(!expectFail, toRunnable(action)); + }, expectLogStrings); + } + + private static void runWithExpectedLogOutput(ThrowingRunnable action, + String... expectLogStrings) { + final var buf = new ByteArrayOutputStream(); + try (PrintStream ps = new PrintStream(buf, true, StandardCharsets.UTF_8)) { + TKit.withExtraLogStream(action, ps); + } finally { + toRunnable(() -> { + var output = new BufferedReader(new InputStreamReader( + new ByteArrayInputStream(buf.toByteArray()), + StandardCharsets.UTF_8)).lines().map(line -> { + // Skip timestamp + return line.substring(LOG_MSG_TIMESTAMP_LENGTH); + }).toList(); + if (output.size() == 1 && expectLogStrings.length == 1) { + TKit.assertEquals(expectLogStrings[0], output.get(0), null); + } else { + TKit.assertStringListEquals(List.of(expectLogStrings), output, null); + } + }).run(); + } + } + + private static String concatMessages(String msg, String msg2) { + if (msg2 != null && !msg2.isBlank()) { + return msg + ": " + msg2; + } + return msg; + } + + private final MethodCallConfig methodCall; + + private static final int LOG_MSG_TIMESTAMP_LENGTH = "[HH:mm:ss.SSS] ".length(); +} diff --git a/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TestSuite.java b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TestSuite.java new file mode 100644 index 0000000000000..f9dda8514146d --- /dev/null +++ b/test/jdk/tools/jpackage/helpers-test/jdk/jpackage/test/TestSuite.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024, 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. + */ +package jdk.jpackage.test; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +/* + * @test + * @summary Unit tests for jpackage test library + * @library /test/jdk/tools/jpackage/helpers + * @library /test/jdk/tools/jpackage/helpers-test + * @build jdk.jpackage.test.* + * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.TestSuite + */ + +public final class TestSuite { + public static void main(String args[]) throws Throwable { + final var pkgName = TestSuite.class.getPackageName(); + final var javaSuffix = ".java"; + final var testSrcNameSuffix = "Test" + javaSuffix; + + final var unitTestDir = TKit.TEST_SRC_ROOT.resolve(Path.of("helpers-test", pkgName.split("\\."))); + + final List runTestArgs = new ArrayList<>(); + runTestArgs.addAll(List.of(args)); + + try (var javaSources = Files.list(unitTestDir)) { + runTestArgs.addAll(javaSources.filter(path -> { + return path.getFileName().toString().endsWith(testSrcNameSuffix); + }).map(path -> { + var filename = path.getFileName().toString(); + return String.join(".", pkgName, filename.substring(0, filename.length() - javaSuffix.length())); + }).map(testClassName -> { + return "--jpt-run=" + testClassName; + }).toList()); + } + + Main.main(runTestArgs.toArray(String[]::new)); + } +} diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java index 87718c1394c2d..a57caa92cb20e 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, 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 @@ -151,12 +151,16 @@ public ExceptionBox(Throwable throwable) { @SuppressWarnings("unchecked") public static RuntimeException rethrowUnchecked(Throwable throwable) throws ExceptionBox { - if (throwable instanceof RuntimeException) { - throw (RuntimeException)throwable; + if (throwable instanceof RuntimeException err) { + throw err; } - if (throwable instanceof InvocationTargetException) { - throw new ExceptionBox(throwable.getCause()); + if (throwable instanceof Error err) { + throw err; + } + + if (throwable instanceof InvocationTargetException err) { + throw rethrowUnchecked(err.getCause()); } throw new ExceptionBox(throwable); diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java index 3bd3b42d59518..bc722e7acd925 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java @@ -22,7 +22,6 @@ */ package jdk.jpackage.test; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -57,15 +56,10 @@ public final class HelloApp { private JarBuilder prepareSources(Path srcDir) throws IOException { final String srcClassName = appDesc.srcClassName(); - - final String qualifiedClassName = appDesc.className(); - - final String className = qualifiedClassName.substring( - qualifiedClassName.lastIndexOf('.') + 1); + final String className = appDesc.shortClassName(); final String packageName = appDesc.packageName(); - final Path srcFile = srcDir.resolve(Path.of(String.join( - File.separator, qualifiedClassName.split("\\.")) + ".java")); + final Path srcFile = srcDir.resolve(appDesc.classNameAsPath(".java")); Files.createDirectories(srcFile.getParent()); JarBuilder jarBuilder = createJarBuilder().addSourceFile(srcFile); @@ -351,7 +345,7 @@ public static AppOutputVerifier assertMainLauncher(JPackageCommand cmd, } - public final static class AppOutputVerifier { + public static final class AppOutputVerifier { AppOutputVerifier(Path helloAppLauncher) { this.launcherPath = helloAppLauncher; this.outputFilePath = TKit.workDir().resolve(OUTPUT_FILENAME); @@ -493,13 +487,13 @@ public static AppOutputVerifier assertApp(Path helloAppLauncher) { return new AppOutputVerifier(helloAppLauncher); } - final static String OUTPUT_FILENAME = "appOutput.txt"; + static final String OUTPUT_FILENAME = "appOutput.txt"; private final JavaAppDesc appDesc; private static final Path HELLO_JAVA = TKit.TEST_SRC_ROOT.resolve( "apps/Hello.java"); - private final static String CLASS_NAME = HELLO_JAVA.getFileName().toString().split( + private static final String CLASS_NAME = HELLO_JAVA.getFileName().toString().split( "\\.", 2)[0]; } diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java index 5b49b01a443b0..3cc2458ce2acc 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JavaAppDesc.java @@ -22,8 +22,9 @@ */ package jdk.jpackage.test; -import java.io.File; import java.nio.file.Path; +import java.util.Objects; +import java.util.stream.Stream; public final class JavaAppDesc { @@ -73,9 +74,18 @@ public String className() { return qualifiedClassName; } + public String shortClassName() { + return qualifiedClassName.substring(qualifiedClassName.lastIndexOf('.') + 1); + } + + Path classNameAsPath(String extension) { + final String[] pathComponents = qualifiedClassName.split("\\."); + pathComponents[pathComponents.length - 1] = shortClassName() + extension; + return Stream.of(pathComponents).map(Path::of).reduce(Path::resolve).get(); + } + public Path classFilePath() { - return Path.of(qualifiedClassName.replace(".", File.separator) - + ".class"); + return classNameAsPath(".class"); } public String moduleName() { @@ -124,6 +134,48 @@ public boolean isWithMainClass() { return withMainClass; } + @Override + public int hashCode() { + int hash = 5; + hash = 79 * hash + Objects.hashCode(this.srcJavaPath); + hash = 79 * hash + Objects.hashCode(this.qualifiedClassName); + hash = 79 * hash + Objects.hashCode(this.moduleName); + hash = 79 * hash + Objects.hashCode(this.bundleFileName); + hash = 79 * hash + Objects.hashCode(this.moduleVersion); + hash = 79 * hash + (this.withMainClass ? 1 : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final JavaAppDesc other = (JavaAppDesc) obj; + if (this.withMainClass != other.withMainClass) { + return false; + } + if (!Objects.equals(this.qualifiedClassName, other.qualifiedClassName)) { + return false; + } + if (!Objects.equals(this.moduleName, other.moduleName)) { + return false; + } + if (!Objects.equals(this.bundleFileName, other.bundleFileName)) { + return false; + } + if (!Objects.equals(this.moduleVersion, other.moduleVersion)) { + return false; + } + return Objects.equals(this.srcJavaPath, other.srcJavaPath); + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java index 7882d4cd92d09..6f486425e7316 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java @@ -22,9 +22,7 @@ */ package jdk.jpackage.test; -import java.awt.Desktop; import java.awt.GraphicsEnvironment; -import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -788,7 +786,7 @@ private static Map createDefaultPackageHandlers() private Map packageHandlers; private boolean ignoreBundleOutputDir; - private static final File BUNDLE_OUTPUT_DIR; + private static final Path BUNDLE_OUTPUT_DIR; static { final String propertyName = "output"; @@ -796,9 +794,9 @@ private static Map createDefaultPackageHandlers() if (val == null) { BUNDLE_OUTPUT_DIR = null; } else { - BUNDLE_OUTPUT_DIR = new File(val).getAbsoluteFile(); + BUNDLE_OUTPUT_DIR = Path.of(val).toAbsolutePath(); - if (!BUNDLE_OUTPUT_DIR.isDirectory()) { + if (!Files.isDirectory(BUNDLE_OUTPUT_DIR)) { throw new IllegalArgumentException(String.format("Invalid value of %s sytem property: [%s]. Should be existing directory", TKit.getConfigPropertyName(propertyName), BUNDLE_OUTPUT_DIR)); diff --git a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java index 02841a1a71337..28c58a4db3dd3 100644 --- a/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java +++ b/test/jdk/tools/jpackage/helpers/jdk/jpackage/test/TKit.java @@ -23,7 +23,6 @@ package jdk.jpackage.test; import java.io.Closeable; -import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; @@ -107,14 +106,21 @@ static void withExtraLogStream(ThrowingRunnable action) { ThrowingRunnable.toRunnable(action).run(); } else { try (PrintStream logStream = openLogStream()) { - extraLogStream = logStream; - ThrowingRunnable.toRunnable(action).run(); - } finally { - extraLogStream = null; + withExtraLogStream(action, logStream); } } } + static void withExtraLogStream(ThrowingRunnable action, PrintStream logStream) { + var oldExtraLogStream = extraLogStream; + try { + extraLogStream = logStream; + ThrowingRunnable.toRunnable(action).run(); + } finally { + extraLogStream = oldExtraLogStream; + } + } + static void runTests(List tests) { if (currentTest != null) { throw new IllegalStateException( @@ -187,11 +193,7 @@ public static boolean isLinux() { } public static boolean isLinuxAPT() { - if (!isLinux()) { - return false; - } - File aptFile = new File("/usr/bin/apt-get"); - return aptFile.exists(); + return isLinux() && Files.exists(Path.of("/usr/bin/apt-get")); } private static String addTimestamp(String msg) { @@ -598,7 +600,7 @@ public static void assertEquals(long expected, long actual, String msg) { msg)); } - traceAssert(String.format("assertEquals(%d): %s", expected, msg)); + traceAssert(concatMessages(String.format("assertEquals(%d)", expected), msg)); } public static void assertNotEquals(long expected, long actual, String msg) { @@ -608,8 +610,8 @@ public static void assertNotEquals(long expected, long actual, String msg) { msg)); } - traceAssert(String.format("assertNotEquals(%d, %d): %s", expected, - actual, msg)); + traceAssert(concatMessages(String.format("assertNotEquals(%d, %d)", expected, + actual), msg)); } public static void assertEquals(String expected, String actual, String msg) { @@ -621,7 +623,7 @@ public static void assertEquals(String expected, String actual, String msg) { msg)); } - traceAssert(String.format("assertEquals(%s): %s", expected, msg)); + traceAssert(concatMessages(String.format("assertEquals(%s)", expected), msg)); } public static void assertNotEquals(String expected, String actual, String msg) { @@ -629,8 +631,8 @@ public static void assertNotEquals(String expected, String actual, String msg) { if ((actual != null && !actual.equals(expected)) || (expected != null && !expected.equals(actual))) { - traceAssert(String.format("assertNotEquals(%s, %s): %s", expected, - actual, msg)); + traceAssert(concatMessages(String.format("assertNotEquals(%s, %s)", expected, + actual), msg)); return; } @@ -644,7 +646,7 @@ public static void assertNull(Object value, String msg) { value), msg)); } - traceAssert(String.format("assertNull(): %s", msg)); + traceAssert(concatMessages("assertNull()", msg)); } public static void assertNotNull(Object value, String msg) { @@ -653,7 +655,7 @@ public static void assertNotNull(Object value, String msg) { error(concatMessages("Unexpected null value", msg)); } - traceAssert(String.format("assertNotNull(%s): %s", value, msg)); + traceAssert(concatMessages(String.format("assertNotNull(%s)", value), msg)); } public static void assertTrue(boolean actual, String msg) { @@ -673,7 +675,7 @@ public static void assertTrue(boolean actual, String msg, Runnable onFail) { error(concatMessages("Failed", msg)); } - traceAssert(String.format("assertTrue(): %s", msg)); + traceAssert(concatMessages("assertTrue()", msg)); } public static void assertFalse(boolean actual, String msg, Runnable onFail) { @@ -685,7 +687,7 @@ public static void assertFalse(boolean actual, String msg, Runnable onFail) { error(concatMessages("Failed", msg)); } - traceAssert(String.format("assertFalse(): %s", msg)); + traceAssert(concatMessages("assertFalse()", msg)); } public static void assertPathExists(Path path, boolean exists) { @@ -865,7 +867,7 @@ public static void assertStringListEquals(List expected, List actual, String msg) { currentTest.notifyAssert(); - traceAssert(String.format("assertStringListEquals(): %s", msg)); + traceAssert(concatMessages("assertStringListEquals()", msg)); String idxFieldFormat = Functional.identity(() -> { int listSize = expected.size(); @@ -895,7 +897,7 @@ public static void assertStringListEquals(List expected, expectedStr)); }); - if (expected.size() < actual.size()) { + if (actual.size() > expected.size()) { // Actual string list is longer than expected error(concatMessages(String.format( "Actual list is longer than expected by %d elements", @@ -905,7 +907,7 @@ public static void assertStringListEquals(List expected, if (actual.size() < expected.size()) { // Actual string list is shorter than expected error(concatMessages(String.format( - "Actual list is longer than expected by %d elements", + "Actual list is shorter than expected by %d elements", expected.size() - actual.size()), msg)); } } diff --git a/test/jdk/tools/jpackage/share/AddLShortcutTest.java b/test/jdk/tools/jpackage/share/AddLShortcutTest.java index 92784abd5cc1d..5b55d906cf163 100644 --- a/test/jdk/tools/jpackage/share/AddLShortcutTest.java +++ b/test/jdk/tools/jpackage/share/AddLShortcutTest.java @@ -22,8 +22,6 @@ */ import java.nio.file.Path; -import java.io.File; -import java.util.Map; import java.lang.invoke.MethodHandles; import jdk.jpackage.test.PackageTest; import jdk.jpackage.test.FileAssociations; @@ -109,6 +107,6 @@ public void test() { packageTest.run(); } - private final static Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of( + private static final Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of( "resources", "icon" + TKit.ICON_SUFFIX)); } diff --git a/test/jdk/tools/jpackage/share/AddLauncherTest.java b/test/jdk/tools/jpackage/share/AddLauncherTest.java index ae774b86f3ad8..af0efc4fb86e3 100644 --- a/test/jdk/tools/jpackage/share/AddLauncherTest.java +++ b/test/jdk/tools/jpackage/share/AddLauncherTest.java @@ -22,7 +22,6 @@ */ import java.nio.file.Path; -import java.io.File; import java.util.Map; import java.lang.invoke.MethodHandles; import jdk.jpackage.test.PackageTest; @@ -229,11 +228,11 @@ public void testMainLauncherIsModular(boolean mainLauncherIsModular) { TKit.assertEquals(ExpectedCN, mainClass, String.format("Check value of app.mainclass=[%s]" + "in NonModularAppLauncher cfg file is as expected", ExpectedCN)); - TKit.assertTrue(classpath.startsWith("$APPDIR" + File.separator - + nonModularAppDesc.jarFileName()), + TKit.assertTrue(classpath.startsWith(Path.of("$APPDIR", + nonModularAppDesc.jarFileName()).toString()), "Check app.classpath value in ModularAppLauncher cfg file"); } - private final static Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of( + private static final Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of( "resources", "icon" + TKit.ICON_SUFFIX)); } diff --git a/src/java.base/share/classes/jdk/internal/access/JavaIOPrintStreamAccess.java b/test/jdk/tools/sincechecker/modules/java.instrument/JavaInstrumentCheckSince.java similarity index 69% rename from src/java.base/share/classes/jdk/internal/access/JavaIOPrintStreamAccess.java rename to test/jdk/tools/sincechecker/modules/java.instrument/JavaInstrumentCheckSince.java index ec205e27dca19..1fe03b5bdddc6 100644 --- a/src/java.base/share/classes/jdk/internal/access/JavaIOPrintStreamAccess.java +++ b/test/jdk/tools/sincechecker/modules/java.instrument/JavaInstrumentCheckSince.java @@ -1,12 +1,10 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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. + * 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 @@ -22,10 +20,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package jdk.internal.access; -import java.io.PrintStream; - -public interface JavaIOPrintStreamAccess { - Object lock(PrintStream ps); -} +/* + * @test + * @bug 8343781 + * @summary Test for `@since` in java.instrument module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker java.instrument + */ diff --git a/src/java.base/share/classes/jdk/internal/access/JavaIOPrintWriterAccess.java b/test/jdk/tools/sincechecker/modules/java.management.rmi/JavaManagementRmiCheckSince.java similarity index 69% rename from src/java.base/share/classes/jdk/internal/access/JavaIOPrintWriterAccess.java rename to test/jdk/tools/sincechecker/modules/java.management.rmi/JavaManagementRmiCheckSince.java index 8be54a76b0afb..8c6b18bb6c069 100644 --- a/src/java.base/share/classes/jdk/internal/access/JavaIOPrintWriterAccess.java +++ b/test/jdk/tools/sincechecker/modules/java.management.rmi/JavaManagementRmiCheckSince.java @@ -1,12 +1,10 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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. + * 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 @@ -22,10 +20,11 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ -package jdk.internal.access; -import java.io.PrintWriter; - -public interface JavaIOPrintWriterAccess { - Object lock(PrintWriter pw); -} +/* + * @test + * @bug 8343781 + * @summary Test for `@since` in java.management.rmi module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker java.management.rmi + */ diff --git a/test/jdk/tools/sincechecker/modules/java.management/JavaManagementCheckSince.java b/test/jdk/tools/sincechecker/modules/java.management/JavaManagementCheckSince.java new file mode 100644 index 0000000000000..65158639e2d81 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/java.management/JavaManagementCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in java.management module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker java.management + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.attach/JdkAttachCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.attach/JdkAttachCheckSince.java new file mode 100644 index 0000000000000..e4806c584b716 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.attach/JdkAttachCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.attach module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.attach + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.hotspot.agent/JdkHotspotAgentCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.hotspot.agent/JdkHotspotAgentCheckSince.java new file mode 100644 index 0000000000000..5f8b8162cd9f3 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.hotspot.agent/JdkHotspotAgentCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.hotspot.agent module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.hotspot.agent + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.jcmd/JdkJcmdCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.jcmd/JdkJcmdCheckSince.java new file mode 100644 index 0000000000000..03a872cf18493 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.jcmd/JdkJcmdCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.jcmd module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.jcmd + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.jconsole/JdkJconsoleCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.jconsole/JdkJconsoleCheckSince.java new file mode 100644 index 0000000000000..b73f9e67e4e16 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.jconsole/JdkJconsoleCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.jconsole module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.jconsole + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.jdi/JdkJdiCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.jdi/JdkJdiCheckSince.java new file mode 100644 index 0000000000000..67da45a26e2ac --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.jdi/JdkJdiCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.jdi module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.jdi + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.jdwp.agent/JdkJdwpAgentCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.jdwp.agent/JdkJdwpAgentCheckSince.java new file mode 100644 index 0000000000000..b00ac2d30c636 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.jdwp.agent/JdkJdwpAgentCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.jdwp.agent module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.jdwp.agent + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.jstatd/JdkJstatdCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.jstatd/JdkJstatdCheckSince.java new file mode 100644 index 0000000000000..b7fbfde37dda1 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.jstatd/JdkJstatdCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.jstatd module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.jstatd + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.management.agent/JdkManagementAgentCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.management.agent/JdkManagementAgentCheckSince.java new file mode 100644 index 0000000000000..a7046f66ac480 --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.management.agent/JdkManagementAgentCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.management.agent module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.management.agent + */ diff --git a/test/jdk/tools/sincechecker/modules/jdk.management/JdkManagementCheckSince.java b/test/jdk/tools/sincechecker/modules/jdk.management/JdkManagementCheckSince.java new file mode 100644 index 0000000000000..94523f59e757e --- /dev/null +++ b/test/jdk/tools/sincechecker/modules/jdk.management/JdkManagementCheckSince.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024, 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 8343781 + * @summary Test for `@since` in jdk.management module + * @library /test/lib /test/jdk/tools/sincechecker + * @run main SinceChecker jdk.management + */ diff --git a/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java b/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java index 369312d690a17..79658e4c606d3 100644 --- a/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java +++ b/test/langtools/jdk/javadoc/doclet/testPreview/TestPreview.java @@ -33,6 +33,7 @@ * @run main TestPreview */ +import java.nio.file.Path; import java.nio.file.Paths; import javadoc.tester.JavadocTester; @@ -209,4 +210,18 @@ public void test8282452() { checkOutput("java.base/preview/NoPreview.html", false, "refers to one or more preview"); } + + @Test + public void testRequiresTransitiveJavaBase() { + Path src = Paths.get(testSrc, "requiresTransitiveJavaBase"); + javadoc("-d", "out-requires-transitive-java-base", + "-XDforcePreview", "--enable-preview", "-source", System.getProperty("java.specification.version"), + "--module-source-path", src.toString(), + "--module", "m", + "--expand-requires", "transitive"); + checkExit(Exit.OK); + + checkOutput("m/module-summary.html", true, + "Indirect exports from the java.base module are"); + } } diff --git a/test/langtools/tools/javac/diags/examples/CantAccessInnerClsConstr.java b/test/langtools/jdk/javadoc/doclet/testPreview/requiresTransitiveJavaBase/m/module-info.java similarity index 74% rename from test/langtools/tools/javac/diags/examples/CantAccessInnerClsConstr.java rename to test/langtools/jdk/javadoc/doclet/testPreview/requiresTransitiveJavaBase/m/module-info.java index 112862cd2eff6..d1576ff8c3e09 100644 --- a/test/langtools/tools/javac/diags/examples/CantAccessInnerClsConstr.java +++ b/test/langtools/jdk/javadoc/doclet/testPreview/requiresTransitiveJavaBase/m/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -20,19 +20,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - -// key: compiler.misc.cant.access.inner.cls.constr -// key: compiler.err.invalid.mref - -class CantAccessInnerClsConstructor { - - interface SAM { - Outer m(); - } - - class Outer { } - - static void test() { - SAM s = Outer::new; - } +module m { + requires transitive java.base; } diff --git a/test/langtools/jdk/jshell/ConsoleTest.java b/test/langtools/jdk/jshell/ConsoleTest.java index 29961a180bab6..4aedc0619397f 100644 --- a/test/langtools/jdk/jshell/ConsoleTest.java +++ b/test/langtools/jdk/jshell/ConsoleTest.java @@ -25,6 +25,7 @@ * @test * @bug 8298425 * @summary Verify behavior of System.console() + * @enablePreview * @build KullaTesting TestingInputStream * @run testng ConsoleTest */ @@ -67,6 +68,13 @@ public String readLine(String prompt) throws IOError { } }; assertEval("System.console().readLine(\"expected\")", "\"AB\""); + console = new ThrowingJShellConsole() { + @Override + public String readLine() throws IOError { + return "AB"; + } + }; + assertEval("System.console().readLine()", "\"AB\""); console = new ThrowingJShellConsole() { @Override public char[] readPassword(String prompt) throws IOError { @@ -210,6 +218,10 @@ public String readLine(String prompt) throws IOError { return console.readLine(prompt); } @Override + public String readLine() throws IOError { + return console.readLine(); + } + @Override public char[] readPassword(String prompt) throws IOError { return console.readPassword(prompt); } @@ -240,6 +252,10 @@ public String readLine(String prompt) throws IOError { throw new IllegalStateException("Not expected!"); } @Override + public String readLine() throws IOError { + throw new IllegalStateException("Not expected!"); + } + @Override public char[] readPassword(String prompt) throws IOError { throw new IllegalStateException("Not expected!"); } diff --git a/test/langtools/tools/javac/6402516/TestClass.java b/test/langtools/tools/javac/6402516/TestClass.java index f080fbc22b43e..57131cddaf96b 100644 --- a/test/langtools/tools/javac/6402516/TestClass.java +++ b/test/langtools/tools/javac/6402516/TestClass.java @@ -26,32 +26,32 @@ class Test { void m1(int m1_arg) { - String x = "Test; 0; 0"; - String y = "Test; 0; 0"; - String z = "Test; 0; 0"; + String x = "Test; 0; 0; 0"; + String y = "Test; 0; 0; 0"; + String z = "Test; 0; 0; 0"; Object o = new Object() { public boolean equals(Object other) { - String p = "-; Test; 0; 0"; - String q = "-; Test; 0; 0"; - String r = "-; Test; 0; 0"; + String p = "-; Test; 0; 0; 0"; + String q = "-; Test; 0; 0; 0"; + String r = "-; Test; 0; 0; 0"; return (this == other); } }; } - String s = "Test; 0; 0"; + String s = "Test; 0; 0; 0"; boolean b = new Object() { public boolean equals(Object other) { - String p = "-; Test; 0; 0"; - String q = "-; Test; 0; 0"; - String r = "-; Test; 0; 0"; + String p = "-; Test; 0; 0; 0"; + String q = "-; Test; 0; 0; 0"; + String r = "-; Test; 0; 0; 0"; return (this == other); } }.equals(null); class Test2 { - String s = "Test.Test2; Test; 0; 0"; + String s = "Test.Test2; Test; 0; 0; 0"; } } diff --git a/test/langtools/tools/javac/6402516/TestLocalElements.java b/test/langtools/tools/javac/6402516/TestLocalElements.java index 589d2e993cb7c..7b835bfdcc30e 100644 --- a/test/langtools/tools/javac/6402516/TestLocalElements.java +++ b/test/langtools/tools/javac/6402516/TestLocalElements.java @@ -23,29 +23,29 @@ import java.util.List; import java.io.*; -//TOPLEVEL_SCOPE:List, Test2, Test; java.io.*, java.lang.* +//TOPLEVEL_SCOPE:List, Test2, Test; java.io.*, java.lang.*; class Test { void m1(int m1_arg) { - String x = "x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*"; - String y = "y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*"; - String z = "z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*"; + String x = "x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;"; + String y = "y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;"; + String z = "z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;"; Object o = new Object() { public boolean equals(Object other) { - String p = "p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*"; - String q = "q, p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*"; - String r = "r, q, p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*"; + String p = "p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;"; + String q = "q, p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;"; + String r = "r, q, p, other, super, this; -, o, z, y, x, m1_arg, super, this; List, Test2, Test; java.io.*, java.lang.*;"; return (this == other); } }; } - String s = "super, this; List, Test2, Test; java.io.*, java.lang.*"; + String s = "super, this; List, Test2, Test; java.io.*, java.lang.*;"; boolean b = new Object() { public boolean equals(Object other) { - String p = "p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*"; - String q = "q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*"; - String r = "r, q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*"; + String p = "p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*;"; + String q = "q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*;"; + String r = "r, q, p, other, super, this; -, super, this; List, Test2, Test; java.io.*, java.lang.*;"; return (this == other); } diff --git a/test/langtools/tools/javac/6402516/TestMethod.java b/test/langtools/tools/javac/6402516/TestMethod.java index 9aec1d5d881c8..304b0abd9cb34 100644 --- a/test/langtools/tools/javac/6402516/TestMethod.java +++ b/test/langtools/tools/javac/6402516/TestMethod.java @@ -25,32 +25,32 @@ class Test { void m1(int m1_arg) { - String x = "m1; 0; 0"; - String y = "m1; 0; 0"; - String z = "m1; 0; 0"; + String x = "m1; 0; 0; 0"; + String y = "m1; 0; 0; 0"; + String z = "m1; 0; 0; 0"; Object o = new Object() { public boolean equals(Object other) { - String p = "equals; m1; 0; 0"; - String q = "equals; m1; 0; 0"; - String r = "equals; m1; 0; 0"; + String p = "equals; m1; 0; 0; 0"; + String q = "equals; m1; 0; 0; 0"; + String r = "equals; m1; 0; 0; 0"; return (this == other); } }; } - String s = "0; 0; 0"; + String s = "0; 0; 0; 0"; boolean b = new Object() { public boolean equals(Object other) { - String p = "equals; 0; 0; 0"; - String q = "equals; 0; 0; 0"; - String r = "equals; 0; 0; 0"; + String p = "equals; 0; 0; 0; 0"; + String q = "equals; 0; 0; 0; 0"; + String r = "equals; 0; 0; 0; 0"; return (this == other); } }.equals(null); class Test2 { - String s = "0; 0; 0; 0"; + String s = "0; 0; 0; 0; 0"; } } diff --git a/test/langtools/tools/javac/ImportModule.java b/test/langtools/tools/javac/ImportModule.java index dc1ed9bd0c12d..1224a9d747071 100644 --- a/test/langtools/tools/javac/ImportModule.java +++ b/test/langtools/tools/javac/ImportModule.java @@ -218,28 +218,14 @@ public class Test { List actualErrors; List expectedErrors; - actualErrors = - new JavacTask(tb) - .options("--enable-preview", "--release", SOURCE_VERSION, - "-XDrawDiagnostics") - .outdir(classes) - .files(tb.findJavaFiles(src)) - .run(Task.Expect.FAIL) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - expectedErrors = List.of( - "Test.java:5:5: compiler.err.ref.ambiguous: Logger, kindname.interface, java.lang.System.Logger, java.lang.System, kindname.class, java.util.logging.Logger, java.util.logging", - "- compiler.note.preview.filename: Test.java, DEFAULT", - "- compiler.note.preview.recompile", - "1 error" - ); - - if (!Objects.equals(expectedErrors, actualErrors)) { - throw new AssertionError("Incorrect Output, expected: " + expectedErrors + - ", actual: " + out); - - } + new JavacTask(tb) + .options("--enable-preview", "--release", SOURCE_VERSION, + "-XDrawDiagnostics") + .outdir(classes) + .files(tb.findJavaFiles(src)) + .run(Task.Expect.SUCCESS) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); tb.writeJavaFiles(src, """ @@ -793,7 +779,7 @@ public class C {} if (!Objects.equals(expectedErrors, actualErrors)) { throw new AssertionError("Incorrect Output, expected: " + expectedErrors + - ", actual: " + out); + ", actual: " + actualErrors); } } @@ -843,4 +829,94 @@ public class Test { } } + public void testPackageImportDisambiguates(Path base) throws Exception { + Path current = base.resolve("."); + Path src = current.resolve("src"); + Path classes = current.resolve("classes"); + Path ma = src.resolve("ma"); + tb.writeJavaFiles(ma, + """ + module ma { + exports ma.p1; + } + """, + """ + package ma.p1; + public class A {} + """); + Path mb = src.resolve("mb"); + tb.writeJavaFiles(mb, + """ + module mb { + exports mb.p1; + } + """, + """ + package mb.p1; + public class A {} + """); + Path test = src.resolve("test"); + tb.writeJavaFiles(test, + """ + module test { + requires ma; + requires mb; + } + """, + """ + package test; + import module ma; + import module mb; + public class Test { + A a; + } + """); + + Files.createDirectories(classes); + + List actualErrors = new JavacTask(tb) + .options("-XDrawDiagnostics", + "--enable-preview", "--release", SOURCE_VERSION, + "--module-source-path", src.toString()) + .outdir(classes) + .files(tb.findJavaFiles(src)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + List expectedErrors = List.of( + "Test.java:5:5: compiler.err.ref.ambiguous: A, kindname.class, mb.p1.A, mb.p1, kindname.class, ma.p1.A, ma.p1", + "- compiler.note.preview.filename: Test.java, DEFAULT", + "- compiler.note.preview.recompile", + "1 error" + ); + + if (!Objects.equals(expectedErrors, actualErrors)) { + throw new AssertionError("Incorrect Output, expected: " + expectedErrors + + ", actual: " + actualErrors); + + } + + tb.writeJavaFiles(test, + """ + package test; + import module ma; + import module mb; + import mb.p1.*; + public class Test { + A a; + } + """); + + Files.createDirectories(classes); + + new JavacTask(tb) + .options("-XDrawDiagnostics", + "--enable-preview", "--release", SOURCE_VERSION, + "--module-source-path", src.toString()) + .outdir(classes) + .files(tb.findJavaFiles(src)) + .run(Task.Expect.SUCCESS) + .writeAll(); + } } diff --git a/test/langtools/tools/javac/LocalFreeVarStaticInstantiate.java b/test/langtools/tools/javac/LocalFreeVarStaticInstantiate.java new file mode 100644 index 0000000000000..39b419c694ae2 --- /dev/null +++ b/test/langtools/tools/javac/LocalFreeVarStaticInstantiate.java @@ -0,0 +1,44 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8322882 + * @summary Disallow attempts to access a free variable proxy field from a static method + * @compile/fail/ref=LocalFreeVarStaticInstantiate.out -XDrawDiagnostics LocalFreeVarStaticInstantiate.java + */ + +class LocalFreeVarStaticInstantiate { + + // local class in method + static void foo(Object there) { + class Local { + { + there.hashCode(); + } + + static { + new Local(); // can't get there from here + } + + static Runnable r = () -> { + new Local(); // can't get there from here + }; + } + } + + // local class in lambda + static Runnable foo = () -> { + Object there = ""; + class Local { + { + there.hashCode(); + } + + static { + new Local(); // can't get there from here + } + + static Runnable r = () -> { + new Local(); // can't get there from here + }; + } + }; +} diff --git a/test/langtools/tools/javac/LocalFreeVarStaticInstantiate.out b/test/langtools/tools/javac/LocalFreeVarStaticInstantiate.out new file mode 100644 index 0000000000000..50e913083b074 --- /dev/null +++ b/test/langtools/tools/javac/LocalFreeVarStaticInstantiate.out @@ -0,0 +1,5 @@ +LocalFreeVarStaticInstantiate.java:18:17: compiler.err.local.cant.be.inst.static: kindname.class, Local +LocalFreeVarStaticInstantiate.java:22:17: compiler.err.local.cant.be.inst.static: kindname.class, Local +LocalFreeVarStaticInstantiate.java:36:17: compiler.err.local.cant.be.inst.static: kindname.class, Local +LocalFreeVarStaticInstantiate.java:40:17: compiler.err.local.cant.be.inst.static: kindname.class, Local +4 errors diff --git a/test/langtools/tools/javac/QualifiedAccess/QualifiedAccess_2.java b/test/langtools/tools/javac/QualifiedAccess/QualifiedAccess_2.java index de36f070766dc..d16c8194a53b9 100644 --- a/test/langtools/tools/javac/QualifiedAccess/QualifiedAccess_2.java +++ b/test/langtools/tools/javac/QualifiedAccess/QualifiedAccess_2.java @@ -7,7 +7,7 @@ * * @compile pack1/P1.java * @compile pack1/P2.java - * @compile/fail/ref=QualifiedAccess_2.out -XDrawDiagnostics QualifiedAccess_2.java + * @compile/fail/ref=QualifiedAccess_2.out -XDdev -XDrawDiagnostics QualifiedAccess_2.java */ import pack1.P1; diff --git a/test/langtools/tools/javac/SuperInit/EarlyIndirectOuterCapture.java b/test/langtools/tools/javac/SuperInit/EarlyIndirectOuterCapture.java new file mode 100644 index 0000000000000..9336c4dc183e0 --- /dev/null +++ b/test/langtools/tools/javac/SuperInit/EarlyIndirectOuterCapture.java @@ -0,0 +1,29 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8334248 + * @summary Invalid error for early construction local class constructor method reference + * @compile/fail/ref=EarlyIndirectOuterCapture.out -XDrawDiagnostics EarlyIndirectOuterCapture.java + */ + +public class EarlyIndirectOuterCapture { + + EarlyIndirectOuterCapture() { + this(null); + } + + EarlyIndirectOuterCapture(InnerSuperclass inner) { } + + class InnerSuperclass { } + + static class InnerOuter extends EarlyIndirectOuterCapture { // accessible + class InnerInnerOuter extends EarlyIndirectOuterCapture { // not accessible + InnerInnerOuter() { + super(/* which enclosing instance here ? */new InnerSuperclass() { }); + } + + InnerInnerOuter(boolean b) { + super(InnerOuter.this.new InnerSuperclass() { }); // ok, explicit + } + } + } +} diff --git a/test/langtools/tools/javac/SuperInit/EarlyIndirectOuterCapture.out b/test/langtools/tools/javac/SuperInit/EarlyIndirectOuterCapture.out new file mode 100644 index 0000000000000..7b96671a2bd1c --- /dev/null +++ b/test/langtools/tools/javac/SuperInit/EarlyIndirectOuterCapture.out @@ -0,0 +1,2 @@ +EarlyIndirectOuterCapture.java:21:60: compiler.err.cant.ref.before.ctor.called: this +1 error diff --git a/test/langtools/tools/javac/SuperInit/EarlyLocalCtorRef.java b/test/langtools/tools/javac/SuperInit/EarlyLocalCtorRef.java new file mode 100644 index 0000000000000..3346d6ff4f7f9 --- /dev/null +++ b/test/langtools/tools/javac/SuperInit/EarlyLocalCtorRef.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024, 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 8334248 + * @summary Allow early construction local class constructor method references + * @enablePreview + */ + +import java.util.function.Supplier; + +public class EarlyLocalCtorRef { + + public EarlyLocalCtorRef() { + class InnerLocal { } + this(InnerLocal::new); + } + + public EarlyLocalCtorRef(Supplier s) { + } + + public static void main(String[] args) { + new EarlyLocalCtorRef(); + } +} diff --git a/test/langtools/tools/javac/SuperInit/EarlyLocalTest2.java b/test/langtools/tools/javac/SuperInit/EarlyLocalTest2.java new file mode 100644 index 0000000000000..ba90f06dc5e35 --- /dev/null +++ b/test/langtools/tools/javac/SuperInit/EarlyLocalTest2.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, 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 8333313 + * @summary Verify references to local classes declared in early construction contexts + * @enablePreview + */ +public class EarlyLocalTest2 { + + class Test { + Test() { + class InnerLocal { } + Runnable r = () -> new InnerLocal() { }; + r.run(); + super(); + } + } + + public static void main(String[] args) { + new EarlyLocalTest2().new Test(); + } +} diff --git a/test/langtools/tools/javac/SuperInit/EarlyLocalTest3.java b/test/langtools/tools/javac/SuperInit/EarlyLocalTest3.java new file mode 100644 index 0000000000000..bf8d6faa09983 --- /dev/null +++ b/test/langtools/tools/javac/SuperInit/EarlyLocalTest3.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024, 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 8333313 + * @summary Verify references to local classes declared in early construction contexts + * @enablePreview + */ +public class EarlyLocalTest3 { + + class Test { + Test() { + class InnerLocal { } + Runnable r = InnerLocal::new; + r.run(); + super(); + } + } + + public static void main(String[] args) { + new EarlyLocalTest3().new Test(); + } +} diff --git a/test/jdk/javax/print/PrintSE/PrintSE.java b/test/langtools/tools/javac/SuperInit/EarlyLocalTest8.java similarity index 50% rename from test/jdk/javax/print/PrintSE/PrintSE.java rename to test/langtools/tools/javac/SuperInit/EarlyLocalTest8.java index df4b2b4ff14f8..806903e901700 100644 --- a/test/jdk/javax/print/PrintSE/PrintSE.java +++ b/test/langtools/tools/javac/SuperInit/EarlyLocalTest8.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 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 @@ -20,33 +20,30 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ +/* + * @test + * @bug 8333313 + * @summary Verify references to local classes declared in early construction contexts + * @enablePreview + */ +import java.util.concurrent.atomic.AtomicReference; -import java.awt.*; -import java.awt.print.*; -import javax.print.*; -import javax.print.attribute.*; - -public class PrintSE implements Printable { - - public static void main(String[] args) throws Exception { - GraphicsEnvironment.getLocalGraphicsEnvironment(); +public class EarlyLocalTest8 { - PrintService service = PrintServiceLookup.lookupDefaultPrintService(); - if (service == null) { - System.out.println("No print service found."); - return; + class Test extends AtomicReference { + Test(int x) { + super( + switch (x) { + case 0 -> null; + default -> { + class InnerLocal { } + yield () -> new InnerLocal() { { System.out.println(EarlyLocalTest8.this); } }; + } + }); } - SimpleDoc doc = - new SimpleDoc(new PrintSE(), - DocFlavor.SERVICE_FORMATTED.PRINTABLE, - new HashDocAttributeSet()); - DocPrintJob job = service.createPrintJob(); - job.print(doc, new HashPrintRequestAttributeSet()); } - public int print(Graphics g, PageFormat pf, int pg) { - if (pg > 0) return NO_SUCH_PAGE; - g.drawString("Test passes.", 100, 100); - return PAGE_EXISTS; - } + public static void main(String[] args) { + new EarlyLocalTest8().new Test(42); + } } diff --git a/test/langtools/tools/javac/api/TestGetScopeResult.java b/test/langtools/tools/javac/api/TestGetScopeResult.java index 8b53ba0a752c6..daa3e761b2a46 100644 --- a/test/langtools/tools/javac/api/TestGetScopeResult.java +++ b/test/langtools/tools/javac/api/TestGetScopeResult.java @@ -73,6 +73,9 @@ import com.sun.tools.javac.tree.JCTree.JCStatement; import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Context.Factory; +import javax.lang.model.element.TypeElement; +import javax.lang.model.util.ElementFilter; +import javax.tools.JavaFileObject; import static javax.tools.JavaFileObject.Kind.SOURCE; @@ -89,6 +92,7 @@ public static void main(String... args) throws IOException { new TestGetScopeResult().testLocalRecordAnnotation(); new TestGetScopeResult().testRuleCases(); new TestGetScopeResult().testNestedSwitchExpression(); + new TestGetScopeResult().testModuleImportScope(); } public void run() throws IOException { @@ -823,6 +827,64 @@ JCTree getCaseBody(Scope scope) { } } + void testModuleImportScope() throws IOException { + JavacTool c = JavacTool.create(); + try (StandardJavaFileManager fm = c.getStandardFileManager(null, null, null)) { + String code = """ + import module java.compiler; + import java.util.*; + import java.lang.System; + class Test { + } + """; + Context ctx = new Context(); + TestAnalyzer.preRegister(ctx); + JavaFileObject input = + SimpleJavaFileObject.forSource(URI.create("myfo:///Test.java"), code); + JavacTask t = (JavacTask) c.getTask(null, fm, null, null, null, + List.of(input), + ctx); + CompilationUnitTree cut = t.parse().iterator().next(); + t.analyze(); + + TreePath topLevelClass = new TreePath(new TreePath(cut), cut.getTypeDecls().get(0)); + Scope scope = Trees.instance(t).getScope(topLevelClass); + + if (scope.getEnclosingClass() == null) { + throw new AssertionError("Expected an enclosing class."); + } + + scope = scope.getEnclosingScope(); + + if (scope.getEnclosingClass() != null) { + throw new AssertionError("Did not expect an enclosing class."); + } + + asssertScopeContainsTypeWithFQN(scope, "java.lang.System"); + asssertScopeContainsTypeWithFQN(scope, "Test"); + + scope = scope.getEnclosingScope(); + + if (scope.getEnclosingClass() != null) { + throw new AssertionError("Did not expect an enclosing class."); + } + + asssertScopeContainsTypeWithFQN(scope, "java.util.List"); + + scope = scope.getEnclosingScope(); + + if (scope.getEnclosingClass() != null) { + throw new AssertionError("Did not expect an enclosing class."); + } + + asssertScopeContainsTypeWithFQN(scope, "javax.tools.ToolProvider"); + + if (scope.getEnclosingScope() != null) { + throw new AssertionError("Did not expect an enclosing scope."); + } + } + } + private List dumpScope(Scope scope) { List content = new ArrayList<>(); while (scope.getEnclosingClass() != null) { @@ -833,4 +895,17 @@ private List dumpScope(Scope scope) { } return content; } + + private void asssertScopeContainsTypeWithFQN(Scope scope, String fqn) { + for (TypeElement type : ElementFilter.typesIn(scope.getLocalElements())) { + if (type.getQualifiedName().contentEquals(fqn)) { + return ; + } + } + + throw new AssertionError("Expected to find: " + fqn + + " in: " + scope.getLocalElements() + + ", but it is missing."); + } + } diff --git a/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java b/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java index d9a3320ecc231..2911e58820f1c 100644 --- a/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/AnnotationDefault/AnnotationDefaultTest.java @@ -88,7 +88,7 @@ private void test(String template, Map replacements, boolean has checkEquals(countNumberOfAttributes(method.attributes()), 1L, "Number of AnnotationDefault attribute"); - checkEquals(attr.attributeName(), + checkEquals(attr.attributeName().stringValue(), "AnnotationDefault", "attribute_name_index"); ExpectedValues expectedValue = expectedValues.get(methodName); diff --git a/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java b/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java index f15771840f59a..924916f5cbdf9 100644 --- a/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/EnclosingMethod/EnclosingMethodTest.java @@ -169,7 +169,7 @@ private void testEnclosingMethodAttribute() { // stop checking, attr is null. test case failed return; } - checkEquals(attr.attributeName(), + checkEquals(attr.attributeName().stringValue(), "EnclosingMethod", "attribute_name_index of EnclosingMethod attribute in the class : " + className); checkEquals(((BoundAttribute)attr).payloadLen(), 4, diff --git a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java index be4a5aaea91e0..531d5e617d066 100644 --- a/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/LineNumberTable/LineNumberTestBase.java @@ -138,7 +138,7 @@ private void verifyCoveredLines(Set actualCoveredLines, TestCase.Method private > int countAttributes(AttributeMapper attr, AttributedElement attributedElement) { int i = 0; for (Attribute attribute : attributedElement.attributes()) { - if (attribute.attributeName().equals(attr.name())) { + if (attribute.attributeName().equalsString(attr.name())) { i++; } } diff --git a/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java b/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java index 72f7d2a6b9b6b..7b75ffa5f9cc2 100644 --- a/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java +++ b/test/langtools/tools/javac/classfiles/attributes/Signature/Driver.java @@ -219,7 +219,7 @@ private void testAttribute( SignatureAttribute attribute = sup.get(); if (expectedSignature != null && checkNotNull(attribute, memberName + " must have attribute")) { - checkEquals(attribute.attributeName(), + checkEquals(attribute.attributeName().stringValue(), "Signature", "Attribute's name : " + memberName); checkEquals(((BoundAttribute)attribute).payloadLen(), 2, "Attribute's length : " + memberName); checkEquals(attribute.signature().stringValue(), diff --git a/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java b/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java index 52d53f9dce4e3..0d81fc2c2829e 100644 --- a/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/SourceFile/SourceFileTestBase.java @@ -108,7 +108,7 @@ private void assertAttributePresent(ClassModel classFile, String fileName) throw SourceFileAttribute attribute = sourceFileAttributes.get(0); - assertEquals(attribute.attributeName(), Attributes.sourceFile().name(), "Incorrect attribute name"); + assertEquals(attribute.attributeName().stringValue(), Attributes.sourceFile().name(), "Incorrect attribute name"); assertEquals(attribute.sourceFile().stringValue(), fileName, "Incorrect source file name"); assertEquals(((BoundAttribute)attribute).payloadLen(), 2, "Incorrect attribute length"); diff --git a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java index 425760ea137c6..6467f3d8027c9 100644 --- a/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java +++ b/test/langtools/tools/javac/classfiles/attributes/deprecated/DeprecatedTest.java @@ -302,7 +302,7 @@ private void testDeprecatedAttribute(String name, DeprecatedAttribute attr, Clas if (checkNotNull(attr, name + " must have deprecated attribute")) { checkEquals(0, ((BoundAttribute)attr).payloadLen(), "attribute_length should equal to 0"); - checkEquals("Deprecated", attr.attributeName(), + checkEquals("Deprecated", attr.attributeName().stringValue(), name + " attribute_name_index"); } } diff --git a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java index 26972de3544ea..aa46d8a9b9d56 100644 --- a/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java +++ b/test/langtools/tools/javac/classfiles/attributes/innerclasses/InnerClassesTestBase.java @@ -206,7 +206,7 @@ private void test(String classToTest, TestCase test, String...skipClasses) { if (!checkNotNull(innerClasses, "InnerClasses attribute should not be null")) { return; } - checkEquals(innerClasses.attributeName(), "InnerClasses", + checkEquals(innerClasses.attributeName().stringValue(), "InnerClasses", "innerClasses.attribute_name_index"); // Inner Classes attribute consists of length (2 bytes) // and 8 bytes for each inner class's entry. diff --git a/test/langtools/tools/javac/danglingDocComments/JBangException1.java b/test/langtools/tools/javac/danglingDocComments/JBangException1.java new file mode 100644 index 0000000000000..123451aff7c22 --- /dev/null +++ b/test/langtools/tools/javac/danglingDocComments/JBangException1.java @@ -0,0 +1,19 @@ +///usr/bin/env jbang "$0" "$@" ; exit $? +// /nodynamiccopyright/ + +/** A class comment */ +public class JBangException1 { + + /** + * A method comment + * + * @param args a parameter comment + */ + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Hello World!"); + } else { + System.out.println("Hello " + args[0]); + } + } +} \ No newline at end of file diff --git a/test/langtools/tools/javac/danglingDocComments/JBangException2.enabled.out b/test/langtools/tools/javac/danglingDocComments/JBangException2.enabled.out new file mode 100644 index 0000000000000..8934c449e3b46 --- /dev/null +++ b/test/langtools/tools/javac/danglingDocComments/JBangException2.enabled.out @@ -0,0 +1,2 @@ +JBangException2.java:1:1: compiler.warn.dangling.doc.comment +1 warning diff --git a/test/langtools/tools/javac/danglingDocComments/JBangException2.java b/test/langtools/tools/javac/danglingDocComments/JBangException2.java new file mode 100644 index 0000000000000..1514542f3fc2b --- /dev/null +++ b/test/langtools/tools/javac/danglingDocComments/JBangException2.java @@ -0,0 +1,19 @@ +/** /usr/bin/env jbang "$0" "$@" ; exit $? */ +// /nodynamiccopyright/ + +/** A class comment */ +public class JBangException2 { + + /** + * A method comment + * + * @param args a parameter comment + */ + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Hello World!"); + } else { + System.out.println("Hello " + args[0]); + } + } +} \ No newline at end of file diff --git a/test/langtools/tools/javac/danglingDocComments/JBangException3.enabled.out b/test/langtools/tools/javac/danglingDocComments/JBangException3.enabled.out new file mode 100644 index 0000000000000..9b08300a7c007 --- /dev/null +++ b/test/langtools/tools/javac/danglingDocComments/JBangException3.enabled.out @@ -0,0 +1,2 @@ +JBangException3.java:1:1: compiler.warn.dangling.doc.comment +1 warning diff --git a/test/langtools/tools/javac/danglingDocComments/JBangException3.java b/test/langtools/tools/javac/danglingDocComments/JBangException3.java new file mode 100644 index 0000000000000..9e14dfc0b553e --- /dev/null +++ b/test/langtools/tools/javac/danglingDocComments/JBangException3.java @@ -0,0 +1,22 @@ +/// A +/// multiline +/// dangling +/// comment +// /nodynamiccopyright/ + +/** A class comment */ +public class JBangException3 { + + /** + * A method comment + * + * @param args a parameter comment + */ + public static void main(String[] args) { + if (args.length == 0) { + System.out.println("Hello World!"); + } else { + System.out.println("Hello " + args[0]); + } + } +} \ No newline at end of file diff --git a/test/langtools/tools/javac/danglingDocComments/JBangExceptionTest.java b/test/langtools/tools/javac/danglingDocComments/JBangExceptionTest.java new file mode 100644 index 0000000000000..4308335f4c56d --- /dev/null +++ b/test/langtools/tools/javac/danglingDocComments/JBangExceptionTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024, 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 + * + * @compile/ref=empty.out -XDrawDiagnostics JBangException1.java + * @compile/ref=empty.out -XDrawDiagnostics -Xlint:dangling-doc-comments JBangException1.java + * + * @compile/ref=empty.out -XDrawDiagnostics JBangException2.java + * @compile/ref=JBangException2.enabled.out -XDrawDiagnostics -Xlint:dangling-doc-comments JBangException2.java + * + * @compile/ref=empty.out -XDrawDiagnostics JBangException3.java + * @compile/ref=JBangException3.enabled.out -XDrawDiagnostics -Xlint:dangling-doc-comments JBangException3.java + */ + +// The classes being tested reside in files separate from this one because +// the classes need to provide the initial dangling comment, which would +// otherwise interfere with the JTReg test comment. For similar reasons, +// the files with test classes do __NOT__ have a copyright header. diff --git a/test/langtools/tools/javac/diags/examples/LocalClassCantBeInstStatic.java b/test/langtools/tools/javac/diags/examples/LocalClassCantBeInstStatic.java new file mode 100644 index 0000000000000..80301cbbb77bc --- /dev/null +++ b/test/langtools/tools/javac/diags/examples/LocalClassCantBeInstStatic.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, 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.local.cant.be.inst.static + +class LocalClassCantBeInstStatic { + static void foo(Object there) { + class Local { + { + there.hashCode(); + } + + static { + new Local(); // can't get there from here + } + } + } +} diff --git a/test/langtools/tools/javac/diags/examples/ModifierNotAllowed/module-info.java b/test/langtools/tools/javac/diags/examples/ModifierNotAllowed/module-info.java index 44bcfae8d44c6..f2e5899a91566 100644 --- a/test/langtools/tools/javac/diags/examples/ModifierNotAllowed/module-info.java +++ b/test/langtools/tools/javac/diags/examples/ModifierNotAllowed/module-info.java @@ -21,7 +21,8 @@ * questions. */ -// key: compiler.err.modifier.not.allowed.here +// key: compiler.err.feature.not.supported.in.source.plural +// key: compiler.misc.feature.java.base.transitive module m { requires transitive java.base; diff --git a/test/langtools/tools/javac/lambda/MethodReference23.out b/test/langtools/tools/javac/lambda/MethodReference23.out index 456a002bd99af..6f7e1c5c90975 100644 --- a/test/langtools/tools/javac/lambda/MethodReference23.out +++ b/test/langtools/tools/javac/lambda/MethodReference23.out @@ -1,6 +1,6 @@ -MethodReference23.java:52:19: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23) -MethodReference23.java:53:16: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, MethodReference23, MethodReference23) -MethodReference23.java:57:19: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23) -MethodReference23.java:58:16: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner1, , MethodReference23) +MethodReference23.java:52:19: compiler.err.non-static.cant.be.ref: kindname.variable, this +MethodReference23.java:53:16: compiler.err.non-static.cant.be.ref: kindname.variable, this +MethodReference23.java:57:19: compiler.err.non-static.cant.be.ref: kindname.variable, this +MethodReference23.java:58:16: compiler.err.non-static.cant.be.ref: kindname.variable, this MethodReference23.java:72:9: compiler.err.ref.ambiguous: call3, kindname.method, call3(MethodReference23.SAM21), MethodReference23, kindname.method, call3(MethodReference23.SAM22), MethodReference23 5 errors diff --git a/test/langtools/tools/javac/lambda/MethodReference37.out b/test/langtools/tools/javac/lambda/MethodReference37.out index 8db8e456daf16..09dc966bd4a3f 100644 --- a/test/langtools/tools/javac/lambda/MethodReference37.out +++ b/test/langtools/tools/javac/lambda/MethodReference37.out @@ -1,5 +1,5 @@ MethodReference37.java:24:38: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Inner, compiler.misc.no.args, MethodReference37.Outer, kindname.class, MethodReference37.Outer.Inner, (compiler.misc.arg.length.mismatch))) MethodReference37.java:29:39: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Inner, compiler.misc.no.args, MethodReference37.Outer, kindname.class, MethodReference37.Outer.Inner, (compiler.misc.arg.length.mismatch))) -MethodReference37.java:34:40: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner, MethodReference37.Outer, MethodReference37.Outer) -MethodReference37.java:38:41: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: Inner, MethodReference37.Outer, MethodReference37.Outer) +MethodReference37.java:34:40: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Inner, compiler.misc.no.args, MethodReference37.Outer, kindname.class, MethodReference37.Outer.Inner, (compiler.misc.arg.length.mismatch))) +MethodReference37.java:38:41: compiler.err.prob.found.req: (compiler.misc.invalid.mref: kindname.constructor, (compiler.misc.cant.apply.symbol: kindname.constructor, Inner, compiler.misc.no.args, MethodReference37.Outer, kindname.class, MethodReference37.Outer.Inner, (compiler.misc.arg.length.mismatch))) 4 errors diff --git a/test/langtools/tools/javac/lambda/MethodReferenceNoThisTest.out b/test/langtools/tools/javac/lambda/MethodReferenceNoThisTest.out index 2dff751f68d02..a411c34048478 100644 --- a/test/langtools/tools/javac/lambda/MethodReferenceNoThisTest.out +++ b/test/langtools/tools/javac/lambda/MethodReferenceNoThisTest.out @@ -1,2 +1,2 @@ MethodReferenceNoThisTest.java:22:15: compiler.err.cant.ref.before.ctor.called: this -1 error \ No newline at end of file +1 error diff --git a/test/langtools/tools/javac/lambda/methodReference/MethodRefToInnerWithoutOuter.out b/test/langtools/tools/javac/lambda/methodReference/MethodRefToInnerWithoutOuter.out index 03b3d33836905..66c50ed315bb3 100644 --- a/test/langtools/tools/javac/lambda/methodReference/MethodRefToInnerWithoutOuter.out +++ b/test/langtools/tools/javac/lambda/methodReference/MethodRefToInnerWithoutOuter.out @@ -1,2 +1,2 @@ -MethodRefToInnerWithoutOuter.java:22:31: compiler.err.invalid.mref: kindname.constructor, (compiler.misc.cant.access.inner.cls.constr: TestString, java.lang.String, MethodRefToInnerBase) +MethodRefToInnerWithoutOuter.java:22:31: compiler.err.non-static.cant.be.ref: kindname.variable, this 1 error diff --git a/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java b/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java index 24c2b04580083..f558ddb20ac84 100644 --- a/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java +++ b/test/langtools/tools/javac/modules/ConvenientAccessErrorsTest.java @@ -432,6 +432,40 @@ public void testInImportOnDemand(Path base) throws Exception { throw new Exception("expected output not found; actual: " + log); } + @Test + public void testInModuleImport(Path base) throws Exception { + Path src = base.resolve("src"); + Path src_m1 = src.resolve("m1x"); + tb.writeJavaFiles(src_m1, + "module m1x { }", + "package api; public class Api { public String test() { return null; } }"); + Path src_m2 = src.resolve("m2x"); + tb.writeJavaFiles(src_m2, + "module m2x { requires m1x; }", + "package test; import module m1x; public class Test { Api api; { api.test().length(); } }"); + Path classes = base.resolve("classes"); + tb.createDirectories(classes); + + List log = new JavacTask(tb) + .options("-XDrawDiagnostics", + "--enable-preview", "--source", System.getProperty("java.specification.version"), + "--module-source-path", src.toString()) + .outdir(classes) + .files(findJavaFiles(src)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + List expected = Arrays.asList( + "Test.java:1:54: compiler.err.cant.resolve.location: kindname.class, Api, , , (compiler.misc.location: kindname.class, test.Test, null)", + "- compiler.note.preview.filename: Test.java, DEFAULT", + "- compiler.note.preview.recompile", + "1 error"); + + if (!expected.equals(log)) + throw new Exception("expected output not found; actual: " + log); + } + @Test public void testUnusedImportOnDemand2(Path base) throws Exception { Path src = base.resolve("src"); diff --git a/test/langtools/tools/javac/modules/EdgeCases.java b/test/langtools/tools/javac/modules/EdgeCases.java index 0dc5d02ce4a88..dd68a5142b222 100644 --- a/test/langtools/tools/javac/modules/EdgeCases.java +++ b/test/langtools/tools/javac/modules/EdgeCases.java @@ -73,6 +73,9 @@ import com.sun.tools.javac.code.Symbol.ModuleSymbol; import com.sun.tools.javac.code.Symtab; import java.util.ArrayList; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import javax.lang.model.element.ModuleElement.DirectiveKind; import toolbox.JarTask; import toolbox.JavacTask; @@ -1153,4 +1156,90 @@ private void record(TaskEvent e, String phase) { } } + @Test + public void testJavaSEHasRequiresTransitiveJavaBase(Path base) throws Exception { + Path src = base.resolve("src"); + Path a = src.resolve("a"); + tb.writeJavaFiles(a, + "module a { requires java.se; }", + """ + package test; + import module java.se; + public class Test { + ArrayList l; + } + """); + Path classes = base.resolve("classes"); + tb.createDirectories(classes); + + AtomicBoolean seenJavaSEDependency = new AtomicBoolean(); + + List log; + + log = new JavacTask(tb) + .outdir(classes) + .options("-XDrawDiagnostics", "-XDshould-stop.at=FLOW") + .callback(verifyJavaSEDependency(true, seenJavaSEDependency)) + .files(findJavaFiles(src)) + .run(Task.Expect.FAIL) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + List expected = List.of( + "Test.java:2:8: compiler.err.preview.feature.disabled.plural: (compiler.misc.feature.module.imports)", + "1 error"); + + if (!expected.equals(log)) + throw new Exception("expected output not found: " + log); + + if (!seenJavaSEDependency.get()) { + throw new AssertionError("Didn't find the java.se dependency!"); + } + + seenJavaSEDependency.set(false); + + new JavacTask(tb) + .outdir(classes) + .options("--enable-preview", + "--source", System.getProperty("java.specification.version")) + .callback(verifyJavaSEDependency(true, seenJavaSEDependency)) + .files(findJavaFiles(src)) + .run(Task.Expect.SUCCESS) + .writeAll() + .getOutputLines(Task.OutputKind.DIRECT); + + if (!seenJavaSEDependency.get()) { + throw new AssertionError("Didn't find the java.se dependency!"); + } + } + private Consumer verifyJavaSEDependency( + boolean expectedTransitive, + AtomicBoolean seenJavaSEDependency) { + return t -> { + t.addTaskListener(new TaskListener() { + @Override + public void finished(TaskEvent e) { + if (e.getKind() == TaskEvent.Kind.ANALYZE) { + ModuleElement javaBase = + t.getElements().getModuleElement("java.base"); + ModuleElement javaSE = + t.getElements().getModuleElement("java.se"); + RequiresDirective requiresJavaBase = + javaSE.getDirectives() + .stream() + .filter(d -> d.getKind() == DirectiveKind.REQUIRES) + .map(d -> (RequiresDirective) d) + .filter(d -> d.getDependency() == javaBase) + .findAny() + .orElseThrow(); + if (requiresJavaBase.isTransitive() != expectedTransitive) { + throw new AssertionError("Expected: " + expectedTransitive + ", " + + "but got: " + requiresJavaBase.isTransitive()); + } + seenJavaSEDependency.set(true); + } + } + }); + }; + } } diff --git a/test/langtools/tools/javac/modules/JavaBaseTest.java b/test/langtools/tools/javac/modules/JavaBaseTest.java index 6d9f574705d0d..484225fcd0c1f 100644 --- a/test/langtools/tools/javac/modules/JavaBaseTest.java +++ b/test/langtools/tools/javac/modules/JavaBaseTest.java @@ -23,7 +23,7 @@ /** * @test - * @bug 8193125 8196623 + * @bug 8193125 8196623 8335989 * @summary test modifiers with java.base * @library /tools/lib * @enablePreview @@ -49,6 +49,7 @@ import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.platform.JDKPlatformProvider; +import java.util.function.Supplier; import toolbox.JavacTask; import toolbox.Task; @@ -56,6 +57,8 @@ public class JavaBaseTest { + private static final String CURRENT_VERSION = System.getProperty("java.specification.version"); + public static void main(String... args) throws Exception { JavaBaseTest t = new JavaBaseTest(); t.run(); @@ -75,13 +78,11 @@ enum Mode { SOURCE, CLASS }; void run() throws Exception { Set targets = new LinkedHashSet<>(); - StreamSupport.stream(new JDKPlatformProvider().getSupportedPlatformNames() - .spliterator(), - false) - .filter(p -> Integer.parseInt(p) >= 9) - .forEach(targets::add); - //run without --release: + targets.add("9"); + targets.add("10"); + targets.add("21"); targets.add("current"); + targets.add("current-preview"); for (List mods : modifiers) { for (String target : targets) { for (Mode mode : Mode.values()) { @@ -119,15 +120,43 @@ void testSource(Path base, List mods, String target) throws Exception { tb.writeJavaFiles(src, "module m { requires " + String.join(" ", mods) + " java.base; }"); Path modules = Files.createDirectories(base.resolve("modules")); - boolean expectOK = target.equals("9"); + boolean expectOK; JavacTask jct = new JavacTask(tb) .outdir(modules); - if (target.equals("current")) - jct.options("-XDrawDiagnostics"); - else - jct.options("-XDrawDiagnostics", "--release", target); + List options = new ArrayList<>(); + + switch (target) { + case "current": + options.add("--release"); + options.add(CURRENT_VERSION); + expectOK = false; + break; + case "current-preview": + options.add("--enable-preview"); + options.add("--release"); + options.add(CURRENT_VERSION); + expectOK = true; + break; + case "9": + options.add("--release"); + options.add(target); + expectOK = true; + break; + default: + options.add("--release"); + options.add(target); + expectOK = false; + break; + } + + if (mods.contains("static") && !"9".equals(target)) { + expectOK = false; + } + + options.add("-XDrawDiagnostics"); + jct.options(options); String log = jct.files(tb.findJavaFiles(src)) .run(expectOK ? Task.Expect.SUCCESS : Task.Expect.FAIL) @@ -138,9 +167,9 @@ void testSource(Path base, List mods, String target) throws Exception { boolean foundErrorMessage = false; for (String mod : mods) { String key = mod.equals("static") - ? "compiler.err.mod.not.allowed.here" - : "compiler.err.modifier.not.allowed.here"; - String message = "module-info.java:1:12: " + key + ": " + mod; + ? "compiler.err.mod.not.allowed.here: " + mod + : "compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.java.base.transitive)"; + String message = "module-info.java:1:12: " + key; if (log.contains(message)) { foundErrorMessage = true; } @@ -152,18 +181,57 @@ void testSource(Path base, List mods, String target) throws Exception { } void testClass(Path base, List mods, String target) throws Exception { - createClass(base, mods, target); + boolean expectOK; + List options = new ArrayList<>(); + + switch (target) { + case "current": + options.add("--release"); + options.add(CURRENT_VERSION); + expectOK = false; + break; + case "current-preview": + options.add("--enable-preview"); + options.add("--release"); + options.add(CURRENT_VERSION); + expectOK = true; + break; + case "9": + options.add("--release"); + options.add(target); + expectOK = true; + break; + default: + options.add("--release"); + options.add(target); + expectOK = false; + break; + } + + if (mods.contains("static") && !"9".equals(target)) { + expectOK = false; + } + + createClass(base, mods, options); + + List testOptions = new ArrayList<>(); + + testOptions.add("-XDrawDiagnostics"); + testOptions.add("--module-path"); testOptions.add(base.resolve("test-modules").toString()); + + if (options.contains("--enable-preview")) { + testOptions.add("--enable-preview"); + testOptions.add("--source"); testOptions.add(CURRENT_VERSION); + } Path src = base.resolve("src"); tb.writeJavaFiles(src, "module mx { requires m; }"); Path modules = Files.createDirectories(base.resolve("modules")); - boolean expectOK = target.equals("9"); String log = new JavacTask(tb) .outdir(modules) - .options("-XDrawDiagnostics", - "--module-path", base.resolve("test-modules").toString()) + .options(testOptions) .files(tb.findJavaFiles(src)) .run(expectOK ? Task.Expect.SUCCESS : Task.Expect.FAIL) .writeAll() @@ -188,7 +256,7 @@ void testClass(Path base, List mods, String target) throws Exception { } } - void createClass(Path base, List mods, String target) throws Exception { + void createClass(Path base, List mods, List options) throws Exception { Path src1 = base.resolve("interim-src"); tb.writeJavaFiles(src1, "module m { requires java.base; }"); @@ -197,9 +265,7 @@ void createClass(Path base, List mods, String target) throws Exception { JavacTask jct = new JavacTask(tb) .outdir(modules1); - if (!target.equals("current")) { - jct.options("--release", target); - } + jct.options(options); jct.files(tb.findJavaFiles(src1)) .run(Task.Expect.SUCCESS); @@ -226,6 +292,8 @@ void createClass(Path base, List mods, String target) throws Exception { requires.set(i, e2); } + boolean preview = options.contains("--enable-preview"); + ModuleAttribute modAttr2 = ModuleAttribute.of( modAttr1.moduleName(), modAttr1.moduleFlagsMask(), @@ -237,8 +305,14 @@ void createClass(Path base, List mods, String target) throws Exception { modAttr1.provides()); Path modInfo = base.resolve("test-modules").resolve("module-info.class"); Files.createDirectories(modInfo.getParent()); - byte[] newBytes = ClassFile.of().transformClass(cm1, ClassTransform.dropping(ce -> ce instanceof ModuleAttribute). - andThen(ClassTransform.endHandler(classBuilder -> classBuilder.with(modAttr2)))); + ClassTransform replace = (builder, element) -> { + switch (element) { + case ClassFileVersion cfv when preview -> builder.withVersion(cfv.majorVersion(), 0xFFFF); + case ModuleAttribute _ -> builder.with(modAttr2); + default -> builder.with(element); + } + }; + byte[] newBytes = ClassFile.of().transformClass(cm1, replace); try (OutputStream out = Files.newOutputStream(modInfo)) { out.write(newBytes); } diff --git a/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java b/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java index 0366d4982ca87..0f9634423ec1b 100644 --- a/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java +++ b/test/langtools/tools/javac/sealed/CheckSubtypesOfSealedTest.java @@ -76,7 +76,7 @@ enum CheckFor { void check(ClassModel classFile) throws Exception { boolean found = false; for (Attribute attr: classFile.attributes()) { - if (attr.attributeName().equals("PermittedSubclasses")) { + if (attr.attributeName().equalsString("PermittedSubclasses")) { PermittedSubclassesAttribute permittedSubclasses = (PermittedSubclassesAttribute)attr; found = true; if (permittedSubclasses.permittedSubclasses().isEmpty()) { @@ -99,7 +99,7 @@ void check(ClassModel classFile) throws Exception { NOT_SEALED { void check(ClassModel classFile) throws Exception { for (Attribute attr: classFile.attributes()) { - if (attr.attributeName().equals("PermittedSubclasses")) { + if (attr.attributeName().equalsString("PermittedSubclasses")) { throw new AssertionError(classFile.thisClass().name() + " should not be sealed"); } } diff --git a/test/langtools/tools/javap/T6716452.java b/test/langtools/tools/javap/T6716452.java index 63ccead52e7bb..20c382918c3a0 100644 --- a/test/langtools/tools/javap/T6716452.java +++ b/test/langtools/tools/javap/T6716452.java @@ -70,7 +70,7 @@ > void test(MethodModel mm, AttributeMapper attr, Clas if (!c.isAssignableFrom(mm.attributes().get(index).getClass())) { error(mm + ": unexpected attribute found," + " expected " + c.getName() - + " found " + mm.attributes().get(index).attributeName()); + + " found " + mm.attributes().get(index).attributeName().stringValue()); } } else { error(mm + ": expected attribute " + attr.name() + " not found"); diff --git a/test/lib/jdk/test/lib/cds/CDSArchiveUtils.java b/test/lib/jdk/test/lib/cds/CDSArchiveUtils.java index 38748ec432b7b..fd76df92ef63a 100644 --- a/test/lib/jdk/test/lib/cds/CDSArchiveUtils.java +++ b/test/lib/jdk/test/lib/cds/CDSArchiveUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2024, 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 @@ -145,6 +145,7 @@ public class CDSArchiveUtils { public static int dynamicArchiveHeaderSize() { return dynamicArchiveHeaderSize; } public static int cdsFileMapRegionSize() { return cdsFileMapRegionSize; } public static long alignment() { return alignment; } + public static int num_regions() { return num_regions; } @@ -495,9 +496,14 @@ public static File deleteBytesAtTheEnd(File orgFile, String newFileName) throws } // used region size - public static long usedRegionSizeAligned(File archiveFile, int region) throws Exception { + public static long usedRegionSize(File archiveFile, int region) throws Exception { long offset = spOffset + cdsFileMapRegionSize * region + spUsedOffset; - long used = readInt(archiveFile, offset, sizetSize); + return readInt(archiveFile, offset, sizetSize); + } + + // used region size + public static long usedRegionSizeAligned(File archiveFile, int region) throws Exception { + long used = usedRegionSize(archiveFile, region); return alignUpWithAlignment(used); } }