/usr/share/doc/libbytecode-java-doc/api/org/biojava/utils/bytecode/package-summary.html is in libbytecode-java-doc 0.92.svn.20090106-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (version 1.7.0_21) on Sun May 26 20:50:41 UTC 2013 -->
<title>org.biojava.utils.bytecode (bytecode API)</title>
<meta name="date" content="2013-05-26">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="org.biojava.utils.bytecode (bytecode API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../org/biojava/utils/bytecode/package-summary.html">Package</a></li>
<li>Class</li>
<li><a href="package-use.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev Package</li>
<li>Next Package</li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/biojava/utils/bytecode/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<div class="header">
<h1 title="Package" class="title">Package org.biojava.utils.bytecode</h1>
<div class="docSummary">
<div class="block">A Java object-model for a Java Bytecode Macro-Assembler.</div>
</div>
<p>See: <a href="#package_description">Description</a></p>
</div>
<div class="contentContainer">
<ul class="blockList">
<li class="blockList">
<table class="packageSummary" border="0" cellpadding="3" cellspacing="0" summary="Interface Summary table, listing interfaces, and an explanation">
<caption><span>Interface Summary</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Interface</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/CodeClass.html" title="interface in org.biojava.utils.bytecode">CodeClass</a></td>
<td class="colLast">
<div class="block">Interface for Java classes within the bytecode generation framework.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/CodeContext.html" title="interface in org.biojava.utils.bytecode">CodeContext</a></td>
<td class="colLast">
<div class="block">Interface which encapsulates the stream to which Java bytecode can
be written.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/CodeGenerator.html" title="interface in org.biojava.utils.bytecode">CodeGenerator</a></td>
<td class="colLast">
<div class="block">Interface for an object which can produce Java bytecode.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/CodeMethod.html" title="interface in org.biojava.utils.bytecode">CodeMethod</a></td>
<td class="colLast">
<div class="block">Wrap up details about a method in a Java class file</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/Instruction.html" title="interface in org.biojava.utils.bytecode">Instruction</a></td>
<td class="colLast">
<div class="block">Base class for java bytecode instructions.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/ParametricCodeGenerator.html" title="interface in org.biojava.utils.bytecode">ParametricCodeGenerator</a></td>
<td class="colLast"> </td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/PParametricCodeGenerator.html" title="interface in org.biojava.utils.bytecode">PParametricCodeGenerator</a></td>
<td class="colLast"> </td>
</tr>
</tbody>
</table>
</li>
<li class="blockList">
<table class="packageSummary" border="0" cellpadding="3" cellspacing="0" summary="Class Summary table, listing classes, and an explanation">
<caption><span>Class Summary</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Class</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/ByteCode.html" title="class in org.biojava.utils.bytecode">ByteCode</a></td>
<td class="colLast">
<div class="block">Factory for objects which encapsulate individual Java bytecode instructions.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/CodeField.html" title="class in org.biojava.utils.bytecode">CodeField</a></td>
<td class="colLast">
<div class="block">Wrap up details about a field in a Java class file.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/CodeUtils.html" title="class in org.biojava.utils.bytecode">CodeUtils</a></td>
<td class="colLast">
<div class="block">Utility code for things you will frequently need.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/ConstantPool.html" title="class in org.biojava.utils.bytecode">ConstantPool</a></td>
<td class="colLast">
<div class="block">Build a Java class file constant pool.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/GeneratedClassLoader.html" title="class in org.biojava.utils.bytecode">GeneratedClassLoader</a></td>
<td class="colLast">
<div class="block">A class loader that actually produces real Java classes from
GeneratedCodeClass instances.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/GeneratedCodeClass.html" title="class in org.biojava.utils.bytecode">GeneratedCodeClass</a></td>
<td class="colLast">
<div class="block">A CodeClass implementation that is used to generate new classes.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/GeneratedCodeMethod.html" title="class in org.biojava.utils.bytecode">GeneratedCodeMethod</a></td>
<td class="colLast">
<div class="block">A method that will be generated.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/IfExpression.html" title="class in org.biojava.utils.bytecode">IfExpression</a></td>
<td class="colLast">
<div class="block">A CodeGenerator that provides something semanticaly identical to if.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/InstructionVector.html" title="class in org.biojava.utils.bytecode">InstructionVector</a></td>
<td class="colLast">
<div class="block">A list of Instructions and/or other CodeGenerator objects.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/IntrospectedCodeClass.html" title="class in org.biojava.utils.bytecode">IntrospectedCodeClass</a></td>
<td class="colLast">
<div class="block">CodeClass instances that represent normal Java Class objects.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/Label.html" title="class in org.biojava.utils.bytecode">Label</a></td>
<td class="colLast">
<div class="block">A Label used to mark a position in byte code.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/LocalVariable.html" title="class in org.biojava.utils.bytecode">LocalVariable</a></td>
<td class="colLast">
<div class="block">A local variable.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/MarkLabel.html" title="class in org.biojava.utils.bytecode">MarkLabel</a></td>
<td class="colLast">
<div class="block">A CodeGenerator that just marks a label that can be used for jumps.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/ParametricType.html" title="class in org.biojava.utils.bytecode">ParametricType</a></td>
<td class="colLast">
<div class="block">A template type.</div>
</td>
</tr>
</tbody>
</table>
</li>
<li class="blockList">
<table class="packageSummary" border="0" cellpadding="3" cellspacing="0" summary="Exception Summary table, listing exceptions, and an explanation">
<caption><span>Exception Summary</span><span class="tabEnd"> </span></caption>
<tr>
<th class="colFirst" scope="col">Exception</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tbody>
<tr class="altColor">
<td class="colFirst"><a href="../../../../org/biojava/utils/bytecode/CodeException.html" title="class in org.biojava.utils.bytecode">CodeException</a></td>
<td class="colLast">
<div class="block">An exception indicating that something went wrong generating byte code.</div>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<a name="package_description">
<!-- -->
</a>
<h2 title="Package org.biojava.utils.bytecode Description">Package org.biojava.utils.bytecode Description</h2>
<div class="block">A Java object-model for a Java Bytecode Macro-Assembler.
<h2>Description</h2>
<p>
The ByteCode package is able to generate Java Bytecode that can be used to
define Java classes. It is not restricted to things that can be expressed as
Java code (as in .java files), and is more flexible than basic Java bytecode.
</p>
<p>
This package supports generating classes, interfaces, methods, fields, and the
like. It follows the macro-assembler pattern, where users can effectively
extend the bytecode instruction set with their own instructions that at
compile time expand to real bytecode instructions. Many useful
pseudo-instructions are provided, such as IfExpression. This package also
supports some advanced functionality such as templating. Templating supports
both object and primitive types and types can be resolved at the level of
complete methods or single expressions.
</p>
<p>
The ByteCode package has no support whatsoever for editing Java Bytecode. In
particular, there is no support for search-and-replace or optimization.
</p>
<p>
The main classes for generating bytecode are
<a href="../../../../org/biojava/utils/bytecode/CodeUtils.html" title="class in org.biojava.utils.bytecode"><code>CodeUtils</code></a>,
<a href="../../../../org/biojava/utils/bytecode/ByteCode.html" title="class in org.biojava.utils.bytecode"><code>ByteCode</code></a>,
<a href="../../../../org/biojava/utils/bytecode/InstructionVector.html" title="class in org.biojava.utils.bytecode"><code>InstructionVector</code></a> and
<a href="../../../../org/biojava/utils/bytecode/GeneratedCodeClass.html" title="class in org.biojava.utils.bytecode"><code>GeneratedCodeClass</code></a>. You will probably also
use <a href="../../../../org/biojava/utils/bytecode/GeneratedClassLoader.html" title="class in org.biojava.utils.bytecode"><code>GeneratedClassLoader</code></a>, as it does the
actual work of building and loading classes.
</p>
<p>
It is probably a requirement of using this package effectively that you have
memorised or have handy a copy of the Java VM specification. This is available
from the Sun web site.
</p>
<h2>Class Reflection</h2>
<p>
The ByteCode package represents classes, methods and fields using its own APIs.
These, for obvious reasons, closely resemble those provided by the core Java
APIs. The three interfaces
<a href="../../../../org/biojava/utils/bytecode/CodeClass.html" title="interface in org.biojava.utils.bytecode"><code>CodeClass</code></a>,
<a href="../../../../org/biojava/utils/bytecode/CodeMethod.html" title="interface in org.biojava.utils.bytecode"><code>CodeMethod</code></a> and
<a href="../../../../org/biojava/utils/bytecode/CodeField.html" title="class in org.biojava.utils.bytecode"><code>CodeField</code></a>
represent these basic concepts.
</p>
<p>
Classes from the Java VM are reflected into this model using
<a href="../../../../org/biojava/utils/bytecode/IntrospectedCodeClass.html" title="class in org.biojava.utils.bytecode"><code>IntrospectedCodeClass</code></a>.
To get an instance, use the factory method
<a href="../../../../org/biojava/utils/bytecode/IntrospectedCodeClass.html#forClass(java.lang.Class)"><code>IntrospectedCodeClass.forClass(Class)</code></a> or
<a href="../../../../org/biojava/utils/bytecode/IntrospectedCodeClass.html#forClass(java.lang.String)"><code>IntrospectedCodeClass.forClass(String)</code></a>.
</p>
<h2>Class Generation</h2>
<p>
Classes that you generate yourself will be represented by instances of
<a href="../../../../org/biojava/utils/bytecode/GeneratedCodeClass.html" title="class in org.biojava.utils.bytecode"><code>GeneratedCodeClass</code></a>.
Methods are created by calling
<a href="../../../../org/biojava/utils/bytecode/GeneratedCodeClass.html#createMethod(java.lang.String, org.biojava.utils.bytecode.CodeClass, org.biojava.utils.bytecode.CodeClass[], java.lang.String[], int)"><code>GeneratedCodeClass.createMethod(java.lang.String, org.biojava.utils.bytecode.CodeClass, org.biojava.utils.bytecode.CodeClass[], java.lang.String[], int)</code></a>,
which will return a
<a href="../../../../org/biojava/utils/bytecode/GeneratedCodeMethod.html" title="class in org.biojava.utils.bytecode"><code>GeneratedCodeMethod</code></a>. The method can then be
implemented by associating a
<a href="../../../../org/biojava/utils/bytecode/CodeGenerator.html" title="interface in org.biojava.utils.bytecode"><code>CodeGenerator</code></a>
with the method on that particular class using
<a href="../../../../org/biojava/utils/bytecode/GeneratedCodeClass.html#setCodeGenerator(org.biojava.utils.bytecode.CodeMethod, org.biojava.utils.bytecode.CodeGenerator)"><code>GeneratedCodeClass.setCodeGenerator(org.biojava.utils.bytecode.CodeMethod, org.biojava.utils.bytecode.CodeGenerator)</code></a>.
</p>
<p>
Fields are generated by calling
<a href="../../../../org/biojava/utils/bytecode/GeneratedCodeClass.html#createField(java.lang.String, org.biojava.utils.bytecode.CodeClass, int)"><code>GeneratedCodeClass.createField(java.lang.String, org.biojava.utils.bytecode.CodeClass, int)</code></a>.
</p>
<p>
The classes themselves are instantiated into the VM using
<a href="../../../../org/biojava/utils/bytecode/GeneratedClassLoader.html" title="class in org.biojava.utils.bytecode"><code>GeneratedClassLoader</code></a>.
This implements
<code>ClassLoader.defineClass(byte[], int, int)</code> and
over-rides the other necessary book-keeping methods. You may wish to sub-class
or wrap this class in an application to generate the desired behavior.
</p>
<h2>An example</h2>
<p>
We are going to implement HelloWorld in bytecode. Here is the (annotated) code.
</p>
<p>
Firstly, lets define our application structure...
<code><pre>
public class BCHelloWorld {
public static void main(String[] args)
throws Throwable {
createHelloWorld().run();
}
public static Runnable createHelloWorld() {
...
}
}
</pre>
</code>
We will fill in the createHelloWorld method to actualy do the work of printing
out hello world by implementing a Runnable with a run() method. Firstly, we
need a load of types, methods and a field or two.
<code>
<pre>
CodeClass cl_Object = IntrospectedCodeClass.forClass(Object.class);
CodeClass cl_String = IntrospectedCodeClass.forClass(String.class);
CodeClass cl_System = IntrospectedCodeClass.forClass(System.class);
CodeClass cl_PrintStream = IntrospectedCodeClass.forClass(PrintStream.class);
CodeClass cl_Void = IntrospectedCodeClass.forClass(Void.TYPE);
CodeClass cl_Runnable = IntrospectedCodeClass.forClass(Runnable.class);
CodeField f_System_out = cl_System.getFieldByName("out");
CodeMethod m_PrintStream_printLn = cl_PrintStream.getMethod(
"printLn",
new CodeClass[] { cl_String } );
CodeMethod m_Object_init = cl_Object.getConstructor(CodeUtils.EMPTY_LIST);
</pre>
</code>
Now we are ready to create our code class. It will be called HelloWorldRunnable,
inherit directly from Object, implement Runnable, and be a public class.
<code>
<pre>
GeneratedCodeClass ourClass = new GeneratedCodeClass(
"HelloWorldRunnable",
cl_Object,
new CodeClass[] { cl_Runnable },
CodeUtils.ACC_PUBLIC | CodeUtils.ACC_SUPER);
</pre>
</code>
This will need a constructor. Remember, constructors have the name >init<:,
and you must be sure to call the super-constructor explicitly. Normaly the javac
compiler does this for you.
<code>
<pre>
GeneratedCodeMethod init = ourClass.createMethod(
"<init>",
cl_Void,
CodeUtils.EMPTY_LIST,
CodeUtils.ACC_PUBLIC);
InstructionVector initIV = new InstructionVector();
initIV.add(ByteCode.make_aload(init.getThis()));
initIV.add(ByteCode.make_invokespecial(m_Object_init));
initIV.add(ByteCode.make_return());
ourClass.setCodeGenerator(init, initIV);
</pre>
</code>
To be a Runnable implementation, we must also provide a run() method. This will
take no arguments, return void and be publically accessible. Also, the body of
this method will print out "Hello World" and then we can all feel pleased with
ourselves.
<code>
<pre>
GeneratedCodeMethod run = ourClass.createMethod(
"run",
cl_Void,
CodeUtils.EMPTY_LIST,
CodeUtils.ACC_PUBLIC);
InstructionVector runIV = new InstructionVector();
runIV.add(ByteCode.make_getstatic(f_System_out));
runIV.add(ByteCode.make_sconst("Hello World");
runIV.add(ByteCode.make_invokevirtual(m_PrintStream_printLn));
runIV.add(ByteCode.make_return());
ourClass.setCodeGenerator(run, runIV);
</pre>
</code>
Now we want to load in a class with this deffinition and instantiate it.
<code>
<pre>
GeneratedClassLoader gcl = new GeneratedClassLoader(class.getClassLoader());
Class newClass = gcl.defineClass(ourClass);
return (Runnable) newClass.newInstance();
</pre>
</code>
And there you are. With any luck, if you type all of this in, and the fates
smile on you, and biojava.jar is arround for linking against, you should have
generated your very own unuque HelloWorld class.
</p>
<p>
Good luck.
</p></div>
</div>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../org/biojava/utils/bytecode/package-summary.html">Package</a></li>
<li>Class</li>
<li><a href="package-use.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../index-all.html">Index</a></li>
<li><a href="../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li>Prev Package</li>
<li>Next Package</li>
</ul>
<ul class="navList">
<li><a href="../../../../index.html?org/biojava/utils/bytecode/package-summary.html" target="_top">Frames</a></li>
<li><a href="package-summary.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>
|