Skip to content
Permalink
Browse files
8269188: [BACKOUT] Remove CodeCache::mark_for_evol_deoptimization() m…
…ethod

Reviewed-by: dholmes, sspitsyn
  • Loading branch information
coleenp committed Jun 23, 2021
1 parent f2e690e commit 52d5d1b3617731bf312aa5813bf7e78ca4dacb00
@@ -1077,6 +1077,12 @@ void CodeCache::old_nmethods_do(MetadataClosure* f) {
log_debug(redefine, class, nmethod)("Walked %d nmethods for mark_on_stack", length);
}

// Just marks the methods in this class as needing deoptimization
void CodeCache::mark_for_evol_deoptimization(InstanceKlass* dependee) {
assert(SafepointSynchronize::is_at_safepoint(), "Can only do this at a safepoint!");
}


// Walk compiled methods and mark dependent methods for deoptimization.
int CodeCache::mark_dependents_for_evol_deoptimization() {
assert(SafepointSynchronize::is_at_safepoint(), "Can only do this at a safepoint!");
@@ -271,6 +271,7 @@ class CodeCache : AllStatic {

// RedefineClasses support
// Flushing and deoptimization in case of evolution
static void mark_for_evol_deoptimization(InstanceKlass* dependee);
static int mark_dependents_for_evol_deoptimization();
static void mark_all_nmethods_for_evol_deoptimization();
static void flush_evol_dependents();
@@ -312,6 +312,7 @@ bool JvmtiExport::_can_modify_any_class = fals
bool JvmtiExport::_can_walk_any_space = false;

uint64_t JvmtiExport::_redefinition_count = 0;
bool JvmtiExport::_all_dependencies_are_recorded = false;

//
// field access management
@@ -187,6 +187,13 @@ class JvmtiExport : public AllStatic {
inline static void increment_redefinition_count() {
JVMTI_ONLY(_redefinition_count++;)
}
// Flag to indicate if the compiler has recorded all dependencies. When the
// can_redefine_classes capability is enabled in the OnLoad phase then the compiler
// records all dependencies from startup. However if the capability is first
// enabled some time later then the dependencies recorded by the compiler
// are incomplete. This flag is used by RedefineClasses to know if the
// dependency information is complete or not.
static bool _all_dependencies_are_recorded;

static void post_method_exit_inner(JavaThread* thread,
methodHandle& mh,
@@ -207,6 +214,14 @@ class JvmtiExport : public AllStatic {
NOT_JVMTI(return 0);
}

inline static bool all_dependencies_are_recorded() {
return _all_dependencies_are_recorded;
}

inline static void set_all_dependencies_are_recorded(bool on) {
_all_dependencies_are_recorded = (on != 0);
}

// Add read edges to the unnamed modules of the bootstrap and app class loaders
static void add_default_read_edges(Handle h_module, TRAPS) NOT_JVMTI_RETURN;

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@@ -328,6 +328,13 @@ void JvmtiManageCapabilities::update() {
RewriteFrequentPairs = false;
}

// If can_redefine_classes is enabled in the onload phase then we know that the
// dependency information recorded by the compiler is complete.
if ((avail.can_redefine_classes || avail.can_retransform_classes) &&
JvmtiEnv::get_phase() == JVMTI_PHASE_ONLOAD) {
JvmtiExport::set_all_dependencies_are_recorded(true);
}

JvmtiExport::set_can_get_source_debug_extension(avail.can_get_source_debug_extension);
JvmtiExport::set_can_maintain_original_method_order(avail.can_maintain_original_method_order);
JvmtiExport::set_can_post_interpreter_events(interp_events);
@@ -4068,17 +4068,56 @@ void VM_RedefineClasses::transfer_old_native_function_registrations(InstanceKlas
transfer.transfer_registrations(_matching_old_methods, _matching_methods_length);
}

// Deoptimize all compiled code that depends on the classes redefined.
// Deoptimize all compiled code that depends on this class.
//
// If the can_redefine_classes capability is obtained in the onload
// phase then the compiler has recorded all dependencies from startup.
// In that case we need only deoptimize and throw away all compiled code
// that depends on the class.
//
// If can_redefine_classes is obtained sometime after the onload
// phase then the dependency information may be incomplete. In that case
// the first call to RedefineClasses causes all compiled code to be
// thrown away. As can_redefine_classes has been obtained then
// all future compilations will record dependencies so second and
// subsequent calls to RedefineClasses need only throw away code
// that depends on the class.
//

// First step is to walk the code cache for each class redefined and mark
// dependent methods. Wait until all classes are processed to deoptimize everything.
void VM_RedefineClasses::mark_dependent_code(InstanceKlass* ik) {
assert_locked_or_safepoint(Compile_lock);

// All dependencies have been recorded from startup or this is a second or
// subsequent use of RedefineClasses
if (JvmtiExport::all_dependencies_are_recorded()) {
CodeCache::mark_for_evol_deoptimization(ik);
}
}

void VM_RedefineClasses::flush_dependent_code() {
assert(SafepointSynchronize::is_at_safepoint(), "sanity check");

int deopt = CodeCache::mark_dependents_for_evol_deoptimization();
log_debug(redefine, class, nmethod)("Marked %d dependent nmethods for deopt", deopt);
bool deopt_needed;

// This is the first redefinition, mark all the nmethods for deoptimization
if (!JvmtiExport::all_dependencies_are_recorded()) {
log_debug(redefine, class, nmethod)("Marked all nmethods for deopt");
CodeCache::mark_all_nmethods_for_evol_deoptimization();
deopt_needed = true;
} else {
int deopt = CodeCache::mark_dependents_for_evol_deoptimization();
log_debug(redefine, class, nmethod)("Marked %d dependent nmethods for deopt", deopt);
deopt_needed = (deopt != 0);
}

if (deopt != 0) {
if (deopt_needed) {
CodeCache::flush_evol_dependents();
}

// From now on we know that the dependency information is complete
JvmtiExport::set_all_dependencies_are_recorded(true);
}

void VM_RedefineClasses::compute_added_deleted_matching_methods() {
@@ -4182,6 +4221,9 @@ void VM_RedefineClasses::redefine_single_class(Thread* current, jclass the_jclas
JvmtiBreakpoints& jvmti_breakpoints = JvmtiCurrentBreakpoints::get_jvmti_breakpoints();
jvmti_breakpoints.clearall_in_class_at_safepoint(the_class);

// Mark all compiled code that depends on this class
mark_dependent_code(the_class);

_old_methods = the_class->methods();
_new_methods = scratch_class->methods();
_the_class = the_class;
@@ -493,6 +493,7 @@ class VM_RedefineClasses: public VM_Operation {
constantPoolHandle scratch_cp, int scratch_cp_length, TRAPS);

void flush_dependent_code();
void mark_dependent_code(InstanceKlass* ik);

// lock classes to redefine since constant pool merging isn't thread safe.
void lock_classes();

1 comment on commit 52d5d1b

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 52d5d1b Jun 23, 2021

Please sign in to comment.