gnu.bytecode

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 » Scripting » Nice » gnu.bytecode 
gnu.bytecode
The gnu.bytecode package

Contains classes to generate, read, write, and print Java bytecode (.class) files.

It is used by Kawa to compile Scheme into bytecodes; it should be useful for other languages that need to be compiled into Java bytecodes. (An interesting exercise would be an interactive Java expression evaluator.) The classes here are relatively low-level. If you want to use them to generate bytecode from a high-level language, it is better to use the gnu.expr package, which works at the expression level, and handles all the code-generation for you.

Javadoc generated documentation of the class is available online.

The most important class is ClassType. This contains information about a single class. Note that the difference between ClassType and java.lang.Class is that the latter only represents existing classes that have been loaded into the Java VM; in contrast, ClassType can be used to build new classes incrementally and on the fly.

A ClassType has a list of Field objects; new ones can be added using the various addField methods. A ClassType manages a ConstantPool. A ClassType also has a list of Method objects; new ones can be created by the various addMethod objects.

A Method contains many methods you can use to generate bytecode. See Kawa for examples.

Once you have finished generating a ClassType, you can write it to a .class file with the writeToFile method. You can also make a byte array suitable for ClassLoader.defineClass using the writeToArray method. This is used by Kawa to compile and immediately load a class.

You can also print out the contains of a ClassType in human-readable form using the class ClassTypeWriter. This prints a fair bit of information of the generated class, including dis-assembling the code of the methods.

You can also build a ClassType by reading it from an existing .class file by using a ClassFileInput class. This reads the constant pool, the fields, methods, superclass, and interfaces. The gnu.bytecode.dump class has a main method that prints out the information in a named class file.

Zip archive manager

To build, extract, list, or print a zip file, you can use ZipArchive as an application:
java gnu.bytecode.ZipArchive [txpq] archive [file ...]
See the comments for ZipArchive.main. ZipArchive does not do compression or uncompressions, and it is reported that that some programs do not like the archives it creates. It is probably best suited for listing and extracting from classes.zip-like archives. (This class has been partially re-written to use java.util.zip. It may get dropped in the future.)

Class file dumper

To print out the contents of a class file foo.class, you can use the class dump as an application:
java gnu.bytecode.dump foo.class
This will print out the constant pool, fields, methods, superclass, and implemented interfaces of class foo. It is useful for printing out detailed information about the constant pool, which javap does not do.

License

See the file COPYING.

Author

Per Bothner <per@bothner.com>

How to get it

The gnu.bytecode package is currently distributed as part of Kawa, though it can be used independent of the rest of Kawa.

Bugs and patches

Send them to per@bothner.com, or to the Kawa mailing list.
Java Source File NameTypeComment
Access.javaClass Access flags.
ArrayClassLoader.javaClass Load classes from a set of byte arrays.
ArrayType.javaClass
AttrContainer.javaInterface An interface for objects that (may) contain Attribute objects.
Attribute.javaClass Represents an Attribute of an AttrContainer.
ClassFileInput.javaClass Class to read a ClassType from a DataInputStream (.class file).
ClassType.javaClass
ClassTypeWriter.javaClass This class prints out in contents of a ClassType in human-readable form.
CodeAttr.javaClass Represents the contents of a standard "Code" attribute.
CodeFragment.javaClass A sequence of bytecode instructions belonging to a method's Code attribute. This provides a hook for re-arranging instruction sequences. It currently has limited functionality - no switch instructions, no non-relative jumps, etc. In the future this may be the basis for generating better code (e.g. avoiding needless jumps).
ConstantPool.javaClass Manages a pool of constants, as used in .class files and Java interpreters.
ConstantValueAttr.javaClass
CpoolClass.javaClass A CONSTANT_Class entry in the constant pool.
CpoolEntry.javaClass An entry in the constant pool for a ClassType. Each entry belong to the constant pool table of the "owning" ClassType.
CpoolFloat.javaClass A CONSTANT_Float entry in the constant pool.
CpoolNameAndType.javaClass A CONSTANT_NameAndType entry in the constant pool.
CpoolRef.javaClass A CONSTANT_{Field,Method,InterfaceMethod}Ref entry in the constant pool.
CpoolString.javaClass A CONSTANT_String entry in the constant pool.
CpoolUtf8.javaClass
CpoolValue1.javaClass A CONSTANT_Integer or CONSTANT_Float entry in the constant pool.
CpoolValue2.javaClass A CONSTANT_Long or CONSTANT_Double entry in the constant pool.
dump.javaClass Class to read a ClassType from a DataInputStream (.class file).
ExceptionsAttr.javaClass Represents the contents of a standard "Exceptions" attribute.
Field.javaClass
Filter.javaInterface
IfState.javaClass The state of a conditional expression or statement.
InnerClassesAttr.javaClass
Label.javaClass A Label represents a location in a Code attribute.
LineNumbersAttr.javaClass Represents the contents of a standard "LineNumberTable" attribute.
LocalVarsAttr.javaClass
Location.javaClass An abstracted "variable", inherited by Field and Variable.
Method.javaClass Represents a method in a ClassType.
MiscAttr.javaClass
ObjectType.javaClass Semi-abstract class object reference types.

Extended by ClassType and ArrayType.

ParameterizedType.javaClass A Generic Java parameterized type.
PrimType.javaClass
Scope.javaClass
SourceFileAttr.javaClass
SourceMap.javaClass A mapping from source files to the bytecode line numbers.
SwitchState.javaClass Maintains the state for generating a switch statement.
TryState.javaClass The state of a try statement.
Type.javaClass
TypeVariable.javaClass A Generic Java / JDK 1.5 type variable.
VarEnumerator.javaClass Use this Enuemration class to iterate over the Variables in a Scope.
Variable.javaClass
VerificationError.javaClass The error thrown when an attempt to generate invalid bytecode is made.
ZipArchive.javaClass A class to manipulate a .zip archive. Does not handle compression/uncompression, though that could be added. When used an an application.
ZipLoader.javaClass Load classes from a Zip archive.
ZipMember.javaClass Information about one member of a ZipArchive.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.