Path: blob/master/src/hotspot/share/code/codeHeapState.hpp
40931 views
/*1* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2018, 2019 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#ifndef SHARE_CODE_CODEHEAPSTATE_HPP26#define SHARE_CODE_CODEHEAPSTATE_HPP2728#include "memory/heap.hpp"29#include "utilities/debug.hpp"30#include "utilities/globalDefinitions.hpp"31#include "utilities/ostream.hpp"3233class CodeHeapState : public CHeapObj<mtCode> {3435public:36enum compType {37noComp = 0, // must be! due to initialization by memset to zero38c1,39c2,40jvmci,41lastComp42};4344enum blobType {45noType = 0, // must be! due to initialization by memset to zero46// The nMethod_* values correspond to the CompiledMethod enum values.47// We can't use the CompiledMethod values 1:1 because we depend on noType == 0.48nMethod_inconstruction, // under construction. Very soon, the type will transition to "in_use".49// can't be observed while holding Compile_lock and CodeCache_lock simultaneously.50// left in here for completeness (and to document we spent a thought).51nMethod_inuse, // executable. This is the "normal" state for a nmethod.52nMethod_notused, // assumed inactive, marked not entrant. Could be revived if necessary.53nMethod_notentrant, // no new activations allowed, marked for deoptimization. Old activations may still exist.54// Will transition to "zombie" after all activations are gone.55nMethod_zombie, // No more activations exist, ready for purge (remove from code cache).56nMethod_unloaded, // No activations exist, should not be called. Transient state on the way to "zombie".57nMethod_alive = nMethod_notentrant, // Combined state: nmethod may have activations, thus can't be purged.58nMethod_dead = nMethod_zombie, // Combined state: nmethod does not have any activations.59runtimeStub = nMethod_unloaded + 1,60ricochetStub,61deoptimizationStub,62uncommonTrapStub,63exceptionStub,64safepointStub,65adapterBlob,66mh_adapterBlob,67bufferBlob,68lastType69};7071private:72static void prepare_StatArray(outputStream* out, size_t nElem, size_t granularity, const char* heapName);73static void prepare_FreeArray(outputStream* out, unsigned int nElem, const char* heapName);74static void prepare_TopSizeArray(outputStream* out, unsigned int nElem, const char* heapName);75static void prepare_SizeDistArray(outputStream* out, unsigned int nElem, const char* heapName);76static void discard_StatArray(outputStream* out);77static void discard_FreeArray(outputStream* out);78static void discard_TopSizeArray(outputStream* out);79static void discard_SizeDistArray(outputStream* out);8081static void update_SizeDistArray(outputStream* out, unsigned int len);8283static const char* get_heapName(CodeHeap* heap);84static unsigned int findHeapIndex(outputStream* out, const char* heapName);85static void get_HeapStatGlobals(outputStream* out, const char* heapName);86static void set_HeapStatGlobals(outputStream* out, const char* heapName);8788static void printBox(outputStream* out, const char border, const char* text1, const char* text2);89static void print_blobType_legend(outputStream* out);90static void print_space_legend(outputStream* out);91static void print_age_legend(outputStream* out);92static void print_blobType_single(outputStream *ast, u2 /* blobType */ type);93static void print_count_single(outputStream *ast, unsigned short count);94static void print_space_single(outputStream *ast, unsigned short space);95static void print_age_single(outputStream *ast, unsigned int age);96static void print_line_delim(outputStream* out, bufferedStream *sst, char* low_bound, unsigned int ix, unsigned int gpl);97static void print_line_delim(outputStream* out, outputStream *sst, char* low_bound, unsigned int ix, unsigned int gpl);98static blobType get_cbType(CodeBlob* cb);99static bool blob_access_is_safe(CodeBlob* this_blob);100static bool nmethod_access_is_safe(nmethod* nm);101static bool holding_required_locks();102103public:104static void discard(outputStream* out, CodeHeap* heap);105static void aggregate(outputStream* out, CodeHeap* heap, size_t granularity);106static void print_usedSpace(outputStream* out, CodeHeap* heap);107static void print_freeSpace(outputStream* out, CodeHeap* heap);108static void print_count(outputStream* out, CodeHeap* heap);109static void print_space(outputStream* out, CodeHeap* heap);110static void print_age(outputStream* out, CodeHeap* heap);111static void print_names(outputStream* out, CodeHeap* heap);112};113114//----------------115// StatElement116//----------------117// Each analysis granule is represented by an instance of118// this StatElement struct. It collects and aggregates all119// information describing the allocated contents of the granule.120// Free (unallocated) contents is not considered (see FreeBlk for that).121// All StatElements of a heap segment are stored in the related StatArray.122// Current size: 40 bytes + 8 bytes class header.123class StatElement : public CHeapObj<mtCode> {124public:125// A note on ages: The compilation_id easily overflows unsigned short in large systems126unsigned int t1_age; // oldest compilation_id of tier1 nMethods.127unsigned int t2_age; // oldest compilation_id of tier2 nMethods.128unsigned int tx_age; // oldest compilation_id of inactive/not entrant nMethods.129unsigned short t1_space; // in units of _segment_size to "prevent" overflow130unsigned short t2_space; // in units of _segment_size to "prevent" overflow131unsigned short tx_space; // in units of _segment_size to "prevent" overflow132unsigned short dead_space; // in units of _segment_size to "prevent" overflow133unsigned short stub_space; // in units of _segment_size to "prevent" overflow134unsigned short t1_count;135unsigned short t2_count;136unsigned short tx_count;137unsigned short dead_count;138unsigned short stub_count;139CompLevel level; // optimization level (see globalDefinitions.hpp)140//---< replaced the correct enum typing with u2 to save space.141u2 compiler; // compiler which generated this blob. Type is CodeHeapState::compType142u2 type; // used only if granularity == segment_size. Type is CodeHeapState::blobType143};144145//-----------146// FreeBlk147//-----------148// Each free block in the code heap is represented by an instance149// of this FreeBlk struct. It collects all information we need to150// know about each free block.151// All FreeBlks of a heap segment are stored in the related FreeArray.152struct FreeBlk : public CHeapObj<mtCode> {153HeapBlock* start; // address of free block154unsigned int len; // length of free block155156unsigned int gap; // gap to next free block157unsigned int index; // sequential number of free block158unsigned short n_gapBlocks; // # used blocks in gap159bool stubs_in_gap; // The occupied space between this and the next free block contains (unmovable) stubs or blobs.160};161162//--------------163// TopSizeBlk164//--------------165// The n largest blocks in the code heap are represented in an instance166// of this TopSizeBlk struct. It collects all information we need to167// know about those largest blocks.168// All TopSizeBlks of a heap segment are stored in the related TopSizeArray.169struct TopSizeBlk : public CHeapObj<mtCode> {170HeapBlock* start; // address of block171const char* blob_name; // name of blob (mostly: name_and_sig of nmethod)172unsigned int len; // length of block, in _segment_size units. Will never overflow int.173174unsigned int index; // ordering index, 0 is largest block175// contains array index of next smaller block176// -1 indicates end of list177178unsigned int nm_size; // nmeethod total size (if nmethod, 0 otherwise)179int temperature; // nmethod temperature (if nmethod, 0 otherwise)180CompLevel level; // optimization level (see globalDefinitions.hpp)181u2 compiler; // compiler which generated this blob182u2 type; // blob type183};184185//---------------------------186// SizeDistributionElement187//---------------------------188// During CodeHeap analysis, each allocated code block is associated with a189// SizeDistributionElement according to its size. Later on, the array of190// SizeDistributionElements is used to print a size distribution bar graph.191// All SizeDistributionElements of a heap segment are stored in the related SizeDistributionArray.192struct SizeDistributionElement : public CHeapObj<mtCode> {193// Range is [rangeStart..rangeEnd).194unsigned int rangeStart; // start of length range, in _segment_size units.195unsigned int rangeEnd; // end of length range, in _segment_size units.196unsigned int lenSum; // length of block, in _segment_size units. Will never overflow int.197198unsigned int count; // number of blocks assigned to this range.199};200201//----------------202// CodeHeapStat203//----------------204// Because we have to deal with multiple CodeHeaps, we need to205// collect "global" information in a segment-specific way as well.206// Thats what the CodeHeapStat and CodeHeapStatArray are used for.207// Before a heap segment is processed, the contents of the CodeHeapStat208// element is copied to the global variables (get_HeapStatGlobals).209// When processing is done, the possibly modified global variables are210// copied back (set_HeapStatGlobals) to the CodeHeapStat element.211struct CodeHeapStat {212StatElement* StatArray;213struct FreeBlk* FreeArray;214struct TopSizeBlk* TopSizeArray;215struct SizeDistributionElement* SizeDistributionArray;216const char* heapName;217size_t segment_size;218// StatElement data219size_t alloc_granules;220size_t granule_size;221bool segment_granules;222unsigned int nBlocks_t1;223unsigned int nBlocks_t2;224unsigned int nBlocks_alive;225unsigned int nBlocks_dead;226unsigned int nBlocks_unloaded;227unsigned int nBlocks_stub;228// FreeBlk data229unsigned int alloc_freeBlocks;230// UsedBlk data231unsigned int alloc_topSizeBlocks;232unsigned int used_topSizeBlocks;233// method hotness data. Temperature range is [-reset_val..+reset_val]234int avgTemp;235int maxTemp;236int minTemp;237};238239#endif // SHARE_CODE_CODEHEAPSTATE_HPP240241242