From 76398c84007862bdf07cea6be792eca50eec9edd Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Tue, 1 Mar 2022 15:28:21 +0000 Subject: [PATCH] 8279573: compiler/codecache/CodeCacheFullCountTest.java fails with "RuntimeException: the value of full_count is wrong." Reviewed-by: thartmann, eosterlund --- src/hotspot/share/code/codeCache.cpp | 6 +++--- src/hotspot/share/memory/heap.hpp | 5 +++-- .../jtreg/compiler/codecache/CodeCacheFullCountTest.java | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/code/codeCache.cpp b/src/hotspot/share/code/codeCache.cpp index 8e9c866500e..a8e9e2fb42b 100644 --- a/src/hotspot/share/code/codeCache.cpp +++ b/src/hotspot/share/code/codeCache.cpp @@ -1238,9 +1238,9 @@ void CodeCache::report_codemem_full(int code_blob_type, bool print) { CodeHeap* heap = get_code_heap(code_blob_type); assert(heap != NULL, "heap is null"); - heap->report_full(); + int full_count = heap->report_full(); - if ((heap->full_count() == 1) || print) { + if ((full_count == 1) || print) { // Not yet reported for this heap, report if (SegmentedCodeCache) { ResourceMark rm; @@ -1277,7 +1277,7 @@ void CodeCache::report_codemem_full(int code_blob_type, bool print) { tty->print("%s", s.as_string()); } - if (heap->full_count() == 1) { + if (full_count == 1) { if (PrintCodeHeapAnalytics) { CompileBroker::print_heapinfo(tty, "all", 4096); // details, may be a lot! } diff --git a/src/hotspot/share/memory/heap.hpp b/src/hotspot/share/memory/heap.hpp index 7405cfe5943..c8cc2ae8dc6 100644 --- a/src/hotspot/share/memory/heap.hpp +++ b/src/hotspot/share/memory/heap.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 @@ -28,6 +28,7 @@ #include "code/codeBlob.hpp" #include "memory/allocation.hpp" #include "memory/virtualspace.hpp" +#include "runtime/atomic.hpp" #include "utilities/macros.hpp" // Blocks @@ -216,7 +217,7 @@ class CodeHeap : public CHeapObj { int adapter_count() { return _adapter_count; } void set_adapter_count(int count) { _adapter_count = count; } int full_count() { return _full_count; } - void report_full() { _full_count++; } + int report_full() { return Atomic::add(&_full_count, 1); } private: size_t heap_unallocated_capacity() const; diff --git a/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java b/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java index 1fee39144ff..8646c5834c6 100644 --- a/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java +++ b/test/hotspot/jtreg/compiler/codecache/CodeCacheFullCountTest.java @@ -55,7 +55,7 @@ public class CodeCacheFullCountTest { public static void runTest() throws Throwable { ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( - "-XX:ReservedCodeCacheSize=2496k", "-XX:-UseCodeCacheFlushing", "CodeCacheFullCountTest", "WasteCodeCache"); + "-XX:ReservedCodeCacheSize=2496k", "-XX:-UseCodeCacheFlushing", "-XX:-MethodFlushing", "CodeCacheFullCountTest", "WasteCodeCache"); OutputAnalyzer oa = ProcessTools.executeProcess(pb); oa.shouldHaveExitValue(0); String stdout = oa.getStdout(); @@ -64,7 +64,7 @@ public class CodeCacheFullCountTest { Matcher stdoutMatcher = pattern.matcher(stdout); if (stdoutMatcher.find()) { int fullCount = Integer.parseInt(stdoutMatcher.group(1)); - if (fullCount != 1) { + if (fullCount == 0) { throw new RuntimeException("the value of full_count is wrong."); } } else {