Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8271008: appcds/*/MethodHandlesAsCollectorTest.java tests time out be…
…cause of excessive GC (CodeCache GC Threshold) in loom

Reviewed-by: thartmann, eosterlund
  • Loading branch information
coleenp committed Feb 22, 2022
1 parent ab6d8e6 commit 022d807
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
29 changes: 13 additions & 16 deletions src/hotspot/share/code/codeCache.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
Expand Down Expand Up @@ -487,7 +487,7 @@ CodeBlob* CodeCache::next_blob(CodeHeap* heap, CodeBlob* cb) {
*/
CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool handle_alloc_failure, int orig_code_blob_type) {
// Possibly wakes up the sweeper thread.
NMethodSweeper::report_allocation(code_blob_type);
NMethodSweeper::report_allocation();
assert_locked_or_safepoint(CodeCache_lock);
assert(size > 0, "Code cache allocation request must be > 0 but is %d", size);
if (size <= 0) {
Expand All @@ -512,7 +512,7 @@ CodeBlob* CodeCache::allocate(int size, int code_blob_type, bool handle_alloc_fa
// Fallback solution: Try to store code in another code heap.
// NonNMethod -> MethodNonProfiled -> MethodProfiled (-> MethodNonProfiled)
// Note that in the sweeper, we check the reverse_free_ratio of the code heap
// and force stack scanning if less than 10% of the code heap are free.
// and force stack scanning if less than 10% of the entire code cache are free.
int type = code_blob_type;
switch (type) {
case CodeBlobType::NonNMethod:
Expand Down Expand Up @@ -889,20 +889,17 @@ size_t CodeCache::max_capacity() {
return max_cap;
}

/**
* Returns the reverse free ratio. E.g., if 25% (1/4) of the code heap
* is free, reverse_free_ratio() returns 4.
*/
double CodeCache::reverse_free_ratio(int code_blob_type) {
CodeHeap* heap = get_code_heap(code_blob_type);
if (heap == NULL) {
return 0;
}

double unallocated_capacity = MAX2((double)heap->unallocated_capacity(), 1.0); // Avoid division by 0;
double max_capacity = (double)heap->max_capacity();
double result = max_capacity / unallocated_capacity;
assert (max_capacity >= unallocated_capacity, "Must be");
// Returns the reverse free ratio. E.g., if 25% (1/4) of the code cache
// is free, reverse_free_ratio() returns 4.
// Since code heap for each type of code blobs falls forward to the next
// type of code heap, return the reverse free ratio for the entire
// code cache.
double CodeCache::reverse_free_ratio() {
double unallocated = MAX2((double)unallocated_capacity(), 1.0); // Avoid division by 0;
double max = (double)max_capacity();
double result = max / unallocated;
assert (max >= unallocated, "Must be");
assert (result >= 1.0, "reverse_free_ratio must be at least 1. It is %f", result);
return result;
}
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/code/codeCache.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
Expand Down Expand Up @@ -211,7 +211,7 @@ class CodeCache : AllStatic {
static size_t unallocated_capacity();
static size_t max_capacity();

static double reverse_free_ratio(int code_blob_type);
static double reverse_free_ratio();

static void clear_inline_caches(); // clear all inline caches
static void cleanup_inline_caches(); // clean unloaded/zombie nmethods from inline caches
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/compiler/compilationPolicy.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 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
Expand Down Expand Up @@ -315,7 +315,7 @@ double CompilationPolicy::threshold_scale(CompLevel level, int feedback_k) {
// The main intention is to keep enough free space for C2 compiled code
// to achieve peak performance if the code cache is under stress.
if (CompilerConfig::is_tiered() && !CompilationModeFlag::disable_intermediate() && is_c1_compile(level)) {
double current_reverse_free_ratio = CodeCache::reverse_free_ratio(CodeCache::get_code_blob_type(level));
double current_reverse_free_ratio = CodeCache::reverse_free_ratio();
if (current_reverse_free_ratio > _increase_threshold_at_ratio) {
k *= exp(current_reverse_free_ratio - _increase_threshold_at_ratio);
}
Expand Down
13 changes: 6 additions & 7 deletions src/hotspot/share/runtime/sweeper.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
Expand Down Expand Up @@ -229,19 +229,19 @@ void NMethodSweeper::sweeper_loop() {
/**
* Wakes up the sweeper thread to sweep if code cache space runs low
*/
void NMethodSweeper::report_allocation(int code_blob_type) {
if (should_start_aggressive_sweep(code_blob_type)) {
void NMethodSweeper::report_allocation() {
if (should_start_aggressive_sweep()) {
MonitorLocker waiter(CodeSweeper_lock, Mutex::_no_safepoint_check_flag);
_should_sweep = true;
CodeSweeper_lock->notify();
}
}

bool NMethodSweeper::should_start_aggressive_sweep(int code_blob_type) {
bool NMethodSweeper::should_start_aggressive_sweep() {
// Makes sure that we do not invoke the sweeper too often during startup.
double start_threshold = 100.0 / (double)StartAggressiveSweepingAt;
double aggressive_sweep_threshold = MAX2(start_threshold, 1.1);
return (CodeCache::reverse_free_ratio(code_blob_type) >= aggressive_sweep_threshold);
return (CodeCache::reverse_free_ratio() >= aggressive_sweep_threshold);
}

/**
Expand Down Expand Up @@ -546,8 +546,7 @@ void NMethodSweeper::possibly_flush(nmethod* nm) {
// ReservedCodeCacheSize
int reset_val = hotness_counter_reset_val();
int time_since_reset = reset_val - nm->hotness_counter();
int code_blob_type = CodeCache::get_code_blob_type(nm);
double threshold = -reset_val + (CodeCache::reverse_free_ratio(code_blob_type) * NmethodSweepActivity);
double threshold = -reset_val + (CodeCache::reverse_free_ratio() * NmethodSweepActivity);
// The less free space in the code cache we have - the bigger reverse_free_ratio() is.
// I.e., 'threshold' increases with lower available space in the code cache and a higher
// NmethodSweepActivity. If the current hotness counter - which decreases from its initial
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/runtime/sweeper.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
Expand Down Expand Up @@ -113,11 +113,11 @@ class NMethodSweeper : public AllStatic {

static CodeBlobClosure* prepare_mark_active_nmethods();
static void sweeper_loop();
static bool should_start_aggressive_sweep(int code_blob_type);
static bool should_start_aggressive_sweep();
static void force_sweep();
static int hotness_counter_reset_val();
static void report_state_change(nmethod* nm);
static void report_allocation(int code_blob_type); // Possibly start the sweeper thread.
static void report_allocation(); // Possibly start the sweeper thread.
static void possibly_flush(nmethod* nm);
static void print(outputStream* out); // Printing/debugging
static void print() { print(tty); }
Expand Down

1 comment on commit 022d807

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.