|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.mj.impl.rt.support; |
|
18 |
|
19 import java.util.Hashtable; |
|
20 import java.util.Enumeration; |
|
21 |
|
22 class FinalizerStatistics |
|
23 { |
|
24 private static Hashtable mReferences = new Hashtable(); |
|
25 |
|
26 private static final boolean mTrace = false; |
|
27 private static class Refcount |
|
28 { |
|
29 int mCount; |
|
30 String mClassName; |
|
31 |
|
32 private Refcount(String className) |
|
33 { |
|
34 mCount = 1; |
|
35 mClassName = className; |
|
36 } |
|
37 } |
|
38 |
|
39 public static void finalizableCreated(String className) |
|
40 { |
|
41 synchronized (mReferences) |
|
42 { |
|
43 Refcount r = (Refcount)mReferences.get(className); |
|
44 int count = 1; |
|
45 if (r != null) |
|
46 { |
|
47 r.mCount++; |
|
48 count = r.mCount; |
|
49 } |
|
50 else |
|
51 { |
|
52 mReferences.put(className, new Refcount(className)); |
|
53 } |
|
54 if (mTrace) System.out.println("Finalizable created. name: " + |
|
55 className + ", count: " + count); |
|
56 } |
|
57 } |
|
58 |
|
59 public static void classFinalized(String className) |
|
60 { |
|
61 synchronized (mReferences) |
|
62 { |
|
63 Refcount r = (Refcount)mReferences.get(className); |
|
64 r.mCount--; |
|
65 if (mTrace) System.out.println("Finalizable destroyed. name: " + |
|
66 className + ", count: " + r.mCount); |
|
67 } |
|
68 } |
|
69 |
|
70 public static boolean getNonfinalizedObjects(StringBuffer sb) |
|
71 { |
|
72 synchronized (mReferences) |
|
73 { |
|
74 sb.append("Finalizable objects\n"); |
|
75 Enumeration e = mReferences.elements(); |
|
76 boolean allFinalized = true; |
|
77 while (e.hasMoreElements()) |
|
78 { |
|
79 Refcount r = (Refcount)e.nextElement(); |
|
80 |
|
81 if (r != null) |
|
82 { |
|
83 if (r.mCount != 0) |
|
84 { |
|
85 allFinalized = false; |
|
86 } |
|
87 sb.append(" class=" + r.mClassName + |
|
88 " count=" + r.mCount + "\n"); |
|
89 } |
|
90 } |
|
91 sb.append("\nStatus "); |
|
92 if (allFinalized) |
|
93 { |
|
94 sb.append("ALL FINALIZED"); |
|
95 } |
|
96 else |
|
97 { |
|
98 sb.append("OBJECTS WAITING FOR FINALIZATION"); |
|
99 } |
|
100 if (mTrace) System.out.println(sb.toString()); |
|
101 |
|
102 return allFinalized; |
|
103 } |
|
104 } |
|
105 |
|
106 public static void reset() |
|
107 { |
|
108 mReferences.clear(); |
|
109 } |
|
110 |
|
111 } |