KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > parsing > PerfJavacIntefaceGCTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.source.parsing;
21 import com.sun.source.tree.CompilationUnitTree;
22 import com.sun.tools.javac.util.Context;
23 import java.io.File JavaDoc;
24 import java.lang.ref.WeakReference JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Collections JavaDoc;
27 import org.netbeans.api.java.classpath.ClassPath;
28 import org.netbeans.insane.scanner.ScannerUtils;
29 import org.netbeans.insane.scanner.SimpleXmlVisitor;
30 import org.netbeans.insane.scanner.Visitor;
31 import org.netbeans.junit.NbTestCase;
32 import org.netbeans.modules.java.source.TestUtil;
33 import org.netbeans.spi.java.classpath.support.ClassPathSupport;
34 import org.openide.filesystems.FileUtil;
35 /** Tests whether the JavacInterface gets GCed after some operations
36  *
37  * @author Petr Hrebejk
38  */

39 public class PerfJavacIntefaceGCTest extends NbTestCase {
40     
41     private File JavaDoc workDir;
42     private File JavaDoc rtJar;
43     private ClassPath bootPath;
44     private ClassPath classPath;
45     private final String JavaDoc SOURCE =
46                 "package some;" +
47                 "import javax.swing.JTable;" +
48                 "import javax.swing.JLabel;" +
49                 "public class MemoryFile<K,V> extends JTable {" +
50                 " public java.util.Map.Entry<K,V> entry;" +
51                 " public JLabel label;" +
52                 " public JTable table = new JTable();" +
53                 " public MemoryFile() {}" +
54                 "}";
55                 
56     public PerfJavacIntefaceGCTest(String JavaDoc testName) {
57         super(testName);
58     }
59
60     protected void setUp() throws Exception JavaDoc {
61         workDir = TestUtil.createWorkFolder();
62         TestUtil.copyFiles( workDir, TestUtil.RT_JAR, "jdk/JTable.java" );
63         rtJar = new File JavaDoc( workDir, TestUtil.RT_JAR );
64         URL JavaDoc url = FileUtil.getArchiveRoot (rtJar.toURI().toURL());
65         this.bootPath = ClassPathSupport.createClassPath (new URL JavaDoc[] {url});
66         this.classPath = ClassPathSupport.createClassPath(new URL JavaDoc[0]);
67     }
68
69     protected void tearDown() throws Exception JavaDoc {
70         TestUtil.removeWorkFolder( workDir );
71     }
72
73 // public void testSimple() throws Exception {
74
//
75
// JavacInterface ji = (JavacInterface) JavacInterface.create( bootPath, classPath, null);
76
// WeakReference<JavacInterface> wr = new WeakReference<JavacInterface>( ji );
77
// ji = null;
78
// assertGC( "JavacInterface should be GCed", wr );
79
//
80
// }
81
//
82
// public void testAfterParse() throws Exception {
83
//
84
// JavacInterface ji = (JavacInterface) JavacInterface.create( bootPath, classPath, null);
85
// ji.parse( FileObjects.memoryFileObject( SOURCE, "MemoryFile.java"), null );
86
// WeakReference<JavacInterface> wr = new WeakReference<JavacInterface>( ji );
87
// ji = null;
88
// assertGC( "JavacInterface should be GCed", wr );
89
//
90
// }
91
//
92
// public void testAfterParseAndResolve() throws Exception {
93
//
94
// JavacInterface ji = (JavacInterface) JavacInterface.create( bootPath, classPath, null);
95
// CompilationUnitTree cu = ji.parse( FileObjects.memoryFileObject( SOURCE, "MemoryFile.java"), null );
96
// ji.resolveElements( cu );
97
// WeakReference<JavacInterface> wr = new WeakReference<JavacInterface>( ji );
98
// WeakReference<Context> ctx = new WeakReference<Context>( ji.getContext() );
99
// cu = null;
100
// ji = null;
101
// assertGC( "JavacInterface should be GCed", wr );
102
//
103
// // Visitor v = new SimpleXmlVisitor( new File( "/tmp/insane.xml" ) );
104
// // ScannerUtils.scan( null, v, Collections.singleton( Context.class.getClassLoader() ), true );
105
//
106
// assertGC( "Context should be GCed", ctx );
107
// }
108
//
109
// public void testAfterGetDeclaration() throws Exception {
110
//
111
// JavacInterface ji = (JavacInterface) JavacInterface.create( bootPath, classPath, null);
112
// TypeDeclaration td = ji.getTypeDeclaration( "java.lang.Object" );
113
// WeakReference<TypeDeclaration> wr = new WeakReference<TypeDeclaration>( td );
114
// WeakReference<Context> ctx = new WeakReference<Context>( ji.getContext() );
115
// td = null;
116
// ji = null;
117
// assertGC( "Type Declaration be GCed", wr );
118
// assertGC( "Context should be GCed", ctx );
119
//
120
// }
121
//
122
//
123
// public void testCompilationUnitSize() throws Exception {
124
//
125
// JavacInterface ji = (JavacInterface) JavacInterface.create( bootPath, classPath, null);
126
// CompilationUnitTree cu = ji.parse( FileObjects.memoryFileObject( SOURCE, "MemoryFile.java"), null );
127
// ji.resolveElements( cu );
128
//
129
// assertSize( "Compilation unit should not be too big", Collections.singleton( ji ), 1600000, new Object[] { CachingArchiveProvider.getDefault() } );
130
//
131
// }
132

133 }
134
Popular Tags