From: chiba Date: Sat, 5 Jun 2004 16:05:18 +0000 (+0000) Subject: Changed subclasses of javassist.expr.Expr so that $_ is always initialized. X-Git-Tag: rel_3_17_1_ga~503 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=134ee70a9fd4959cbf6b9b6f3b9d1498247ec1e5;p=javassist.git Changed subclasses of javassist.expr.Expr so that $_ is always initialized. git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@109 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- diff --git a/Readme.html b/Readme.html index 7c0a4cfb..fbf088f9 100644 --- a/Readme.html +++ b/Readme.html @@ -5,7 +5,7 @@ -

Javassist version 2

+

Javassist version 3

Copyright (C) 2000-2004 by Shigeru Chiba, All rights reserved.

@@ -255,7 +255,7 @@ see javassist.Dump.

Changes

-

- version 3.0 RC1 +

- version 3.0 beta in May 18th, 2004.

- version 2.6 in August, 2003. @@ -553,7 +554,8 @@ Fabian Crabus, Bo Norregaard Jorgensen, Bob Lee, Bill Burke, Remy Sanlaville, Muga Nishizawa, Alexey Loubyansky, Saori Oki, Andreas Salathe, Dante Torres estrada, S. Pam, Nuno Santos, Denis Taye, Colin Sampaleanu, Robert Bialek, Asato Shimotaki, -Howard Lewis Ship, Richard Jones, and Marjan Sterjev +Howard Lewis Ship, Richard Jones, Marjan Sterjev, +Bruce McDonald, and Mark Brennan for their contributions.


diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 001269a8..bf5a28ee 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -35,7 +35,7 @@ public abstract class CtClass { /** * The version number of this release. */ - public static final String version = "3.0 beta"; + public static final String version = "3.0 beta 3"; /** * Prints the version number and the copyright notice. diff --git a/src/main/javassist/bytecode/Bytecode.java b/src/main/javassist/bytecode/Bytecode.java index ae6f1691..e319eeea 100644 --- a/src/main/javassist/bytecode/Bytecode.java +++ b/src/main/javassist/bytecode/Bytecode.java @@ -441,6 +441,29 @@ public class Bytecode implements Opcode { addLdc(constPool.addIntegerInfo(n)); } + /** + * Appends an instruction for pushing zero or null on the stack. + * If the type is void, this method does not append any instruction. + * + * @param type the type of the zero value (or null). + */ + public void addConstZero(CtClass type) { + if (type.isPrimitive()) { + if (type == CtClass.longType) + addOpcode(LCONST_0); + else if (type == CtClass.floatType) + addOpcode(FCONST_0); + else if (type == CtClass.doubleType) + addOpcode(DCONST_0); + else if (type == CtClass.voidType) + throw new RuntimeException("void type?"); + else + addOpcode(ICONST_0); + } + else + addOpcode(ACONST_NULL); + } + /** * Appends ILOAD or (WIDE) ILOAD_<n> * @@ -680,9 +703,9 @@ public class Bytecode implements Opcode { addLstore(n); return 2; } - else if(type == CtClass.floatType) + else if (type == CtClass.floatType) addFstore(n); - else if(type == CtClass.doubleType) { + else if (type == CtClass.doubleType) { addDstore(n); return 2; } diff --git a/src/main/javassist/bytecode/Descriptor.java b/src/main/javassist/bytecode/Descriptor.java index b3cc5a8c..9590d632 100644 --- a/src/main/javassist/bytecode/Descriptor.java +++ b/src/main/javassist/bytecode/Descriptor.java @@ -46,22 +46,20 @@ public class Descriptor { return classname.replace('/', '.'); } - /** - * Converts to a classname from a descriptor - */ - public static String fromDescriptor(String descriptor) - { - String newname = toJavaName(descriptor).substring(1); - return newname.substring(0, newname.length() - 1); - } - - /** - * Converts to a descriptor from a classname - */ - public static String toDescriptor(String classname) - { - return "L" + toJvmName(classname) + ";"; - } + /** + * Converts to a classname from a descriptor + */ + public static String fromDescriptor(String descriptor) { + String newname = toJavaName(descriptor).substring(1); + return newname.substring(0, newname.length() - 1); + } + + /** + * Converts to a descriptor from a classname + */ + public static String toDescriptor(String classname) { + return "L" + toJvmName(classname) + ";"; + } /** * Returns the internal representation of the class name in the @@ -179,8 +177,6 @@ public class Descriptor { return sbuf.toString(); } - - private static void toDescriptor(StringBuffer desc, CtClass type) { if (type.isArray()) { desc.append('['); diff --git a/src/main/javassist/expr/Cast.java b/src/main/javassist/expr/Cast.java index 80ad4012..160698ff 100644 --- a/src/main/javassist/expr/Cast.java +++ b/src/main/javassist/expr/Cast.java @@ -113,6 +113,10 @@ public class Cast extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + jc.compileStmnt(statement); bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/FieldAccess.java b/src/main/javassist/expr/FieldAccess.java index 8598f456..954c3413 100644 --- a/src/main/javassist/expr/FieldAccess.java +++ b/src/main/javassist/expr/FieldAccess.java @@ -174,6 +174,8 @@ public class FieldAccess extends Expr { /* Is $_ included in the source code? */ boolean included = checkResultValue(retType, statement); + if (read) + included = true; int retVar = jc.recordReturnType(retType, included); if (read) @@ -189,6 +191,17 @@ public class FieldAccess extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, isStatic(), paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + if (included) + if (retType == CtClass.voidType) { + bytecode.addOpcode(ACONST_NULL); + bytecode.addAstore(retVar); + } + else { + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + } + jc.compileStmnt(statement); if (read) bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/Instanceof.java b/src/main/javassist/expr/Instanceof.java index a0982583..2cb9790b 100644 --- a/src/main/javassist/expr/Instanceof.java +++ b/src/main/javassist/expr/Instanceof.java @@ -118,6 +118,10 @@ public class Instanceof extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + jc.compileStmnt(statement); bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/MethodCall.java b/src/main/javassist/expr/MethodCall.java index 28ed8d2d..1e0a842d 100644 --- a/src/main/javassist/expr/MethodCall.java +++ b/src/main/javassist/expr/MethodCall.java @@ -211,6 +211,12 @@ public class MethodCall extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, c == INVOKESTATIC, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + if (retType != CtClass.voidType) { + bytecode.addConstZero(retType); + bytecode.addStore(retVar, retType); // initialize $_ + } + jc.compileStmnt(statement); if (retType != CtClass.voidType) bytecode.addLoad(retVar, retType); diff --git a/src/main/javassist/expr/NewExpr.java b/src/main/javassist/expr/NewExpr.java index 1fa7d4e9..e4c979fe 100644 --- a/src/main/javassist/expr/NewExpr.java +++ b/src/main/javassist/expr/NewExpr.java @@ -178,6 +178,10 @@ public class NewExpr extends Expr { Bytecode bytecode = jc.getBytecode(); storeStack(params, true, paramVar, bytecode); jc.recordLocalVariables(ca, pos); + + bytecode.addConstZero(newType); + bytecode.addStore(retVar, newType); // initialize $_ + jc.compileStmnt(statement); bytecode.addAload(retVar); diff --git a/tutorial/tutorial.html b/tutorial/tutorial.html index ce0a40cf..6c260011 100644 --- a/tutorial/tutorial.html +++ b/tutorial/tutorial.html @@ -106,7 +106,27 @@ byte[] b = cc.toBytecode();

The default ClassPool returned by a static method ClassPool.getDefault() searches the same path that the underlying JVM (Java virtual machine) has. -The users can expand this class search path if needed. +If a program is running on a web application server such as JBoss and Tomcat, +the ClassPool object may not be able to find user classes +since such a web application server uses multiple class loaders as well as +the system class loader. In that case, an additional class path must be +registered to the ClassPool. Suppose that pool +refers to a ClassPool object: + +

+ +

+This statement registers the class path that was used for loading +the class of the object that this referes to. +You can use any Class object as an argument instead of +this.getClass(). The class path used for loading the +class represented by that Class object is registered. + + +

+You can register a directory name as the class search path. For example, the following code adds a directory /usr/local/javalib to the search path: