Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/utilities/histogram.cpp
32285 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "oops/oop.inline.hpp"26#include "utilities/histogram.hpp"2728#ifdef ASSERT2930////////////////// HistogramElement ////////////////////////3132HistogramElement::HistogramElement() {33_count = 0;34}3536int HistogramElement::count() {37return _count;38}3940const char* HistogramElement::name() {41return _name;42}4344void HistogramElement::increment_count() {45// We can't use the accessor :-(.46Atomic::inc(&_count);47}4849int HistogramElement::compare(HistogramElement* e1,HistogramElement* e2) {50if(e1->count() > e2->count()) {51return -1;52} else if(e1->count() < e2->count()) {53return 1;54}55return 0;56}5758void HistogramElement::print_on(outputStream* st) const {59st->print("%10d ",((HistogramElement*)this)->count());60st->print_cr("%s",((HistogramElement*)this)->name());61}6263////////////////// Histogram ////////////////////////6465int Histogram::sort_helper(HistogramElement** e1, HistogramElement** e2) {66return (*e1)->compare(*e1,*e2);67}6869Histogram::Histogram(const char* title,int estimatedCount) {70_title = title;71_elements = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<HistogramElement*>(estimatedCount,true);72}7374void Histogram::add_element(HistogramElement* element) {75// Note, we need to add locking !76elements()->append(element);77}7879void Histogram::print_header(outputStream* st) {80st->print_cr("%s",title());81st->print_cr("--------------------------------------------------");82}8384void Histogram::print_elements(outputStream* st) {85elements()->sort(Histogram::sort_helper);86jint total = 0;87for(int i=0; i < elements()->length(); i++) {88elements()->at(i)->print();89total += elements()->at(i)->count();90}91st->print("%10d ", total);92st->print_cr("Total");93}9495void Histogram::print_on(outputStream* st) const {96((Histogram*)this)->print_header(st);97((Histogram*)this)->print_elements(st);98}99100#endif101102103