From 0dfd4203df3d38afcc4ca08f0ff4fdbb6c90c780 Mon Sep 17 00:00:00 2001 From: "tongbao.ztb" Date: Wed, 6 Mar 2019 20:02:55 +0800 Subject: [PATCH] [Misc] Print the young generation histogram once after parnew gc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: - Port D65580 to dragonwell - Print the young generation histogram once after parnew gc with the manageable flag: PrintYoungGenHistoAfterParNewGC Test Plan: hotspot/test/gc/parNew/testPrintYoungGenHisto.sh Reviewers: 传胜 Differential Revision: https://aone.alibaba-inc.com/code/D849729 --- .../parNew/parNewGeneration.cpp | 10 +++- src/share/vm/memory/heapInspection.cpp | 13 ++++- src/share/vm/runtime/globals_ext.hpp | 4 ++ .../TestPrintYoungGenHistoAfterParNewGC.java | 54 ++++++++++++++++++ test/gc/parNew/testPrintYoungGenHisto.sh | 56 +++++++++++++++++++ 5 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 test/gc/parNew/TestPrintYoungGenHistoAfterParNewGC.java create mode 100644 test/gc/parNew/testPrintYoungGenHisto.sh diff --git a/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp b/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp index 8ef1bd2cd..80c355c96 100644 --- a/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp +++ b/src/share/vm/gc_implementation/parNew/parNewGeneration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -40,6 +40,7 @@ #include "memory/genOopClosures.inline.hpp" #include "memory/generation.hpp" #include "memory/generation.inline.hpp" +#include "memory/heapInspection.hpp" #include "memory/referencePolicy.hpp" #include "memory/resourceArea.hpp" #include "memory/sharedHeap.hpp" @@ -1096,6 +1097,13 @@ void ParNewGeneration::collect(bool full, _gc_timer->register_gc_end(); + // print the young generation histo once after parnew gc then reset the PrintYoungGenHistoAfterParNewGC + if (PrintYoungGenHistoAfterParNewGC) { + HeapInspection inspect(false, false, false, NULL); + inspect.heap_inspection(tty); + PrintYoungGenHistoAfterParNewGC = false; + } + gc_tracer.report_gc_end(_gc_timer->gc_end(), _gc_timer->time_partitions()); } diff --git a/src/share/vm/memory/heapInspection.cpp b/src/share/vm/memory/heapInspection.cpp index cc8f4fc06..5e3b5dec2 100644 --- a/src/share/vm/memory/heapInspection.cpp +++ b/src/share/vm/memory/heapInspection.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -26,6 +26,7 @@ #include "classfile/classLoaderData.hpp" #include "gc_interface/collectedHeap.hpp" #include "memory/genCollectedHeap.hpp" +#include "memory/generation.hpp" #include "memory/heapInspection.hpp" #include "memory/resourceArea.hpp" #include "runtime/os.hpp" @@ -487,8 +488,14 @@ size_t HeapInspection::populate_table(KlassInfoTable* cit, BoolObjectClosure *fi ResourceMark rm; RecordInstanceClosure ric(cit, filter); - Universe::heap()->object_iterate(&ric); - return ric.missed_count(); + if (PrintYoungGenHistoAfterParNewGC && UseParNewGC) { + assert(GenCollectedHeap::heap()->n_gens() == 2, "When using ParNew GC, there are only two generations"); + GenCollectedHeap::heap()->get_gen(0)->object_iterate(&ric); + return ric.missed_count(); + } else { + Universe::heap()->object_iterate(&ric); + return ric.missed_count(); + } } void HeapInspection::heap_inspection(outputStream* st) { diff --git a/src/share/vm/runtime/globals_ext.hpp b/src/share/vm/runtime/globals_ext.hpp index fe8227743..2d290e27c 100644 --- a/src/share/vm/runtime/globals_ext.hpp +++ b/src/share/vm/runtime/globals_ext.hpp @@ -27,6 +27,10 @@ // globals_extension.hpp extension #define AJVM_FLAGS(develop, develop_pd, product, product_pd, diagnostic, experimental, notproduct, manageable, product_rw, lp64_product) \ + \ + manageable(bool, PrintYoungGenHistoAfterParNewGC, false, \ + "print the young generation class histogram after parNew GC") \ + //add new AJVM specific flags here diff --git a/test/gc/parNew/TestPrintYoungGenHistoAfterParNewGC.java b/test/gc/parNew/TestPrintYoungGenHistoAfterParNewGC.java new file mode 100644 index 000000000..7e3fbe771 --- /dev/null +++ b/test/gc/parNew/TestPrintYoungGenHistoAfterParNewGC.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 Alibaba Group Holding Limited. 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. Alibaba designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +import java.util.ArrayList; + +public class TestPrintYoungGenHistoAfterParNewGC { + public static void main(String []args) { + int count = 0; + ArrayList list = new ArrayList(); + for (int i = 0; ; i++) { + byte[] data = new byte[1024]; + list.add(data); + InnerA aa = new InnerA(); + InnerA bb = new InnerA(); + if (i % 100000 == 0) { + count++; + list.clear(); + if (count > 1000000) { + break; + } + } + } + } + + public static class InnerA { + String name; + int id; + String number; + public InnerA() { + name = "hello"; + id = 23333; + number = "010110"; + } + } +} diff --git a/test/gc/parNew/testPrintYoungGenHisto.sh b/test/gc/parNew/testPrintYoungGenHisto.sh new file mode 100644 index 000000000..fbdcf0a34 --- /dev/null +++ b/test/gc/parNew/testPrintYoungGenHisto.sh @@ -0,0 +1,56 @@ +#!/bin/sh + +# +# Copyright (c) 2019 Alibaba Group Holding Limited. 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. Alibaba designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# @test +# @summary Test for the young generation histogram once after a parnew gc +# @build TestPrintYoungGenHistoAfterParNewGC +# @run shell testPrintYoungGenHisto.sh + +TMP1=tmp_$$ + +# testing set the VM flag PrintYoungGenHistoAfterParNewGC on the fly by using vm tools(jinfo -flag) +printYongGenHistoTest() { + echo "Tetsting setting the PrintYoungGenHistoAfterParNewGC flag by using the vm tools(jinfo -flag)" + ${TESTJAVA}/bin/java ${TESTVMOPTS} -Xmx1g -Xmn500m -verbose:gc -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails \ + -cp ${TESTCLASSES} TestPrintYoungGenHistoAfterParNewGC >${TMP1} 2>&1 & + PID=$(ps aux | grep TestPrintYoungGenHistoAfterParNewGC | grep -v "grep" | awk '{print $2}') + echo "hello" + echo $PID + ${TESTJAVA}/bin/jinfo -flag +PrintYoungGenHistoAfterParNewGC $PID + sleep 1s + cat ${TMP1} + RESULT=$(cat ${TMP1} | grep -o 'Total' | wc -l) + if [ $RESULT -gt 0 ] + then echo "--- passed as expected " + else + echo "--- failed" + exit 1 + fi + + kill -9 $PID +} + +printYongGenHistoTest + + +rm ${TMP1} -- GitLab