Thu, 20 Nov 2008 16:56:09 -0800
6684579: SoftReference processing can be made more efficient
Summary: For current soft-ref clearing policies, we can decide at marking time if a soft-reference will definitely not be cleared, postponing the decision of whether it will definitely be cleared to the final reference processing phase. This can be especially beneficial in the case of concurrent collectors where the marking is usually concurrent but reference processing is usually not.
Reviewed-by: jmasa
1 /*
2 * Copyright 1998-2000 Sun Microsystems, Inc. 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 it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
25 // This class provides a framework for collecting various statistics.
26 // The current implementation is oriented towards counting invocations
27 // of various types, but that can be easily changed.
28 //
29 // To use it, you need to declare a Histogram*, and a subtype of
30 // HistogramElement:
31 //
32 // HistogramElement* MyHistogram;
33 //
34 // class MyHistogramElement : public HistogramElement {
35 // public:
36 // MyHistogramElement(char* name);
37 // };
38 //
39 // MyHistogramElement::MyHistogramElement(char* elementName) {
40 // _name = elementName;
41 //
42 // if(MyHistogram == NULL)
43 // MyHistogram = new Histogram("My Call Counts",100);
44 //
45 // MyHistogram->add_element(this);
46 // }
47 //
48 // #define MyCountWrapper(arg) static MyHistogramElement* e = new MyHistogramElement(arg); e->increment_count()
49 //
50 // This gives you a simple way to count invocations of specfic functions:
51 //
52 // void a_function_that_is_being_counted() {
53 // MyCountWrapper("FunctionName");
54 // ...
55 // }
56 //
57 // To print the results, invoke print() on your Histogram*.
59 #ifdef ASSERT
61 class HistogramElement : public CHeapObj {
62 protected:
63 jint _count;
64 const char* _name;
66 public:
67 HistogramElement();
68 virtual int count();
69 virtual const char* name();
70 virtual void increment_count();
71 void print_on(outputStream* st) const;
72 virtual int compare(HistogramElement* e1,HistogramElement* e2);
73 };
75 class Histogram : public CHeapObj {
76 protected:
77 GrowableArray<HistogramElement*>* _elements;
78 GrowableArray<HistogramElement*>* elements() { return _elements; }
79 const char* _title;
80 const char* title() { return _title; }
81 static int sort_helper(HistogramElement** e1,HistogramElement** e2);
82 virtual void print_header(outputStream* st);
83 virtual void print_elements(outputStream* st);
85 public:
86 Histogram(const char* title,int estimatedSize);
87 virtual void add_element(HistogramElement* element);
88 void print_on(outputStream* st) const;
89 };
91 #endif