2
|
1 |
/*
|
|
2 |
* Copyright 2001 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 |
|
|
24 |
/**
|
|
25 |
*
|
|
26 |
*/
|
|
27 |
import java.util.*;
|
|
28 |
|
|
29 |
class UnloadEventTarg {
|
|
30 |
static int loadersFinalized = 0;
|
|
31 |
|
|
32 |
public static void main(String[] args) throws ClassNotFoundException {
|
|
33 |
loadup("first");
|
|
34 |
loadup("second");
|
|
35 |
if (!forceUnload()) {
|
|
36 |
System.err.println("Unable to force unload");
|
|
37 |
}
|
|
38 |
lastStop();
|
|
39 |
}
|
|
40 |
|
|
41 |
static void loadup(String id) throws ClassNotFoundException {
|
|
42 |
ClassLoaderTarg cl = new ClassLoaderTarg(id);
|
|
43 |
cl.findClass("Unload1Targ").getFields();
|
|
44 |
cl.findClass("Unload2Targ").getFields();
|
|
45 |
}
|
|
46 |
|
|
47 |
static boolean forceUnload() {
|
|
48 |
List holdAlot = new ArrayList();
|
|
49 |
for (int chunk=10000000; chunk > 10000; chunk = chunk / 2) {
|
|
50 |
if (loadersFinalized > 1) {
|
|
51 |
return true;
|
|
52 |
}
|
|
53 |
try {
|
|
54 |
while(true) {
|
|
55 |
holdAlot.add(new byte[chunk]);
|
|
56 |
System.err.println("Allocated " + chunk);
|
|
57 |
}
|
|
58 |
}
|
|
59 |
catch ( Throwable thrown ) { // OutOfMemoryError
|
|
60 |
System.gc();
|
|
61 |
}
|
|
62 |
System.runFinalization();
|
|
63 |
}
|
|
64 |
return false;
|
|
65 |
}
|
|
66 |
|
|
67 |
static void classLoaderFinalized(String id) {
|
|
68 |
System.err.println("finalizing ClassLoaderTarg - " + id);
|
|
69 |
loadersFinalized++;
|
|
70 |
}
|
|
71 |
|
|
72 |
static void unloading1() {
|
|
73 |
System.err.println("unloading Unload1Targ");
|
|
74 |
}
|
|
75 |
|
|
76 |
static void unloading2() {
|
|
77 |
System.err.println("unloading Unload2Targ");
|
|
78 |
}
|
|
79 |
|
|
80 |
static void lastStop() {
|
|
81 |
System.err.println("UnloadEventTarg exiting");
|
|
82 |
}
|
|
83 |
|
|
84 |
}
|