diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index 2dcfc43898c4b..23bc65178542b 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -4572,8 +4572,7 @@ oop java_lang_invoke_ResolvedMethodName::find_resolved_method(const methodHandle NoSafepointVerifier nsv; if (method->is_old()) { - method = (method->is_deleted()) ? Universe::throw_no_such_method_error() : - method->get_new_method(); + method = method->get_new_method(); } InstanceKlass* holder = method->method_holder(); diff --git a/src/hotspot/share/oops/cpCache.cpp b/src/hotspot/share/oops/cpCache.cpp index a855639e74b8f..d4d03c9b783ea 100644 --- a/src/hotspot/share/oops/cpCache.cpp +++ b/src/hotspot/share/oops/cpCache.cpp @@ -643,7 +643,6 @@ void ConstantPoolCache::adjust_method_entries(bool * trace_name_printed) { if (old_method == nullptr || !old_method->is_old()) { continue; } - assert(!old_method->is_deleted(), "cannot delete these methods"); Method* new_method = old_method->get_new_method(); resolved_indy_entry_at(j)->adjust_method_entry(new_method); log_adjust("indy", old_method, new_method, trace_name_printed); @@ -657,11 +656,6 @@ void ConstantPoolCache::adjust_method_entries(bool * trace_name_printed) { if (old_method == nullptr || !old_method->is_old()) { continue; // skip uninteresting entries } - if (old_method->is_deleted()) { - // clean up entries with deleted methods - method_entry->reset_entry(); - continue; - } Method* new_method = old_method->get_new_method(); method_entry->adjust_method_entry(new_method); log_adjust("non-indy", old_method, new_method, trace_name_printed); diff --git a/src/hotspot/share/oops/instanceKlass.cpp b/src/hotspot/share/oops/instanceKlass.cpp index f4ab8c3140966..c245ebf463ded 100644 --- a/src/hotspot/share/oops/instanceKlass.cpp +++ b/src/hotspot/share/oops/instanceKlass.cpp @@ -3474,7 +3474,6 @@ void InstanceKlass::adjust_default_methods(bool* trace_name_printed) { if (old_method == nullptr || !old_method->is_old()) { continue; // skip uninteresting entries } - assert(!old_method->is_deleted(), "default methods may not be deleted"); Method* new_method = old_method->get_new_method(); default_methods()->at_put(index, new_method); diff --git a/src/hotspot/share/oops/klassVtable.cpp b/src/hotspot/share/oops/klassVtable.cpp index 8d13310cdc7a0..a6d0aa889d9e3 100644 --- a/src/hotspot/share/oops/klassVtable.cpp +++ b/src/hotspot/share/oops/klassVtable.cpp @@ -1022,8 +1022,6 @@ void klassVtable::adjust_method_entries(bool * trace_name_printed) { if (old_method == nullptr || !old_method->is_old()) { continue; // skip uninteresting entries } - assert(!old_method->is_deleted(), "vtable methods may not be deleted"); - Method* new_method = old_method->get_new_method(); put_method_at(new_method, index); @@ -1385,7 +1383,6 @@ void klassItable::adjust_method_entries(bool * trace_name_printed) { if (old_method == nullptr || !old_method->is_old()) { continue; // skip uninteresting entries } - assert(!old_method->is_deleted(), "itable methods may not be deleted"); Method* new_method = old_method->get_new_method(); ime->initialize(_klass, new_method); diff --git a/src/hotspot/share/oops/method.cpp b/src/hotspot/share/oops/method.cpp index 7552bf50ed9f9..fea336427ab33 100644 --- a/src/hotspot/share/oops/method.cpp +++ b/src/hotspot/share/oops/method.cpp @@ -1224,7 +1224,6 @@ void Method::remove_unshareable_flags() { // clear all the flags that shouldn't be in the archived version assert(!is_old(), "must be"); assert(!is_obsolete(), "must be"); - assert(!is_deleted(), "must be"); set_is_prefixed_native(false); set_queued_for_compilation(false); diff --git a/src/hotspot/share/oops/methodFlags.hpp b/src/hotspot/share/oops/methodFlags.hpp index 2ae1e002b653d..9113fc48b5a5a 100644 --- a/src/hotspot/share/oops/methodFlags.hpp +++ b/src/hotspot/share/oops/methodFlags.hpp @@ -46,7 +46,7 @@ class MethodFlags { status(has_jsrs , 1 << 1) \ status(is_old , 1 << 2) /* RedefineClasses() has replaced this method */ \ status(is_obsolete , 1 << 3) /* RedefineClasses() has made method obsolete */ \ - status(is_deleted , 1 << 4) /* RedefineClasses() has deleted this method */ \ + status(UNUSED , 1 << 4) \ status(is_prefixed_native , 1 << 5) /* JVMTI has prefixed this native method */ \ status(monitor_matching , 1 << 6) /* True if we know that monitorenter/monitorexit bytecodes match */ \ status(queued_for_compilation , 1 << 7) \ diff --git a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp index 3066ef74cb832..2fba7b6a03656 100644 --- a/src/hotspot/share/prims/jvmtiRedefineClasses.cpp +++ b/src/hotspot/share/prims/jvmtiRedefineClasses.cpp @@ -72,11 +72,7 @@ Array* VM_RedefineClasses::_old_methods = nullptr; Array* VM_RedefineClasses::_new_methods = nullptr; Method** VM_RedefineClasses::_matching_old_methods = nullptr; Method** VM_RedefineClasses::_matching_new_methods = nullptr; -Method** VM_RedefineClasses::_deleted_methods = nullptr; -Method** VM_RedefineClasses::_added_methods = nullptr; int VM_RedefineClasses::_matching_methods_length = 0; -int VM_RedefineClasses::_deleted_methods_length = 0; -int VM_RedefineClasses::_added_methods_length = 0; // This flag is global as the constructor does not reset it: bool VM_RedefineClasses::_has_redefined_Object = false; @@ -926,12 +922,6 @@ static jvmtiError check_permitted_subclasses_attribute(InstanceKlass* the_class, scratch_class->permitted_subclasses()); } -static bool can_add_or_delete(Method* m) { - // Compatibility mode - return (AllowRedefinitionToAddDeleteMethods && - (m->is_private() && (m->is_static() || m->is_final()))); -} - jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions( InstanceKlass* the_class, InstanceKlass* scratch_class) { @@ -1184,51 +1174,18 @@ jvmtiError VM_RedefineClasses::compare_and_normalize_class_versions( ++ni; break; case added: - // method added, see if it is OK - if (!can_add_or_delete(k_new_method)) { - log_info(redefine, class, normalize) - ("redefined class %s methods error: added method: %s [%d]", - the_class->external_name(), k_new_method->name_and_sig_as_C_string(), ni); - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED; - } - { - u2 num = the_class->next_method_idnum(); - if (num == ConstMethod::UNSET_IDNUM) { - // cannot add any more methods - log_info(redefine, class, normalize) - ("redefined class %s methods error: can't create ID for new method %s [%d]", - the_class->external_name(), k_new_method->name_and_sig_as_C_string(), ni); - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED; - } - u2 new_num = k_new_method->method_idnum(); - Method* idnum_owner = scratch_class->method_with_idnum(num); - if (idnum_owner != nullptr) { - // There is already a method assigned this idnum -- switch them - // Take current and original idnum from the new_method - idnum_owner->set_method_idnum(new_num); - idnum_owner->set_orig_method_idnum(k_new_method->orig_method_idnum()); - } - k_new_method->set_method_idnum(num); - k_new_method->set_orig_method_idnum(num); - if (thread->has_pending_exception()) { - return JVMTI_ERROR_OUT_OF_MEMORY; - } - } - log_trace(redefine, class, normalize) - ("Method added: new: %s [%d]", k_new_method->name_and_sig_as_C_string(), ni); - ++ni; // advance to next new method + // method added, report the error + log_info(redefine, class, normalize) + ("redefined class %s methods error: added method: %s [%d]", + the_class->external_name(), k_new_method->name_and_sig_as_C_string(), ni); + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_ADDED; break; case deleted: - // method deleted, see if it is OK - if (!can_add_or_delete(k_old_method)) { - log_info(redefine, class, normalize) - ("redefined class %s methods error: deleted method %s [%d]", - the_class->external_name(), k_old_method->name_and_sig_as_C_string(), oi); - return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED; - } - log_trace(redefine, class, normalize) - ("Method deleted: old: %s [%d]", k_old_method->name_and_sig_as_C_string(), oi); - ++oi; // advance to next old method + // method deleted, report the error + log_info(redefine, class, normalize) + ("redefined class %s methods error: deleted method %s [%d]", + the_class->external_name(), k_old_method->name_and_sig_as_C_string(), oi); + return JVMTI_ERROR_UNSUPPORTED_REDEFINITION_METHOD_DELETED; break; default: ShouldNotReachHere(); @@ -3918,26 +3875,6 @@ int VM_RedefineClasses::check_methods_and_mark_as_obsolete() { } old_method->set_is_old(); } - for (int i = 0; i < _deleted_methods_length; ++i) { - Method* old_method = _deleted_methods[i]; - - assert(!old_method->has_vtable_index(), - "cannot delete methods with vtable entries");; - - // Mark all deleted methods as old, obsolete and deleted - old_method->set_is_deleted(); - old_method->set_is_old(); - old_method->set_is_obsolete(); - ++obsolete_count; - // With tracing we try not to "yack" too much. The position of - // this trace assumes there are fewer obsolete methods than - // EMCP methods. - if (log_is_enabled(Trace, redefine, class, obsolete, mark)) { - ResourceMark rm; - log_trace(redefine, class, obsolete, mark) - ("mark deleted %s(%s) as obsolete", old_method->name()->as_C_string(), old_method->signature()->as_C_string()); - } - } assert((emcp_method_count + obsolete_count) == _old_methods->length(), "sanity check"); log_trace(redefine, class, obsolete, mark)("EMCP_cnt=%d, obsolete_cnt=%d", emcp_method_count, obsolete_count); @@ -4051,7 +3988,7 @@ class TransferNativeFunctionRegistration { prefixes = JvmtiExport::get_all_native_method_prefixes(&prefix_count); } - // Attempt to transfer any of the old or deleted methods that are native + // Attempt to transfer any of the old methods that are native void transfer_registrations(Method** old_methods, int methods_length) { for (int j = 0; j < methods_length; j++) { Method* old_method = old_methods[j]; @@ -4073,7 +4010,6 @@ class TransferNativeFunctionRegistration { // Don't lose the association between a native method and its JNI function. void VM_RedefineClasses::transfer_old_native_function_registrations(InstanceKlass* the_class) { TransferNativeFunctionRegistration transfer(the_class); - transfer.transfer_registrations(_deleted_methods, _deleted_methods_length); transfer.transfer_registrations(_matching_old_methods, _matching_methods_length); } @@ -4114,18 +4050,14 @@ void VM_RedefineClasses::flush_dependent_code() { JvmtiExport::set_all_dependencies_are_recorded(true); } -void VM_RedefineClasses::compute_added_deleted_matching_methods() { +void VM_RedefineClasses::compute_matching_methods() { Method* old_method; Method* new_method; _matching_old_methods = NEW_RESOURCE_ARRAY(Method*, _old_methods->length()); _matching_new_methods = NEW_RESOURCE_ARRAY(Method*, _old_methods->length()); - _added_methods = NEW_RESOURCE_ARRAY(Method*, _new_methods->length()); - _deleted_methods = NEW_RESOURCE_ARRAY(Method*, _old_methods->length()); _matching_methods_length = 0; - _deleted_methods_length = 0; - _added_methods_length = 0; int nj = 0; int oj = 0; @@ -4135,14 +4067,10 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() { break; // we've looked at everything, done } // New method at the end - new_method = _new_methods->at(nj); - _added_methods[_added_methods_length++] = new_method; - ++nj; + assert(false, "unexpected added method at the end"); } else if (nj >= _new_methods->length()) { // Old method, at the end, is deleted - old_method = _old_methods->at(oj); - _deleted_methods[_deleted_methods_length++] = old_method; - ++oj; + assert(false, "unexpected deleted method at the end"); } else { old_method = _old_methods->at(oj); new_method = _new_methods->at(nj); @@ -4155,24 +4083,21 @@ void VM_RedefineClasses::compute_added_deleted_matching_methods() { } else { // added overloaded have already been moved to the end, // so this is a deleted overloaded method - _deleted_methods[_deleted_methods_length++] = old_method; - ++oj; + assert(false, "unexpected deleted overloaded method"); } } else { // names don't match if (old_method->name()->fast_compare(new_method->name()) > 0) { // new method - _added_methods[_added_methods_length++] = new_method; - ++nj; + assert(false, "unexpected added method"); } else { // deleted method - _deleted_methods[_deleted_methods_length++] = old_method; - ++oj; + assert(false, "unexpected deleted method"); } } } } - assert(_matching_methods_length + _deleted_methods_length == _old_methods->length(), "sanity"); - assert(_matching_methods_length + _added_methods_length == _new_methods->length(), "sanity"); + assert(_matching_methods_length == _old_methods->length(), "sanity"); + assert(_matching_methods_length == _new_methods->length(), "sanity"); } @@ -4218,7 +4143,7 @@ void VM_RedefineClasses::redefine_single_class(Thread* current, jclass the_jclas _old_methods = the_class->methods(); _new_methods = scratch_class->methods(); _the_class = the_class; - compute_added_deleted_matching_methods(); + compute_matching_methods(); update_jmethod_ids(); _any_class_has_resolved_methods = the_class->has_resolved_methods() || _any_class_has_resolved_methods; @@ -4573,26 +4498,6 @@ void VM_RedefineClasses::dump_methods() { m->access_flags().print_on(&log_stream); log_stream.cr(); } - log_trace(redefine, class, dump)("_deleted_methods --"); - for (j = 0; j < _deleted_methods_length; ++j) { - LogStreamHandle(Trace, redefine, class, dump) log_stream; - Method* m = _deleted_methods[j]; - log_stream.print("%4d (%5d) ", j, m->vtable_index()); - m->access_flags().print_on(&log_stream); - log_stream.print(" -- "); - m->print_name(&log_stream); - log_stream.cr(); - } - log_trace(redefine, class, dump)("_added_methods --"); - for (j = 0; j < _added_methods_length; ++j) { - LogStreamHandle(Trace, redefine, class, dump) log_stream; - Method* m = _added_methods[j]; - log_stream.print("%4d (%5d) ", j, m->vtable_index()); - m->access_flags().print_on(&log_stream); - log_stream.print(" -- "); - m->print_name(&log_stream); - log_stream.cr(); - } } void VM_RedefineClasses::print_on_error(outputStream* st) const { diff --git a/src/hotspot/share/prims/jvmtiRedefineClasses.hpp b/src/hotspot/share/prims/jvmtiRedefineClasses.hpp index d2eda1f3eede4..e67a4656946da 100644 --- a/src/hotspot/share/prims/jvmtiRedefineClasses.hpp +++ b/src/hotspot/share/prims/jvmtiRedefineClasses.hpp @@ -337,11 +337,7 @@ class VM_RedefineClasses: public VM_Operation { static Array* _new_methods; static Method** _matching_old_methods; static Method** _matching_new_methods; - static Method** _deleted_methods; - static Method** _added_methods; static int _matching_methods_length; - static int _deleted_methods_length; - static int _added_methods_length; static bool _has_redefined_Object; static bool _has_null_class_loader; @@ -403,9 +399,8 @@ class VM_RedefineClasses: public VM_Operation { jvmtiError compare_and_normalize_class_versions( InstanceKlass* the_class, InstanceKlass* scratch_class); - // Figure out which new methods match old methods in name and signature, - // which methods have been added, and which are no longer present - void compute_added_deleted_matching_methods(); + // Figure out which new methods match old methods in name and signature. + void compute_matching_methods(); // Change jmethodIDs to point to the new methods void update_jmethod_ids(); diff --git a/src/hotspot/share/prims/resolvedMethodTable.cpp b/src/hotspot/share/prims/resolvedMethodTable.cpp index cdd41730dea5a..7688864fde71a 100644 --- a/src/hotspot/share/prims/resolvedMethodTable.cpp +++ b/src/hotspot/share/prims/resolvedMethodTable.cpp @@ -358,9 +358,7 @@ class AdjustMethodEntries : public StackObj { if (old_method->is_old()) { - Method* new_method = (old_method->is_deleted()) ? - Universe::throw_no_such_method_error() : - old_method->get_new_method(); + Method* new_method = old_method->get_new_method(); java_lang_invoke_ResolvedMethodName::set_vmtarget(mem_name, new_method); ResourceMark rm; diff --git a/src/hotspot/share/runtime/arguments.cpp b/src/hotspot/share/runtime/arguments.cpp index d2a1c31282fd7..b50f3a8f92f29 100644 --- a/src/hotspot/share/runtime/arguments.cpp +++ b/src/hotspot/share/runtime/arguments.cpp @@ -522,7 +522,6 @@ void Arguments::init_version_specific_system_properties() { static SpecialFlag const special_jvm_flags[] = { // -------------- Deprecated Flags -------------- // --- Non-alias flags - sorted by obsolete_in then expired_in: - { "AllowRedefinitionToAddDeleteMethods", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() }, { "FlightRecorder", JDK_Version::jdk(13), JDK_Version::undefined(), JDK_Version::undefined() }, { "DumpSharedSpaces", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() }, { "DynamicDumpSharedSpaces", JDK_Version::jdk(18), JDK_Version::jdk(19), JDK_Version::undefined() }, @@ -532,6 +531,7 @@ static SpecialFlag const special_jvm_flags[] = { #ifdef _LP64 { "UseCompressedClassPointers", JDK_Version::jdk(25), JDK_Version::jdk(26), JDK_Version::undefined() }, #endif + { "AllowRedefinitionToAddDeleteMethods", JDK_Version::jdk(13), JDK_Version::jdk(26), JDK_Version::jdk(27) }, { "ParallelRefProcEnabled", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) }, { "ParallelRefProcBalancingEnabled", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) }, { "PSChunkLargeArrays", JDK_Version::jdk(26), JDK_Version::jdk(27), JDK_Version::jdk(28) }, diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index 41520442cd407..d7941b8134f3b 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -873,10 +873,6 @@ const int ObjectAlignmentInBytes = 8; "and can affect tests that expect specific methods to be EMCP. " \ "This option should be used with caution.") \ \ - product(bool, AllowRedefinitionToAddDeleteMethods, false, \ - "(Deprecated) Allow redefinition to add and delete private " \ - "static or final methods for compatibility with old releases") \ - \ develop(bool, TraceBytecodes, false, \ "Trace bytecode execution") \ \ diff --git a/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java b/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java index 99c2d27f8d3ea..f4e9338900e1f 100644 --- a/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java +++ b/test/hotspot/jtreg/runtime/CommandLine/VMDeprecatedOptions.java @@ -56,9 +56,6 @@ public class VMDeprecatedOptions { ArrayList deprecated = new ArrayList( Arrays.asList(new String[][] { // { , } - // deprecated non-alias flags: - {"AllowRedefinitionToAddDeleteMethods", "true"}, - // deprecated alias flags (see also aliased_jvm_flags): {"CreateMinidumpOnCrash", "false"} } diff --git a/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineAddLambdaExpression.java b/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineAddLambdaExpression.java deleted file mode 100644 index 7fe3ee29a7b86..0000000000000 --- a/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineAddLambdaExpression.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2018, 2022, 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 8193524 - * @summary Redefine a class' public static method that contains a lambda expression - * @requires vm.jvmti - * @library /test/lib - * @modules java.base/jdk.internal.misc - * @modules java.compiler - * java.instrument - * jdk.jartool/sun.tools.jar - * @run main RedefineClassHelper - * @run main/othervm -javaagent:redefineagent.jar -XX:+AllowRedefinitionToAddDeleteMethods -Xlog:redefine+class*=trace RedefineAddLambdaExpression - */ - -interface MathOperation { - public int operation(int a, int b); -} - -class B { - public static int operate(int a, int b, MathOperation mathOperation) { - return mathOperation.operation(a, b); - } - static int test_math(String p) { - MathOperation addition = (int a, int b) -> a + b; - return operate(10, 5, addition); - } -} - -public class RedefineAddLambdaExpression { - - public static String newB = """ - class B { - public static int operate(int a, int b, MathOperation mathOperation) { - return mathOperation.operation(a, b); - } - static int test_math(String p) { - MathOperation addition = (int a, int b) -> a + b; - System.out.println(p + " from class B's test_math method"); - MathOperation subtraction = (int a, int b) -> a - b; - return operate(10, 5, subtraction); - } - } - """; - - public static void main(String[] args) throws Exception { - int res = B.test_math("Hello"); - System.out.println("Result = " + res); - if (res != 15) { - throw new Error("test_math returned " + res + " expected " + 15); - } - RedefineClassHelper.redefineClass(B.class, newB); - - res = B.test_math("Hello"); - if (res != 5) - throw new Error("test_math returned " + res + " expected " + 5); - } -} diff --git a/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineSubtractLambdaExpression.java b/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineSubtractLambdaExpression.java deleted file mode 100644 index 4afc7cc1697ba..0000000000000 --- a/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/RedefineSubtractLambdaExpression.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2018, 2022, 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 8193524 - * @summary Redefine a class' public static method that contains a lambda expression - * @requires vm.jvmti - * @library /test/lib - * @modules java.base/jdk.internal.misc - * @modules java.compiler - * java.instrument - * jdk.jartool/sun.tools.jar - * @run main RedefineClassHelper - * @run main/othervm -javaagent:redefineagent.jar -XX:+AllowRedefinitionToAddDeleteMethods -Xlog:redefine+class*=trace RedefineSubtractLambdaExpression - */ - -interface MathOperation { - public int operation(int a, int b); -} - -class B { - public static int operate(int a, int b, MathOperation mathOperation) { - return mathOperation.operation(a, b); - } - static int test_math(String p) { - System.out.println(p + " from class B's test_math method"); - MathOperation subtraction = (int a, int b) -> a - b; - MathOperation addition = (int a, int b) -> a + b; - return operate(10, 5, addition); - } -} - -public class RedefineSubtractLambdaExpression { - - public static String newB = """ - class B { - public static int operate(int a, int b, MathOperation mathOperation) { - return mathOperation.operation(a, b); - } - static int test_math(String p) { - MathOperation subtraction = (int a, int b) -> a - b; - return operate(10, 5, subtraction); - } - } - """; - - public static void main(String[] args) throws Exception { - int res = B.test_math("Hello"); - System.out.println("Result = " + res); - if (res != 15) { - throw new Error("test_math returned " + res + " expected " + 15); - } - RedefineClassHelper.redefineClass(B.class, newB); - - res = B.test_math("Hello"); - if (res != 5) - throw new Error("test_math returned " + res + " expected " + 5); - } -} diff --git a/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/TestAddDeleteMethods.java b/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/TestAddDeleteMethods.java deleted file mode 100644 index dc997a28b8f97..0000000000000 --- a/test/hotspot/jtreg/serviceability/jvmti/RedefineClasses/TestAddDeleteMethods.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2019, 2020, 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 8192936 - * @summary RI does not follow the JVMTI RedefineClasses spec; need to disallow adding and deleting methods - * @requires vm.jvmti - * @library /test/lib - * @modules java.base/jdk.internal.misc - * @modules java.compiler - * java.instrument - * jdk.jartool/sun.tools.jar - * @run main RedefineClassHelper - * @run main/othervm -javaagent:redefineagent.jar TestAddDeleteMethods AllowAddDelete=no - * @run main/othervm -javaagent:redefineagent.jar -XX:+AllowRedefinitionToAddDeleteMethods TestAddDeleteMethods AllowAddDelete=yes - */ - -import static jdk.test.lib.Asserts.assertEquals; -import java.lang.Runnable; - -// package access top-level class to avoid problem with RedefineClassHelper -// and nested types. -class A implements Runnable { - private void foo() { System.out.println(" OLD foo called"); } - public void publicFoo() { System.out.println(" OLD publicFoo called"); } - private final void finalFoo() { System.out.println(" OLD finalFoo called"); } - private static void staticFoo() { System.out.println(" OLD staticFoo called"); } - public void run() { foo(); publicFoo(); finalFoo(); staticFoo(); } -} - -class B implements Runnable { - public void run() { } -} - -public class TestAddDeleteMethods { - static private boolean allowAddDeleteMethods = false; - - static private A a; - static private B b; - - // This redefinition is expected to always succeed. - public static String newA = - "class A implements Runnable {" + - "private void foo() { System.out.println(\" NEW foo called\"); }" + - "public void publicFoo() { System.out.println(\" NEW publicFoo called\"); }" + - "private final void finalFoo() { System.out.println(\" NEW finalFoo called\"); }" + - "private static void staticFoo() { System.out.println(\" NEW staticFoo called\"); }" + - "public void run() { foo(); publicFoo(); finalFoo(); staticFoo(); }" + - "}"; - - // This redefinition is expected to always fail. - public static String ADeleteFoo = - "class A implements Runnable {" + - "public void publicFoo() { System.out.println(\" NEW publicFoo called\"); }" + - "private final void finalFoo() { System.out.println(\" NEW finalFoo called\"); }" + - "private static void staticFoo() { System.out.println(\" NEW staticFoo called\"); }" + - "public void run() { publicFoo(); finalFoo(); staticFoo(); }" + - "}"; - - // This redefinition is expected to always fail. - public static String ADeletePublicFoo = - "class A implements Runnable {" + - "private void foo() { System.out.println(\" NEW foo called\"); }" + - "private final void finalFoo() { System.out.println(\" NEW finalFoo called\"); }" + - "private static void staticFoo() { System.out.println(\" NEW staticFoo called\"); }" + - "public void run() { foo(); finalFoo(); staticFoo(); }" + - "}"; - - // This redefinition is expected to succeed with option -XX:+AllowRedefinitionToAddDeleteMethods. - public static String ADeleteFinalFoo = - "class A implements Runnable {" + - "private void foo() { System.out.println(\" NEW foo called\"); }" + - "public void publicFoo() { System.out.println(\" NEW publicFoo called\"); }" + - "private static void staticFoo() { System.out.println(\" NEW staticFoo called\"); }" + - "public void run() { foo(); publicFoo(); staticFoo(); }" + - "}"; - - // This redefinition is expected to succeed with option -XX:+AllowRedefinitionToAddDeleteMethods. - // With compatibility option redefinition ADeleteFinalFoo already deleted finalFoo method. - // So, this redefinition will add it back which is expected to work. - public static String ADeleteStaticFoo = - "class A implements Runnable {" + - "private void foo() { System.out.println(\" NEW foo called\"); }" + - "public void publicFoo() { System.out.println(\" NEW publicFoo called\"); }" + - "private final void finalFoo() { System.out.println(\" NEW finalFoo called\"); }" + - "public void run() { foo(); publicFoo(); finalFoo(); }" + - "}"; - - // This redefinition is expected to always fail. - public static String BAddBar = - "class B implements Runnable {" + - "private void bar() { System.out.println(\" bar called\"); }" + - "public void run() { bar(); }" + - "}"; - - // This redefinition is expected to always fail. - public static String BAddPublicBar = - "class B implements Runnable {" + - "public void publicBar() { System.out.println(\" publicBar called\"); }" + - "public void run() { publicBar(); }" + - "}"; - - // This redefinition is expected to succeed with option -XX:+AllowRedefinitionToAddDeleteMethods. - public static String BAddFinalBar = - "class B implements Runnable {" + - "private final void finalBar() { System.out.println(\" finalBar called\"); }" + - "public void run() { finalBar(); }" + - "}"; - - // This redefinition is expected to succeed with option -XX:+AllowRedefinitionToAddDeleteMethods. - // With compatibility option redefinition BAddFinalBar added finalBar method. - // So, this redefinition will deleate it back which is expected to work. - public static String BAddStaticBar = - "class B implements Runnable {" + - "private static void staticBar() { System.out.println(\" staticBar called\"); }" + - "public void run() { staticBar(); }" + - "}"; - - static private final String ExpMsgPrefix = "attempted to "; - static private final String ExpMsgPostfix = " a method"; - - static private void log(String msg) { System.out.println(msg); } - - public static void test(Runnable obj, String newBytes, String expSuffix, String methodName, - boolean expectedRedefToPass) throws Exception { - String expectedMessage = ExpMsgPrefix + expSuffix + ExpMsgPostfix; - Class klass = obj.getClass(); - String className = klass.getName(); - String expResult = expectedRedefToPass ? "PASS" : "FAIL"; - - log(""); - log("## Test " + expSuffix + " method \'" + methodName + "\' in class " + className + - "; redefinition expected to " + expResult); - - try { - RedefineClassHelper.redefineClass(klass, newBytes); - - if (expectedRedefToPass) { - log(" Did not get UOE at redefinition as expected"); - } else { - throw new RuntimeException("Failed, expected UOE"); - } - obj.run(); - log(""); - } catch (UnsupportedOperationException uoe) { - String message = uoe.getMessage(); - - if (expectedRedefToPass) { - throw new RuntimeException("Failed, unexpected UOE: " + message); - } else { - log(" Got expected UOE: " + message); - if (!message.endsWith(expectedMessage)) { - throw new RuntimeException("Expected UOE error message to end with: " + expectedMessage); - } - } - } - } - - static { - a = new A(); - b = new B(); - } - - public static void main(String[] args) throws Exception { - if (args.length > 0 && args[0].equals("AllowAddDelete=yes")) { - allowAddDeleteMethods = true; - } - - log("## Test original class A"); - a.run(); - log(""); - - log("## Test with modified method bodies in class A; redefinition expected to pass: true"); - RedefineClassHelper.redefineClass(A.class, newA); - a.run(); - - test(a, ADeleteFoo, "delete", "foo", false); - test(a, ADeletePublicFoo, "delete", "publicFoo", false); - test(a, ADeleteFinalFoo, "delete", "finalFoo", allowAddDeleteMethods); - test(a, ADeleteStaticFoo, "delete", "staticFoo", allowAddDeleteMethods); - - test(b, BAddBar, "add", "bar", false); - test(b, BAddPublicBar, "add", "publicBar", false); - test(b, BAddFinalBar, "add", "finalBar", allowAddDeleteMethods); - test(b, BAddStaticBar, "add", "staticBar", allowAddDeleteMethods); - } -} diff --git a/test/jdk/com/sun/jdi/RedefineAddPrivateMethod.java b/test/jdk/com/sun/jdi/RedefineAddPrivateMethod.java deleted file mode 100644 index 4d25ae2367733..0000000000000 --- a/test/jdk/com/sun/jdi/RedefineAddPrivateMethod.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2016, 2019, 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 8149743 - * @summary crash when adding a breakpoint after redefining to add a private static method - * @comment converted from test/jdk/com/sun/jdi/RedefineAddPrivateMethod.sh - * - * @library /test/lib - * @compile -g RedefineAddPrivateMethod.java - * @run main/othervm RedefineAddPrivateMethod - */ - -import jdk.test.lib.process.OutputAnalyzer; -import lib.jdb.JdbCommand; -import lib.jdb.JdbTest; - -class RedefineAddPrivateMethodTarg { - static public void main(String[] args) { - System.out.println("@1 breakpoint"); - System.out.println("@2 breakpoint"); - } - - // @1 uncomment private static void test() {} -} - -public class RedefineAddPrivateMethod extends JdbTest { - static private final String ALLOW_ADD_DELETE_OPTION = "-XX:+AllowRedefinitionToAddDeleteMethods"; - - public static void main(String argv[]) { - RedefineAddPrivateMethod test = new RedefineAddPrivateMethod(); - test.launchOptions.addVMOptions(ALLOW_ADD_DELETE_OPTION); - test.run(); - } - - private RedefineAddPrivateMethod() { - super(DEBUGGEE_CLASS, SOURCE_FILE); - } - - private static final String DEBUGGEE_CLASS = RedefineAddPrivateMethodTarg.class.getName(); - private static final String SOURCE_FILE = "RedefineAddPrivateMethod.java"; - - @Override - protected void runCases() { - setBreakpoints(1); - jdb.command(JdbCommand.run()); - - redefineClass(1, "-g"); - // ensure "test()" method has been added successfully - execCommand(JdbCommand.eval(DEBUGGEE_CLASS + ".test()")) - .shouldNotContain("ParseException"); - - setBreakpoints(2); - jdb.command(JdbCommand.run()); - - jdb.quit(); - - new OutputAnalyzer(getDebuggeeOutput()) - .shouldNotContain("Internal exception:"); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineAddDeleteMethod/DeleteMethodHandle/MethodHandleDeletedMethod.java b/test/jdk/java/lang/instrument/RedefineAddDeleteMethod/DeleteMethodHandle/MethodHandleDeletedMethod.java deleted file mode 100644 index 88c91d3a417f3..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineAddDeleteMethod/DeleteMethodHandle/MethodHandleDeletedMethod.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2019, 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 8181171 - * @summary Break ResolvedMethodTable with redefined nest class. - * @library /test/lib - * @modules java.base/jdk.internal.misc - * @modules java.compiler - * java.instrument - * @compile ../../NamedBuffer.java - * @compile redef/Xost.java - * @run main RedefineClassHelper - * @run main/othervm -XX:+AllowRedefinitionToAddDeleteMethods -javaagent:redefineagent.jar -Xlog:redefine+class+update*=debug,membername+table=debug MethodHandleDeletedMethod - */ - -import java.io.File; -import java.io.FileInputStream; -import java.lang.invoke.*; - -class Host { - static MethodHandle fooMH; - - static class A { - private static void foo() { System.out.println("OLD foo called"); } - } - static void bar() throws NoSuchMethodError { - A.foo(); - } - static void barMH() throws Throwable { - fooMH.invokeExact(); - } - - public static void reresolve() throws Throwable { - fooMH = MethodHandles.lookup().findStatic(A.class, "foo", MethodType.methodType(void.class)); - } - - static { - try { - fooMH = MethodHandles.lookup().findStatic(A.class, "foo", MethodType.methodType(void.class)); - } catch (ReflectiveOperationException ex) { - } - } -} - -public class MethodHandleDeletedMethod { - - static final String DEST = System.getProperty("test.classes"); - static final boolean VERBOSE = false; - - private static byte[] bytesForHostClass(char replace) throws Throwable { - return NamedBuffer.bytesForHostClass(replace, "Host$A"); - } - - public static void main(java.lang.String[] unused) throws Throwable { - Host h = new Host(); - h.bar(); - h.barMH(); - byte[] buf = bytesForHostClass('X'); - RedefineClassHelper.redefineClass(Host.A.class, buf); - try { - h.bar(); // call deleted Method directly - throw new RuntimeException("Failed, expected NSME"); - } catch (NoSuchMethodError nsme) { - System.out.println("Received expected NSME"); - } - try { - h.barMH(); // call through MethodHandle for deleted Method - throw new RuntimeException("Failed, expected NSME"); - } catch (NoSuchMethodError nsme) { - System.out.println("Received expected NSME"); - } - System.out.println("Passed."); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodAddInvoke.sh b/test/jdk/java/lang/instrument/RedefineMethodAddInvoke.sh deleted file mode 100644 index 284051d05d8d0..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodAddInvoke.sh +++ /dev/null @@ -1,89 +0,0 @@ -# -# 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 -# 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 6667089 -# @summary Reflexive invocation of newly added methods broken. -# @author Daniel D. Daugherty -# -# @run shell MakeJAR3.sh RedefineMethodAddInvokeAgent 'Can-Redefine-Classes: true' -# @run build RedefineMethodAddInvokeApp -# @run shell RedefineMethodAddInvoke.sh -# - -if [ "${TESTJAVA}" = "" ] -then - echo "TESTJAVA not set. Test cannot execute. Failed." - exit 1 -fi - -if [ "${COMPILEJAVA}" = "" ] -then - COMPILEJAVA="${TESTJAVA}" -fi -echo "COMPILEJAVA=${COMPILEJAVA}" - -if [ "${TESTSRC}" = "" ] -then - echo "TESTSRC not set. Test cannot execute. Failed." - exit 1 -fi - -if [ "${TESTCLASSES}" = "" ] -then - echo "TESTCLASSES not set. Test cannot execute. Failed." - exit 1 -fi - -JAVAC="${COMPILEJAVA}"/bin/javac -JAVA="${TESTJAVA}"/bin/java - -cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_1.java \ - RedefineMethodAddInvokeTarget.java -"${JAVAC}" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . RedefineMethodAddInvokeTarget.java -mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_1.java -mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_1.class - -cp "${TESTSRC}"/RedefineMethodAddInvokeTarget_2.java \ - RedefineMethodAddInvokeTarget.java -"${JAVAC}" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . RedefineMethodAddInvokeTarget.java -mv RedefineMethodAddInvokeTarget.java RedefineMethodAddInvokeTarget_2.java -mv RedefineMethodAddInvokeTarget.class RedefineMethodAddInvokeTarget_2.class - -"${JAVA}" ${TESTVMOPTS} ${TESTJAVAOPTS} -javaagent:RedefineMethodAddInvokeAgent.jar \ - -XX:+AllowRedefinitionToAddDeleteMethods \ - -classpath "${TESTCLASSES}" RedefineMethodAddInvokeApp > output.log 2>&1 -cat output.log - -MESG="Exception" -grep "$MESG" output.log -result=$? -if [ "$result" = 0 ]; then - echo "FAIL: found '$MESG' in the test output" - result=1 -else - echo "PASS: did NOT find '$MESG' in the test output" - result=0 -fi - -exit $result diff --git a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeAgent.java b/test/jdk/java/lang/instrument/RedefineMethodAddInvokeAgent.java deleted file mode 100644 index feaf837bdf94f..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeAgent.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2008, 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.lang.instrument.Instrumentation; - -public class RedefineMethodAddInvokeAgent { - private static Instrumentation instrumentation; - - private RedefineMethodAddInvokeAgent() { - } - - public static void premain(String agentArgs, Instrumentation inst) { - System.out.println("Hello from RedefineMethodAddInvokeAgent!"); - System.out.println("isRedefineClassesSupported()=" + - inst.isRedefineClassesSupported()); - - instrumentation = inst; - } - - public static Instrumentation getInstrumentation() { - return instrumentation; - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeApp.java b/test/jdk/java/lang/instrument/RedefineMethodAddInvokeApp.java deleted file mode 100644 index 47f736f87bbee..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeApp.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2008, 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.*; -import java.lang.instrument.*; - -public class RedefineMethodAddInvokeApp { - public static void main(String args[]) throws Exception { - System.out.println("Hello from RedefineMethodAddInvokeApp!"); - - new RedefineMethodAddInvokeApp().doTest(); - - System.exit(0); - } - - private void doTest() throws Exception { - RedefineMethodAddInvokeTarget target = - new RedefineMethodAddInvokeTarget(); - - System.out.println("RedefineMethodAddInvokeApp: invoking myMethod()"); - target.test(0); // invoke the original myMethod() - - // add myMethod1() - do_redefine(1); - - System.out.println("RedefineMethodAddInvokeApp: invoking myMethod1()"); - target.test(1); // invoke myMethod1() - - // add myMethod2() - do_redefine(2); - - System.out.println("RedefineMethodAddInvokeApp: invoking myMethod2()"); - target.test(2); // invoke myMethod2() - } - - private static void do_redefine(int counter) throws Exception { - File f = new File("RedefineMethodAddInvokeTarget_" + counter + - ".class"); - System.out.println("Reading test class from " + f); - InputStream redefineStream = new FileInputStream(f); - - byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream); - - ClassDefinition redefineParamBlock = new ClassDefinition( - RedefineMethodAddInvokeTarget.class, redefineBuffer); - - RedefineMethodAddInvokeAgent.getInstrumentation().redefineClasses( - new ClassDefinition[] {redefineParamBlock}); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget.java b/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget.java deleted file mode 100644 index c3bb295620634..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2008, 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.lang.reflect.Method; - -public class RedefineMethodAddInvokeTarget { - public void test(int counter) throws Exception { - Method method = getClass().getDeclaredMethod("myMethod" + - (counter == 0 ? "" : counter)); - method.setAccessible(true); - method.invoke(this); - } - - public void myMethod() { - System.out.println("Hello from the original myMethod()!"); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget_1.java b/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget_1.java deleted file mode 100644 index 2a4e6623353e2..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget_1.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2008, 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.lang.reflect.Method; - -public class RedefineMethodAddInvokeTarget { - public void test(int counter) throws Exception { - Method method = getClass().getDeclaredMethod("myMethod" + - (counter == 0 ? "" : counter)); - method.setAccessible(true); - method.invoke(this); - } - - public void myMethod() { - System.out.println("Hello from the non-EMCP myMethod()!"); - } - - private final void myMethod1() { - System.out.println("Hello from myMethod1()!"); - System.out.println("Calling myMethod() from myMethod1():"); - myMethod(); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget_2.java b/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget_2.java deleted file mode 100644 index dc64a48f0561d..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodAddInvokeTarget_2.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2008, 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.lang.reflect.Method; - -public class RedefineMethodAddInvokeTarget { - public void test(int counter) throws Exception { - Method method = getClass().getDeclaredMethod("myMethod" + - (counter == 0 ? "" : counter)); - method.setAccessible(true); - method.invoke(this); - } - - public void myMethod() { - System.out.println("Hello from the non-EMCP again myMethod()!"); - } - - private final void myMethod1() { - System.out.println("Hello from myMethod1()!"); - System.out.println("Calling myMethod() from myMethod1():"); - myMethod(); - } - - private final void myMethod2() { - System.out.println("Hello from myMethod2()!"); - System.out.println("Calling myMethod1() from myMethod2():"); - myMethod1(); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodDelInvoke.sh b/test/jdk/java/lang/instrument/RedefineMethodDelInvoke.sh deleted file mode 100644 index 0df5a10474115..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodDelInvoke.sh +++ /dev/null @@ -1,99 +0,0 @@ -# -# 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 -# 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 8042796 -# @summary jvmtiRedefineClasses.cpp: guarantee(false) failed: OLD and/or OBSOLETE method(s) found -# @author Daniel D. Daugherty -# @author Serguei Spitsyn -# -# @run shell MakeJAR3.sh RedefineMethodDelInvokeAgent 'Can-Redefine-Classes: true' -# @run build RedefineMethodDelInvokeApp -# @run shell RedefineMethodDelInvoke.sh -# - -if [ "${TESTJAVA}" = "" ] -then - echo "TESTJAVA not set. Test cannot execute. Failed." - exit 1 -fi - -if [ "${COMPILEJAVA}" = "" ] -then - COMPILEJAVA="${TESTJAVA}" -fi -echo "COMPILEJAVA=${COMPILEJAVA}" - -if [ "${TESTSRC}" = "" ] -then - echo "TESTSRC not set. Test cannot execute. Failed." - exit 1 -fi - -if [ "${TESTCLASSES}" = "" ] -then - echo "TESTCLASSES not set. Test cannot execute. Failed." - exit 1 -fi - -JAVAC="${COMPILEJAVA}"/bin/javac -JAVA="${TESTJAVA}"/bin/java - -cp "${TESTSRC}"/RedefineMethodDelInvokeTarget_1.java \ - RedefineMethodDelInvokeTarget.java -"${JAVAC}" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . RedefineMethodDelInvokeTarget.java -mv RedefineMethodDelInvokeTarget.java RedefineMethodDelInvokeTarget_1.java -mv RedefineMethodDelInvokeTarget.class RedefineMethodDelInvokeTarget_1.class - -cp "${TESTSRC}"/RedefineMethodDelInvokeTarget_2.java \ - RedefineMethodDelInvokeTarget.java -"${JAVAC}" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . RedefineMethodDelInvokeTarget.java -mv RedefineMethodDelInvokeTarget.java RedefineMethodDelInvokeTarget_2.java -mv RedefineMethodDelInvokeTarget.class RedefineMethodDelInvokeTarget_2.class - -"${JAVA}" ${TESTVMOPTS} ${TESTJAVAOPTS} -javaagent:RedefineMethodDelInvokeAgent.jar \ - -XX:+AllowRedefinitionToAddDeleteMethods \ - -classpath "${TESTCLASSES}" RedefineMethodDelInvokeApp > output.log 2>&1 - -result=$? -if [ "$result" = 0 ]; then - echo "The test returned expected exit code: $result" -else - echo "FAIL: the test returned unexpected exit code: $result" - exit $result -fi - -cat output.log - -MESG="Exception" -grep "$MESG" output.log -result=$? -if [ "$result" = 0 ]; then - echo "FAIL: found '$MESG' in the test output" - result=1 -else - echo "PASS: did NOT find '$MESG' in the test output" - result=0 -fi - -exit $result diff --git a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeAgent.java b/test/jdk/java/lang/instrument/RedefineMethodDelInvokeAgent.java deleted file mode 100644 index 2a3532f794ed5..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeAgent.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.lang.instrument.Instrumentation; - -public class RedefineMethodDelInvokeAgent { - private static Instrumentation instrumentation; - - private RedefineMethodDelInvokeAgent() { - } - - public static void premain(String agentArgs, Instrumentation inst) { - System.out.println("Hello from RedefineMethodDelInvokeAgent!"); - System.out.println("isRedefineClassesSupported()=" + - inst.isRedefineClassesSupported()); - - instrumentation = inst; - } - - public static Instrumentation getInstrumentation() { - return instrumentation; - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeApp.java b/test/jdk/java/lang/instrument/RedefineMethodDelInvokeApp.java deleted file mode 100644 index 1cd354e85e5bb..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeApp.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import java.io.*; -import java.lang.instrument.*; - -public class RedefineMethodDelInvokeApp { - public static void main(String args[]) { - System.out.println("Hello from RedefineMethodDelInvokeApp!"); - - try { - new RedefineMethodDelInvokeApp().doTest(); - } catch (Exception ex) { - System.out.println("Exception has been caught"); - ex.printStackTrace(); - System.exit(1); - } - System.exit(0); - } - - private void doTest() throws Exception { - RedefineMethodDelInvokeTarget target = - new RedefineMethodDelInvokeTarget(); - - System.out.println("RedefineMethodDelInvokeApp: invoking myMethod0(), myMethod1(), myMethod2()"); - target.test(); - - // delete myMethod2() - do_redefine(1); - - System.out.println("RedefineMethodDelInvokeApp: invoking myMethod0(), myMethod1()"); - target.test(); - - // delete myMethod1() - do_redefine(2); - - System.out.println("RedefineMethodDelInvokeApp: invoking myMethod0()"); - target.test(); - } - - private static void do_redefine(int counter) throws Exception { - File f = new File("RedefineMethodDelInvokeTarget_" + counter + - ".class"); - System.out.println("Reading test class from " + f); - InputStream redefineStream = new FileInputStream(f); - - byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream); - - ClassDefinition redefineParamBlock = new ClassDefinition( - RedefineMethodDelInvokeTarget.class, redefineBuffer); - - RedefineMethodDelInvokeAgent.getInstrumentation().redefineClasses( - new ClassDefinition[] {redefineParamBlock}); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget.java b/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget.java deleted file mode 100644 index 5bfcae4555262..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -public class RedefineMethodDelInvokeTarget { - public void test() { - myMethod0(); - } - - public static void myMethod0() { - System.out.println("Target 0: myMethod0: Calling myMethod1()"); - myMethod1(); - } - - private static void myMethod1() { - System.out.println("Target 0: myMethod1: Calling myMethod2()"); - myMethod2(); - } - - private static void myMethod2() { - System.out.println("Target 0: myMethod2"); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget_1.java b/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget_1.java deleted file mode 100644 index 170e41eba5a52..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget_1.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -public class RedefineMethodDelInvokeTarget { - public void test() { - myMethod0(); - } - - public static void myMethod0() { - System.out.println("Target 1: myMethod0: Calling myMethod1()"); - myMethod1(); - } - - private static void myMethod1() { - System.out.println("Target 1: myMethod1"); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget_2.java b/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget_2.java deleted file mode 100644 index 2513c52f5284e..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodDelInvokeTarget_2.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -public class RedefineMethodDelInvokeTarget { - public void test() { - myMethod0(); - } - - public static void myMethod0() { - System.out.println("Target 2: myMethod0"); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodInBacktrace.sh b/test/jdk/java/lang/instrument/RedefineMethodInBacktrace.sh deleted file mode 100644 index 85d06fd486e66..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodInBacktrace.sh +++ /dev/null @@ -1,94 +0,0 @@ -# -# 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 -# 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 7174978 -# @summary Redefine a class with a method stored in a backtrace. -# @author Stefan Karlsson -# -# @modules java.instrument -# jdk.management -# @run shell MakeJAR3.sh RedefineMethodInBacktraceAgent 'Can-Redefine-Classes: true' -# @run build RedefineMethodInBacktraceTarget RedefineMethodInBacktraceApp -# @run shell RedefineMethodInBacktrace.sh -# - -if [ "${TESTJAVA}" = "" ] -then - echo "TESTJAVA not set. Test cannot execute. Failed." - exit 1 -fi - -if [ "${COMPILEJAVA}" = "" ] -then - COMPILEJAVA="${TESTJAVA}" -fi -echo "COMPILEJAVA=${COMPILEJAVA}" - -if [ "${TESTSRC}" = "" ] -then - echo "TESTSRC not set. Test cannot execute. Failed." - exit 1 -fi - -if [ "${TESTCLASSES}" = "" ] -then - echo "TESTCLASSES not set. Test cannot execute. Failed." - exit 1 -fi - -JAVAC="${COMPILEJAVA}"/bin/javac -JAVA="${TESTJAVA}"/bin/java - -cp "${TESTSRC}"/RedefineMethodInBacktraceTarget_2.java \ - RedefineMethodInBacktraceTarget.java -"${JAVAC}" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . RedefineMethodInBacktraceTarget.java - -cp "${TESTSRC}"/RedefineMethodInBacktraceTargetB_2.java \ - RedefineMethodInBacktraceTargetB.java -"${JAVAC}" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d . RedefineMethodInBacktraceTargetB.java - -"${JAVA}" ${TESTVMOPTS} ${TESTJAVAOPTS} -javaagent:RedefineMethodInBacktraceAgent.jar \ - -XX:+AllowRedefinitionToAddDeleteMethods \ - -classpath "${TESTCLASSES}" RedefineMethodInBacktraceApp > output.log 2>&1 -RUN_RESULT=$? - -if [ $RUN_RESULT != 0 ]; then - echo "FAIL: the run failed with exit code '$RUN_RESULT'" - exit $RUN_RESULT -fi - -cat output.log - -MESG="Test failed" -grep "$MESG" output.log -result=$? -if [ "$result" = 0 ]; then - echo "FAIL: found '$MESG' in the test output" - result=1 -else - echo "PASS: did NOT find '$MESG' in the test output" - result=0 -fi - -exit $result diff --git a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceAgent.java b/test/jdk/java/lang/instrument/RedefineMethodInBacktraceAgent.java deleted file mode 100644 index a4cc182bf2373..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceAgent.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2013, 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.lang.instrument.Instrumentation; - -public class RedefineMethodInBacktraceAgent { - private static Instrumentation instrumentation; - - private RedefineMethodInBacktraceAgent() {} - - public static void premain(String agentArgs, Instrumentation inst) { - System.out.println("Hello from RedefineMethodInBacktraceAgent!"); - System.out.println("isRedefineClassesSupported()=" + - inst.isRedefineClassesSupported()); - - instrumentation = inst; - } - - public static Instrumentation getInstrumentation() { - return instrumentation; - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceApp.java b/test/jdk/java/lang/instrument/RedefineMethodInBacktraceApp.java deleted file mode 100644 index d406ae0ceedf2..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceApp.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2013, 2015, 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 com.sun.management.DiagnosticCommandMBean; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.lang.instrument.ClassDefinition; -import java.lang.management.ManagementFactory; -import java.lang.management.ThreadInfo; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.concurrent.CountDownLatch; -import javax.management.JMX; -import javax.management.ObjectName; - -/** - * When an exception is thrown, the JVM collects just enough information - * about the stack trace to be able to create a full fledged stack trace - * (StackTraceElement[]). The backtrace contains this information and the - * JVM must make sure that the data in the backtrace is still usable after - * a class redefinition. - * - * After the PermGen removal there was a bug when the last reference to a Method - * was in the backtrace. The class of the method was kept alive, because of the - * mirror stored in the backtrace, but the old versions of the redefined method - * could be freed, since class redefinition didn't know about the backtraces. - */ -public class RedefineMethodInBacktraceApp { - static boolean failed = false; - - public static void main(String args[]) throws Exception { - System.out.println("Hello from RedefineMethodInBacktraceApp!"); - new RedefineMethodInBacktraceApp().doTest(); - - if (failed) { - throw new Exception("ERROR: RedefineMethodInBacktraceApp failed."); - } - } - - public static CountDownLatch stop = new CountDownLatch(1); - public static CountDownLatch called = new CountDownLatch(1); - - private void doTest() throws Exception { - doMethodInBacktraceTest(); - doMethodInBacktraceTestB(); - } - - private void doMethodInBacktraceTest() throws Exception { - Throwable t1 = getThrowableFromMethodToRedefine(); - Throwable t2 = getThrowableFromMethodToDelete(); - - doRedefine(RedefineMethodInBacktraceTarget.class); - - doClassUnloading(); - - System.out.println("checking backtrace for throwable from methodToRedefine"); - touchRedefinedMethodInBacktrace(t1); - - System.out.println("checking backtrace for throwable from methodToDelete"); - touchRedefinedMethodInBacktrace(t2); - } - - private void doMethodInBacktraceTestB() throws Exception { - // Start a thread which blocks in method - Thread t = new Thread(RedefineMethodInBacktraceTargetB::methodToRedefine); - t.setDaemon(true); - t.start(); - - // Wait here until the new thread is in the method we want to redefine - called.await(); - - // Now redefine the class while the method is still on the stack of the new thread - doRedefine(RedefineMethodInBacktraceTargetB.class); - - // Do thread dumps in two different ways (to exercise different code paths) - // while the old class is still on the stack - - ThreadInfo[] tis = ManagementFactory.getThreadMXBean().dumpAllThreads(false, false); - for(ThreadInfo ti : tis) { - System.out.println(ti); - } - - String[] threadPrintArgs = {}; - Object[] dcmdArgs = {threadPrintArgs}; - String[] signature = {String[].class.getName()}; - System.out.println(ManagementFactory.getPlatformMBeanServer().invoke( - ObjectName.getInstance("com.sun.management:type=DiagnosticCommand"), - "threadPrint", - dcmdArgs, - signature)); - - // release the thread - stop.countDown(); - } - - private static Throwable getThrowableFromMethodToRedefine() throws Exception { - Class c = - RedefineMethodInBacktraceTarget.class; - Method method = c.getMethod("methodToRedefine"); - - Throwable thrownFromMethodToRedefine = null; - try { - method.invoke(null); - } catch (InvocationTargetException e) { - thrownFromMethodToRedefine = e.getCause(); - if (!(thrownFromMethodToRedefine instanceof RuntimeException)) { - throw e; - } - } catch (Exception e) { - e.printStackTrace(); - System.out.println("\nTest failed: unexpected exception: " + e.toString()); - failed = true; - } - method = null; - c = null; - - return thrownFromMethodToRedefine; - } - - private static Throwable getThrowableFromMethodToDelete() throws Exception { - Class c = - RedefineMethodInBacktraceTarget.class; - Method method = c.getMethod("callMethodToDelete"); - - Throwable thrownFromMethodToDelete = null; - try { - method.invoke(null); - } catch (InvocationTargetException e) { - thrownFromMethodToDelete = e.getCause(); - if (!(thrownFromMethodToDelete instanceof RuntimeException)) { - throw e; - } - } catch (Exception e) { - e.printStackTrace(); - System.out.println("\nTest failed: unexpected exception: " + e.toString()); - failed = true; - } - return thrownFromMethodToDelete; - } - - - private static void doClassUnloading() { - // This will clean out old, unused redefined methods. - System.gc(); - } - - private static void touchRedefinedMethodInBacktrace(Throwable throwable) { - throwable.printStackTrace(); - // Make sure that we can convert the backtrace, which is referring to - // the redefined method, to a StrackTraceElement[] without crashing. - StackTraceElement[] stackTrace = throwable.getStackTrace(); - for (int i = 0; i < stackTrace.length; i++) { - StackTraceElement frame = stackTrace[i]; - if (frame.getClassName() == null) { - System.out.println("\nTest failed: trace[" + i + "].getClassName() returned null"); - failed = true; - } - if (frame.getMethodName() == null) { - System.out.println("\nTest failed: trace[" + i + "].getMethodName() returned null"); - failed = true; - } - } - } - - private static void doRedefine(Class clazz) throws Exception { - // Load the second version of this class. - File f = new File(clazz.getName() + ".class"); - System.out.println("Reading test class from " + f.getAbsolutePath()); - InputStream redefineStream = new FileInputStream(f); - - byte[] redefineBuffer = NamedBuffer.loadBufferFromStream(redefineStream); - - ClassDefinition redefineParamBlock = new ClassDefinition( - clazz, redefineBuffer); - - RedefineMethodInBacktraceAgent.getInstrumentation().redefineClasses( - new ClassDefinition[] {redefineParamBlock}); - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTarget.java b/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTarget.java deleted file mode 100644 index d1c1e33078d15..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTarget.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2013, 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. - */ - -/** - * The first version of this class. The second version is in - * RedefineMethodInBacktraceTarget_2.java. - */ -public class RedefineMethodInBacktraceTarget { - public static void methodToRedefine() { - throw new RuntimeException("Test exception"); - } - - public static void callMethodToDelete() { - methodToDelete(); - } - - private static void methodToDelete() { - throw new RuntimeException("Test exception in methodToDelete"); - } - -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTargetB.java b/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTargetB.java deleted file mode 100644 index d7fb6f7857a48..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTargetB.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2013, 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. - */ - -/** - * The first version of this class. The second version is in - * RedefineMethodInBacktraceTargetB_2.java. - */ -public class RedefineMethodInBacktraceTargetB { - public static void methodToRedefine() { - try { - // signal that we are here - RedefineMethodInBacktraceApp.called.countDown(); - - // wait until test is done - RedefineMethodInBacktraceApp.stop.await(); - } catch (InterruptedException ex) { - // ignore, test will fail - } - } - - public static void callMethodToDelete() { - try { - // signal that we are here - RedefineMethodInBacktraceApp.called.countDown(); - - // wait until test is done - RedefineMethodInBacktraceApp.stop.await(); - } catch (InterruptedException ex) { - // ignore, test will fail - } - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTargetB_2.java b/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTargetB_2.java deleted file mode 100644 index 33c6e7103e213..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTargetB_2.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2013, 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. - */ - -/** - * This is the second version of this class. The first version is in - * RedefineMethodInBacktraceTargetB.java. - */ -public class RedefineMethodInBacktraceTargetB { - public static void methodToRedefine() { - } - - public static void callMethodToDelete() { - } -} diff --git a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTarget_2.java b/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTarget_2.java deleted file mode 100644 index a7d9dc666a198..0000000000000 --- a/test/jdk/java/lang/instrument/RedefineMethodInBacktraceTarget_2.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2013, 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. - */ - -/** - * This is the second version of this class. The first version is in - * RedefineMethodInBacktraceTarget.java. - */ -public class RedefineMethodInBacktraceTarget { - public static void methodToRedefine() { - throw new RuntimeException("Test exception 2"); - } - - public static void callMethodToDelete() { - throw new RuntimeException("Test exception 2 in callMethodToDelete"); - } -}