Source Code Cross Referenced for GenerateClasses.java in  » Aspect-oriented » aspectwerkz-2.0 » test » weavebench » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Aspect oriented » aspectwerkz 2.0 » test.weavebench 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**************************************************************************************
002:         * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved.                 *
003:         * http://aspectwerkz.codehaus.org                                                    *
004:         * ---------------------------------------------------------------------------------- *
005:         * The software in this package is published under the terms of the LGPL license      *
006:         * a copy of which has been included with this distribution in the license.txt file.  *
007:         **************************************************************************************/package test.weavebench;
008:
009:        import org.codehaus.aspectwerkz.transform.inlining.AsmHelper;
010:        import org.codehaus.aspectwerkz.transform.AspectWerkzPreProcessor;
011:        import org.codehaus.aspectwerkz.hook.impl.WeavingClassLoader;
012:        import org.codehaus.aspectwerkz.definition.SystemDefinition;
013:        import org.codehaus.aspectwerkz.definition.DeploymentScope;
014:        import org.codehaus.aspectwerkz.definition.SystemDefinitionContainer;
015:        import org.codehaus.aspectwerkz.definition.DefinitionParserHelper;
016:        import org.objectweb.asm.ClassVisitor;
017:        import org.objectweb.asm.Constants;
018:        import org.objectweb.asm.Type;
019:        import org.objectweb.asm.CodeVisitor;
020:        import org.objectweb.asm.ClassWriter;
021:
022:        import java.net.URL;
023:        import java.net.URLClassLoader;
024:        import java.io.File;
025:        import java.util.HashSet;
026:        import java.util.Set;
027:        import java.lang.reflect.Method;
028:
029:        /**
030:         * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
031:         */
032:        public class GenerateClasses implements  Constants {
033:
034:            private final static String DUMP_DIR = "_dump2";
035:
036:            private final static String CLASS_NAME_PREFIX = "test/weavebench/Generated_";
037:
038:            public int m_classCount;
039:
040:            public int m_count;
041:
042:            public GenerateClasses(int classCount, int methodCount) {
043:                m_classCount = classCount;
044:                m_count = methodCount;
045:            }
046:
047:            public void generate() throws Throwable {
048:                for (int i = 0; i < m_classCount; i++) {
049:                    ClassWriter cv = AsmHelper.newClassWriter(true);
050:
051:                    String className = CLASS_NAME_PREFIX + i;
052:                    cv.visit(AsmHelper.JAVA_VERSION, ACC_PUBLIC + ACC_SUPER
053:                            + ACC_SYNTHETIC, className, Object.class.getName()
054:                            .replace('.', '/'), new String[] { IGenerated.class
055:                            .getName().replace('.', '/') }, null);
056:
057:                    CodeVisitor mv = cv.visitMethod(ACC_PUBLIC, "<init>",
058:                            "()V", new String[0], null);
059:                    mv.visitVarInsn(ALOAD, 0);
060:                    mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object",
061:                            "<init>", "()V");
062:                    mv.visitVarInsn(ALOAD, 0);
063:                    mv.visitInsn(RETURN);
064:                    mv.visitMaxs(0, 0);
065:
066:                    for (int m = 0; m < m_count; m++) {
067:                        mv = cv.visitMethod(
068:                                (m == 0) ? ACC_PUBLIC : ACC_PRIVATE,//TODO change to private to have wrapper, public for no wrappers
069:                                "method_" + m, "()I", new String[0], null);
070:
071:                        // call next method
072:                        if (m != m_count - 1) {
073:                            mv.visitVarInsn(ALOAD, 0);
074:                            mv.visitMethodInsn(INVOKEVIRTUAL, className,
075:                                    "method_" + (m + 1), "()I");
076:                        }
077:                        AsmHelper.loadIntegerConstant(mv, m);
078:                        mv.visitInsn(IRETURN);
079:                        mv.visitMaxs(0, 0);
080:                    }
081:
082:                    cv.visitEnd();
083:
084:                    AsmHelper.dumpClass(DUMP_DIR, className, cv);
085:                }
086:            }
087:
088:            public static void main(String args[]) throws Throwable {
089:                int CLASS_COUNT = 100;
090:                int METHOD_COUNT = 100;
091:                int JP_COUNT = (METHOD_COUNT * 2 - 1/*last method has no call jp*/+ 1/*init exec*/)
092:                        * CLASS_COUNT;
093:                GenerateClasses me = new GenerateClasses(CLASS_COUNT,
094:                        METHOD_COUNT);
095:
096:                System.out.println("********* Bench for");
097:                System.out.println(" classes: " + CLASS_COUNT);
098:                System.out.println(" methods: " + METHOD_COUNT);
099:                System.out.println(" jps: " + JP_COUNT);
100:                System.out.println("*************************************");
101:
102:                me.generate();
103:
104:                ClassLoader custom_1 = new URLClassLoader(
105:                        new URL[] { (new File(DUMP_DIR)).toURL() },
106:                        GenerateClasses.class.getClassLoader());
107:                bench("No weaver hooked in", custom_1, CLASS_COUNT, 0);
108:
109:                ClassLoader custom_2 = new WeavingClassLoader(
110:                        new URL[] { (new File(DUMP_DIR)).toURL() },
111:                        GenerateClasses.class.getClassLoader());
112:                bench("Weaver hooked in and match none", custom_2, CLASS_COUNT,
113:                        0);
114:
115:                ClassLoader custom_3 = new WeavingClassLoader(
116:                        new URL[] { (new File(DUMP_DIR)).toURL() },
117:                        GenerateClasses.class.getClassLoader());
118:                SystemDefinition sd = SystemDefinitionContainer
119:                        .getVirtualDefinitionAt(custom_3);
120:                sd.addDeploymentScope(DeploymentScope.MATCH_ALL);
121:                DefinitionParserHelper
122:                        .attachDeploymentScopeDefsToVirtualAdvice(sd);
123:                Set defs = new HashSet();
124:                defs.add(sd);
125:                SystemDefinitionContainer.deployDefinitions(custom_3, defs);
126:                bench("Weaver hooked in and match all", custom_3, CLASS_COUNT,
127:                        JP_COUNT);
128:
129:            }
130:
131:            public static void bench(String label, ClassLoader loader,
132:                    int classCount, int jpCount) throws Throwable {
133:                System.out.println("*************************************");
134:                System.out.print(label);
135:                System.out.println("  ");
136:                long t = System.currentTimeMillis();
137:                Class[] classes = new Class[classCount];
138:                for (int i = 0; i < classCount; i++) {
139:                    classes[i] = Class.forName((CLASS_NAME_PREFIX + i).replace(
140:                            '/', '.'), false, loader);
141:                }
142:
143:                System.out.println("  Total load time = "
144:                        + (System.currentTimeMillis() - t));
145:
146:                long t2 = System.currentTimeMillis();
147:                for (int i = 0; i < classCount; i++) {
148:                    Class gen = classes[i];
149:                    Method m0 = gen.getMethod("method_0", new Class[] {});
150:                    Object res = m0.invoke(gen.newInstance(), new Object[] {});
151:                    System.out.print(i);
152:                }
153:                System.out.println("");
154:                long execTimeNotWarmedUp = System.currentTimeMillis() - t2;
155:                System.out.println("  Exec time = " + execTimeNotWarmedUp);
156:                System.out.println("  Total time = "
157:                        + (System.currentTimeMillis() - t));
158:                if (jpCount > 0)
159:                    System.out.println("  Exec / jp ratio (ns) = "
160:                            + execTimeNotWarmedUp * 1000 / jpCount);
161:
162:                t2 = System.currentTimeMillis();
163:                for (int i = 0; i < classCount; i++) {
164:                    Class gen = classes[i];
165:                    Method m0 = gen.getMethod("method_0", new Class[] {});
166:                    Object res = m0.invoke(gen.newInstance(), new Object[] {});
167:                }
168:                System.out.println("  Exec time warmed up = "
169:                        + (System.currentTimeMillis() - t2));
170:            }
171:
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.