You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Jacob Kjome <ho...@visi.com> on 2005/08/27 16:59:33 UTC
BCEL newbie question
How do I get this...
private void createMethod_11() {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(ACC_STATIC | ACC_FINAL,
Type.VOID, Type.NO_ARGS, new String[] {}, "<clinit>",
className, il, _cp);
il.append(_factory.createFieldAccess(className, "class$L" +
className.replace('.', '$'), new ObjectType(
"java.lang.Class"), Constants.GETSTATIC));
il.append(_factory.createFieldAccess(className,
"XMLC_GENERATED_CLASS",
new ObjectType("java.lang.Class"), Constants.PUTSTATIC));
il.append(_factory.createFieldAccess(className,
"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
new ObjectType("java.lang.Class"),
Constants.GETSTATIC));
il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFactoryCache",
"getFactory", new
ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[] { new
ObjectType(
"java.lang.Class") }, Constants.INVOKESTATIC));
il.append(_factory.createFieldAccess(className, "fDOMFactory", new
ObjectType(
"org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
Constants.PUTSTATIC));
il.append(InstructionFactory.createReturn(Type.VOID));
method.setMaxStack();
method.setMaxLocals();
_cg.addMethod(method.getMethod());
il.dispose();
}
to generate this...
static {
XMLC_GENERATED_CLASS = $$XMLC_GENERATED$$.dyna.dyna01.html.class;
fDOMFactory =
XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTMLDomFactory.class);
}
currently, it is generating this...
static final {
XMLC_GENERATED_CLASS = class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
fDOMFactory =
XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory);
}
The class was originally generated by the BCELifier (by someone else on our
team) based on an example generated XMLC ( http://xmlc.objectweb.org/ )
class. We tweaked it for our purposes, but the code in the block above
never really worked so we had it commented out (I also removed bits to
avoid generating code that didn't need to be generated and got it slimmed
down to the code you see above). However, that means that some
functionality isn't available where it works just fine for the ASM2 version
(built with the ASMifier). I would like the two to generate nearly
identical code and this is the last little bit that I need to get
working. Can someone please point out the syntax needed to generate the
proper code (like the former, which is spit out by the ASM2 version) rather
than the improper code (like the latter, generated by the BCEL code above,
which is clearly incorrect, but I'm just not familiar enough with these
bytecode tools to know what the proper syntax is).
thanks,
Jake
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question (solved!)
Posted by Andrew Huntwork <as...@huntwork.net>.
On 11/2/05, Jacob Kjome <ho...@visi.com> wrote:
>
> [...]I really don't have the first clue about this stuff and am happy to
> have
> the code generated for me. But just for giggles, how about this...
>
> The instruction lists append stuff and return instruction
> handles. Great. But if this appending is akin to something like a
> StringBuffer, order matters. Is that the case with Instruction lists? If
> so, how do I deal with this?...
Order definitely matters. You can append a forward branch (like 4: ifnonnull
32 in your example) by simply inserting the branch instruction when you come
to it in the code segment you're generating, but initially give the branch a
null target. Then you can set the target of the branch instruction after
inserting the target instruction. For example, if you want to generate this
code:
0: aconst_null[1](1)
1: ifnonnull[199](3) -> nop
4: nop[0](1)
5: return[177](1)
you can use this code:
InstructionList il = new InstructionList();
il.append(new ACONST_NULL());
IFNONNULL inn = new IFNONNULL(null); //create the branch but don't set a
target yet
il.append(inn); // append the branch
InstructionHandle ih = il.append(new NOP()); //append the target
inn.setTarget(ih); //set the target of the branch after inserting the target
of the branch
...
> 4: ifnonnull 32
> ...
> 32: putstatic #47; //Field XMLC_GENERATED_CLASS:Ljava/lang/Class;
> ...
>
> So, If I'm going in order, how do I reference InstructionHandle 32 before
> I
> create it? for instance...
>
> ...
> il.append(InstructionFactory.createBranchInstruction(Constants.IFNONNULL,
> ih_32));
> ...
> InstructionHandle ih_32 = il.append(_factory.createFieldAccess(className,
> "XMLC_GENERATED_CLASS",
> new ObjectType("java.lang.Class"), Constants.PUTSTATIC));
> ...
>
> I must be missing some mind-bogglingly obvious here. Please point it out,
> if you could.
>
> thanks,
>
>
> Jake
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>
Re: BCEL newbie question (solved!)
Posted by Jacob Kjome <ho...@visi.com>.
At 12:08 AM 10/30/2005 -0700, you wrote:
>Jacob Kjome wrote:
>> I am quite lost trying to figure out how to write BCel code to match the
>> disassembled code. Can you help out? Here's javap's output for the
>> static block in question...
>
>I am happy to help, but i'm not happy to do your work for you when it
>appears you haven't really put much effort into doing it yourself.
I understand where you are coming from. I've felt the same way with others
when working on several open source projects upon which I am a
committer. However, in this case I'm coming from the user's point of view
and I'm learning to empathize. I've put hours into staring at this stuff
trying to make sense of it and what I've posted so far is as far as I've
gotten with something that doesn't simply die at runtime, so I think you
are being a bit presumptuous here. And, to be honest, my goal here is not
to learn the ins and outs of BCEL, but to get this little tiny piece of
code working so I can move on with life and never bother with this
gobbledygook again (no offense to those who like to write bytecode, it just
not my cup of tea). Like I said, I've got the class working 99%
properly. It seems that this 1% is taking many times the effort it took to
do the first 99%.
> A good place to start learning how to write bcel code is here:
>
>http://jakarta.apache.org/bcel/manual.html
>
>you may be particularly interested in 3.3.4, which talks about
>instruction lists. (almost) all you have to do is write code that
>creates an instruction list and adds to it one instruction per
>instruction in the disassembly of the asm2 code. you can learn about
>instructions, their arguments, and how to generate them by reading the
>bcel manual referenced above.
>
I've seen these docs and they make slightly more sense once I figured out
what the heck the "javap" command provides. What I finally ended up doing
was regenerating the class entirely using the BCELifier. Took me a while
to get it working. It was failing for a couple different reasons. First,
it doesn't seem to like JDK1.5-compiled code at all. It just bombs and
produces no output. Second, it didn't like my ASM2-generated class even
when compiled using JDK1.4.2. It just bombs like the first case. Not sure
why? The VM likes it just fine and the decompiler likes it just
fine. Anyway, I finally compiled the original class using JDK1.4.2 (the
one in which I ran the ASMifier upon) and ran BCELifier upon that. It
worked fine and now I have it all working, with a few tweaks to make it
generalized.
>i'll be happy to take a look at any more specific questions you may have.
I really don't have the first clue about this stuff and am happy to have
the code generated for me. But just for giggles, how about this...
The instruction lists append stuff and return instruction
handles. Great. But if this appending is akin to something like a
StringBuffer, order matters. Is that the case with Instruction lists? If
so, how do I deal with this?...
...
4: ifnonnull 32
...
32: putstatic #47; //Field XMLC_GENERATED_CLASS:Ljava/lang/Class;
...
So, If I'm going in order, how do I reference InstructionHandle 32 before I
create it? for instance...
...
il.append(InstructionFactory.createBranchInstruction(Constants.IFNONNULL,
ih_32));
...
InstructionHandle ih_32 = il.append(_factory.createFieldAccess(className,
"XMLC_GENERATED_CLASS",
new ObjectType("java.lang.Class"), Constants.PUTSTATIC));
...
I must be missing some mind-bogglingly obvious here. Please point it out,
if you could.
thanks,
Jake
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question
Posted by Andrew Huntwork <as...@huntwork.net>.
Jacob Kjome wrote:
> I am quite lost trying to figure out how to write BCel code to match the
> disassembled code. Can you help out? Here's javap's output for the
> static block in question...
I am happy to help, but i'm not happy to do your work for you when it
appears you haven't really put much effort into doing it yourself. A
good place to start learning how to write bcel code is here:
http://jakarta.apache.org/bcel/manual.html
you may be particularly interested in 3.3.4, which talks about
instruction lists. (almost) all you have to do is write code that
creates an instruction list and adds to it one instruction per
instruction in the disassembly of the asm2 code. you can learn about
instructions, their arguments, and how to generate them by reading the
bcel manual referenced above.
i'll be happy to take a look at any more specific questions you may have.
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question
Posted by Jacob Kjome <ho...@visi.com>.
At 10:15 PM 10/27/2005 -0700, you wrote:
>the problem is that the code you're generating is in fact really screwed
>up in many ways. class names are wrong, there aren't even enough
>methods, and maybe some other things.
It just occurred to me that you might be under the impression that I think
that the code below ought to generate a whole class. If so, no. The rest
of the class is being generated just fine. The *only* thing that is
generating badly is this tiny little static block. Again, I need this
(this was decompiled from a class that BCel generated from my existing
not-quite-working-properly code)...
static {
XMLC_GENERATED_CLASS = class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
fDOMFactory =
XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory);
}
...to look like this (this was decompiled from a class that ASM2 generated
which works perfectly)...
static {
XMLC_GENERATED_CLASS = $$XMLC_GENERATED$$.dyna.dyna01.html.class;
fDOMFactory =
XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTMLDomFactory.class);
}
The original BCel code (which I believe was generated, but was commented
out because it wasn't working properly) was creating all kinds of extra
crap which I sifted out make it look at least close to code I want to
generate. The class names were always messed up, even in the code before I
manipulated it ("$" instead of "."). In fact, it bombed when attempting to
run the class generated by the original code. Although the code above is
malformed, the class actually successfully loads at runtime. It only craps
out when other code tries to access the fDOMFactory field which only
happens under rare circumstances. It is the rare circumstances that I want
to make work because there is no reason the class shouldn't work 100% properly.
> probably a good way to go would be
>for you to disassemble (using javap or some other tool) a class with the
>code you want and the class generated by bcel and compare them. then
>you can try to make them match by screwing around with the bcel code.
>if you can't figure out how to generate a particular segment, ask back here.
>
I am quite lost trying to figure out how to write BCel code to match the
disassembled code. Can you help out? Here's javap's output for the static
block in question...
static {};
Code:
0: getstatic #25; //Field class$0:Ljava/lang/Class;
3: dup
4: ifnonnull 32
7: pop
8: ldc #27; //String $$XMLC_GENERATED$$.dyna.dyna01.html
10: invokestatic #33; //Method
java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
13: dup
14: putstatic #25; //Field class$0:Ljava/lang/Class;
17: goto 32
20: new #35; //class java/lang/NoClassDefFoundError
23: dup_x1
24: swap
25: invokevirtual #41; //Method
java/lang/Throwable.getMessage:()Ljava/lang/String;
28: invokespecial #45; //Method
java/lang/NoClassDefFoundError."<init>":(Ljava/lang/String;)V
31: athrow
32: putstatic #47; //Field XMLC_GENERATED_CLASS:Ljava/lang/Class;
35: getstatic #49; //Field class$1:Ljava/lang/Class;
38: dup
39: ifnonnull 67
42: pop
43: ldc #51; //String
org.enhydra.xml.xmlc.dom.xerces.XercesHTMLDomFactory
45: invokestatic #33; //Method
java/lang/Class.forName:(Ljava/lang/String;)Ljava/lang/Class;
48: dup
49: putstatic #49; //Field class$1:Ljava/lang/Class;
52: goto 67
55: new #35; //class java/lang/NoClassDefFoundError
58: dup_x1
59: swap
60: invokevirtual #41; //Method
java/lang/Throwable.getMessage:()Ljava/lang/String;
63: invokespecial #45; //Method
java/lang/NoClassDefFoundError."<init>":(Ljava/lang/String;)V
66: athrow
67: invokestatic #57; //Method
org/enhydra/xml/xmlc/dom/XMLCDomFactoryCache.getFactory:(Ljava/lang/Class;)Lorg/enhydra/xml/xmlc/dom/XMLCDomFactory;
70: putstatic #59; //Field
fDOMFactory:Lorg/enhydra/xml/xmlc/dom/XMLCDomFactory;
73: return
Exception table:
from to target type
8 13 20 Class java/lang/ClassNotFoundException
43 48 55 Class java/lang/ClassNotFoundException
Here's the existing code block that needs to be modified to work properly...
private void createMethod_11() {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(ACC_STATIC, Type.VOID,
Type.NO_ARGS, new String[] {}, "<clinit>",
className, il, _cp);
il.append(_factory.createFieldAccess(className, "class$L" +
className.replace('.', '$'), new ObjectType(
"java.lang.Class"), Constants.GETSTATIC));
il.append(_factory.createFieldAccess(className,
"XMLC_GENERATED_CLASS",
new ObjectType("java.lang.Class"), Constants.PUTSTATIC));
il.append(_factory.createFieldAccess(className,
"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
new ObjectType("java.lang.Class"),
Constants.GETSTATIC));
il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFactoryCache",
"getFactory", new
ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[] { new
ObjectType(
"java.lang.Class") }, Constants.INVOKESTATIC));
il.append(_factory.createFieldAccess(className, "fDOMFactory", new
ObjectType(
"org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
Constants.PUTSTATIC));
il.append(InstructionFactory.createReturn(Type.VOID));
method.setMaxStack();
method.setMaxLocals();
_cg.addMethod(method.getMethod());
il.dispose();
}
thanks for the help!
Jake
>Jacob Kjome wrote:
>> Trying yet again. Is my question too newbie or something? I'm hoping
>> for a little direction here.
>>
>> thanks,
>>
>> Jake
>>
>> At 09:46 PM 9/19/2005 -0500, you wrote:
>> >
>> >Trying again. Any takers? Here's a link to the beginning of the thread
>> >for better readability....
>> >
>> >http://www.mail-archive.com/bcel-user@jakarta.apache.org/msg00780.html
>> >
>> >
>> >Jake
>> >
>> >At 12:24 AM 9/3/2005 -0500, you wrote:
>> > >
>> > >Is there someone that can comment on this? I'm sure I'm just missing
>> > >something small. But even though it is small, I'm still dead in the
>> water
>> > >until I get it figured out.
>> > >
>> > >thanks,
>> > >
>> > >Jake
>> > >
>> > >At 09:59 AM 8/27/2005 -0500, you wrote:
>> > > >
>> > > >How do I get this...
>> > > >
>> > > >private void createMethod_11() {
>> > > > InstructionList il = new InstructionList();
>> > > > MethodGen method = new MethodGen(ACC_STATIC | ACC_FINAL,
>> > > >Type.VOID, Type.NO_ARGS, new String[] {}, "<clinit>",
>> > > > className, il, _cp);
>> > > > il.append(_factory.createFieldAccess(className, "class$L" +
>> > > >className.replace('.', '$'), new ObjectType(
>> > > > "java.lang.Class"), Constants.GETSTATIC));
>> > > > il.append(_factory.createFieldAccess(className,
>> > > >"XMLC_GENERATED_CLASS",
>> > > > new ObjectType("java.lang.Class"),
>> Constants.PUTSTATIC));
>> > > > il.append(_factory.createFieldAccess(className,
>> > > >
>> > > >"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
>> > > >
>> > > >new ObjectType("java.lang.Class"),
>> > > > Constants.GETSTATIC));
>> > > >
>> > >
>> >il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFacto
>> ryCa
>> > >che",
>> > > > "getFactory", new
>> > > >ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[]
>> { new
>> > > >ObjectType(
>> > > > "java.lang.Class") },
>> Constants.INVOKESTATIC));
>> > > > il.append(_factory.createFieldAccess(className,
>> "fDOMFactory", new
>> > > >ObjectType(
>> > > > "org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
>> > > >Constants.PUTSTATIC));
>> > > > il.append(InstructionFactory.createReturn(Type.VOID));
>> > > > method.setMaxStack();
>> > > > method.setMaxLocals();
>> > > > _cg.addMethod(method.getMethod());
>> > > > il.dispose();
>> > > > }
>> > > >
>> > > >to generate this...
>> > > >
>> > > > static {
>> > > > XMLC_GENERATED_CLASS =
>> $$XMLC_GENERATED$$.dyna.dyna01.html.class;
>> > > > fDOMFactory =
>> > >
>> >XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTM
>> >LDom
>> > > >Factory.class);
>> > > > }
>> > > >
>> > > >currently, it is generating this...
>> > > >
>> > > > static final {
>> > > > XMLC_GENERATED_CLASS =
>> class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
>> > > > fDOMFactory =
>> > >
>> >XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$Xe
>> >rces
>> > > >HTMLDomFactory);
>> > > > }
>> > > >
>> > > >
>> > > >The class was originally generated by the BCELifier (by someone
>> else on our
>> > > >team) based on an example generated XMLC (
>> http://xmlc.objectweb.org/ )
>> > > >class. We tweaked it for our purposes, but the code in the block
>> above
>> > > >never really worked so we had it commented out (I also removed
>> bits to
>> > > >avoid generating code that didn't need to be generated and got it
>> slimmed
>> > > >down to the code you see above). However, that means that some
>> > > >functionality isn't available where it works just fine for the
>> ASM2 version
>> > > >(built with the ASMifier). I would like the two to generate nearly
>> > > >identical code and this is the last little bit that I need to get
>> > > >working. Can someone please point out the syntax needed to
>> generate the
>> > > >proper code (like the former, which is spit out by the ASM2
>> version) rather
>> > > >than the improper code (like the latter, generated by the BCEL
>> code above,
>> > > >which is clearly incorrect, but I'm just not familiar enough with
>> these
>> > > >bytecode tools to know what the proper syntax is).
>> > > >
>> > > >thanks,
>> > > >
>> > > >
>> > > >Jake
>> > > >
>> > > >
>> > > >
>> > > >
>> > > >---------------------------------------------------------------------
>> > > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>> > > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>> > > >
>> > > >
>> > > >
>> > >
>> > >
>> > >---------------------------------------------------------------------
>> > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>> > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>> > >
>> > >
>> > >
>> >
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>> >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>> >
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question
Posted by Jacob Kjome <ho...@visi.com>.
Thanks for the reply. That's the direction I needed.
Jake
Quoting Andrew Huntwork <as...@huntwork.net>:
> the problem is that the code you're generating is in fact really screwed
> up in many ways. class names are wrong, there aren't even enough
> methods, and maybe some other things. probably a good way to go would be
> for you to disassemble (using javap or some other tool) a class with the
> code you want and the class generated by bcel and compare them. then
> you can try to make them match by screwing around with the bcel code.
> if you can't figure out how to generate a particular segment, ask back here.
>
> Jacob Kjome wrote:
> > Trying yet again. Is my question too newbie or something? I'm hoping
> > for a little direction here.
> >
> > thanks,
> >
> > Jake
> >
> > At 09:46 PM 9/19/2005 -0500, you wrote:
> > >
> > >Trying again. Any takers? Here's a link to the beginning of the thread
> > >for better readability....
> > >
> > >http://www.mail-archive.com/bcel-user@jakarta.apache.org/msg00780.html
> > >
> > >
> > >Jake
> > >
> > >At 12:24 AM 9/3/2005 -0500, you wrote:
> > > >
> > > >Is there someone that can comment on this? I'm sure I'm just missing
> > > >something small. But even though it is small, I'm still dead in the
> > water
> > > >until I get it figured out.
> > > >
> > > >thanks,
> > > >
> > > >Jake
> > > >
> > > >At 09:59 AM 8/27/2005 -0500, you wrote:
> > > > >
> > > > >How do I get this...
> > > > >
> > > > >private void createMethod_11() {
> > > > > InstructionList il = new InstructionList();
> > > > > MethodGen method = new MethodGen(ACC_STATIC | ACC_FINAL,
> > > > >Type.VOID, Type.NO_ARGS, new String[] {}, "<clinit>",
> > > > > className, il, _cp);
> > > > > il.append(_factory.createFieldAccess(className, "class$L" +
> > > > >className.replace('.', '$'), new ObjectType(
> > > > > "java.lang.Class"), Constants.GETSTATIC));
> > > > > il.append(_factory.createFieldAccess(className,
> > > > >"XMLC_GENERATED_CLASS",
> > > > > new ObjectType("java.lang.Class"),
> > Constants.PUTSTATIC));
> > > > > il.append(_factory.createFieldAccess(className,
> > > > >
> > > > >"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
> > > > >
> > > > >new ObjectType("java.lang.Class"),
> > > > > Constants.GETSTATIC));
> > > > >
> > > >
> > >il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFacto
> > ryCa
> > > >che",
> > > > > "getFactory", new
> > > > >ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[]
> > { new
> > > > >ObjectType(
> > > > > "java.lang.Class") },
> > Constants.INVOKESTATIC));
> > > > > il.append(_factory.createFieldAccess(className,
> > "fDOMFactory", new
> > > > >ObjectType(
> > > > > "org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
> > > > >Constants.PUTSTATIC));
> > > > > il.append(InstructionFactory.createReturn(Type.VOID));
> > > > > method.setMaxStack();
> > > > > method.setMaxLocals();
> > > > > _cg.addMethod(method.getMethod());
> > > > > il.dispose();
> > > > > }
> > > > >
> > > > >to generate this...
> > > > >
> > > > > static {
> > > > > XMLC_GENERATED_CLASS =
> > $$XMLC_GENERATED$$.dyna.dyna01.html.class;
> > > > > fDOMFactory =
> > > >
> > >XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTM
> > >LDom
> > > > >Factory.class);
> > > > > }
> > > > >
> > > > >currently, it is generating this...
> > > > >
> > > > > static final {
> > > > > XMLC_GENERATED_CLASS =
> > class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
> > > > > fDOMFactory =
> > > >
> > >XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$Xe
> > >rces
> > > > >HTMLDomFactory);
> > > > > }
> > > > >
> > > > >
> > > > >The class was originally generated by the BCELifier (by someone
> > else on our
> > > > >team) based on an example generated XMLC (
> > http://xmlc.objectweb.org/ )
> > > > >class. We tweaked it for our purposes, but the code in the block
> > above
> > > > >never really worked so we had it commented out (I also removed
> > bits to
> > > > >avoid generating code that didn't need to be generated and got it
> > slimmed
> > > > >down to the code you see above). However, that means that some
> > > > >functionality isn't available where it works just fine for the
> > ASM2 version
> > > > >(built with the ASMifier). I would like the two to generate nearly
> > > > >identical code and this is the last little bit that I need to get
> > > > >working. Can someone please point out the syntax needed to
> > generate the
> > > > >proper code (like the former, which is spit out by the ASM2
> > version) rather
> > > > >than the improper code (like the latter, generated by the BCEL
> > code above,
> > > > >which is clearly incorrect, but I'm just not familiar enough with
> > these
> > > > >bytecode tools to know what the proper syntax is).
> > > > >
> > > > >thanks,
> > > > >
> > > > >
> > > > >Jake
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >---------------------------------------------------------------------
> > > > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > > > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> > > >
> > > >
> > > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question
Posted by Andrew Huntwork <as...@huntwork.net>.
the problem is that the code you're generating is in fact really screwed
up in many ways. class names are wrong, there aren't even enough
methods, and maybe some other things. probably a good way to go would be
for you to disassemble (using javap or some other tool) a class with the
code you want and the class generated by bcel and compare them. then
you can try to make them match by screwing around with the bcel code.
if you can't figure out how to generate a particular segment, ask back here.
Jacob Kjome wrote:
> Trying yet again. Is my question too newbie or something? I'm hoping
> for a little direction here.
>
> thanks,
>
> Jake
>
> At 09:46 PM 9/19/2005 -0500, you wrote:
> >
> >Trying again. Any takers? Here's a link to the beginning of the thread
> >for better readability....
> >
> >http://www.mail-archive.com/bcel-user@jakarta.apache.org/msg00780.html
> >
> >
> >Jake
> >
> >At 12:24 AM 9/3/2005 -0500, you wrote:
> > >
> > >Is there someone that can comment on this? I'm sure I'm just missing
> > >something small. But even though it is small, I'm still dead in the
> water
> > >until I get it figured out.
> > >
> > >thanks,
> > >
> > >Jake
> > >
> > >At 09:59 AM 8/27/2005 -0500, you wrote:
> > > >
> > > >How do I get this...
> > > >
> > > >private void createMethod_11() {
> > > > InstructionList il = new InstructionList();
> > > > MethodGen method = new MethodGen(ACC_STATIC | ACC_FINAL,
> > > >Type.VOID, Type.NO_ARGS, new String[] {}, "<clinit>",
> > > > className, il, _cp);
> > > > il.append(_factory.createFieldAccess(className, "class$L" +
> > > >className.replace('.', '$'), new ObjectType(
> > > > "java.lang.Class"), Constants.GETSTATIC));
> > > > il.append(_factory.createFieldAccess(className,
> > > >"XMLC_GENERATED_CLASS",
> > > > new ObjectType("java.lang.Class"),
> Constants.PUTSTATIC));
> > > > il.append(_factory.createFieldAccess(className,
> > > >
> > > >"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
> > > >
> > > >new ObjectType("java.lang.Class"),
> > > > Constants.GETSTATIC));
> > > >
> > >
> >il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFacto
> ryCa
> > >che",
> > > > "getFactory", new
> > > >ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[]
> { new
> > > >ObjectType(
> > > > "java.lang.Class") },
> Constants.INVOKESTATIC));
> > > > il.append(_factory.createFieldAccess(className,
> "fDOMFactory", new
> > > >ObjectType(
> > > > "org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
> > > >Constants.PUTSTATIC));
> > > > il.append(InstructionFactory.createReturn(Type.VOID));
> > > > method.setMaxStack();
> > > > method.setMaxLocals();
> > > > _cg.addMethod(method.getMethod());
> > > > il.dispose();
> > > > }
> > > >
> > > >to generate this...
> > > >
> > > > static {
> > > > XMLC_GENERATED_CLASS =
> $$XMLC_GENERATED$$.dyna.dyna01.html.class;
> > > > fDOMFactory =
> > >
> >XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTM
> >LDom
> > > >Factory.class);
> > > > }
> > > >
> > > >currently, it is generating this...
> > > >
> > > > static final {
> > > > XMLC_GENERATED_CLASS =
> class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
> > > > fDOMFactory =
> > >
> >XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$Xe
> >rces
> > > >HTMLDomFactory);
> > > > }
> > > >
> > > >
> > > >The class was originally generated by the BCELifier (by someone
> else on our
> > > >team) based on an example generated XMLC (
> http://xmlc.objectweb.org/ )
> > > >class. We tweaked it for our purposes, but the code in the block
> above
> > > >never really worked so we had it commented out (I also removed
> bits to
> > > >avoid generating code that didn't need to be generated and got it
> slimmed
> > > >down to the code you see above). However, that means that some
> > > >functionality isn't available where it works just fine for the
> ASM2 version
> > > >(built with the ASMifier). I would like the two to generate nearly
> > > >identical code and this is the last little bit that I need to get
> > > >working. Can someone please point out the syntax needed to
> generate the
> > > >proper code (like the former, which is spit out by the ASM2
> version) rather
> > > >than the improper code (like the latter, generated by the BCEL
> code above,
> > > >which is clearly incorrect, but I'm just not familiar enough with
> these
> > > >bytecode tools to know what the proper syntax is).
> > > >
> > > >thanks,
> > > >
> > > >
> > > >Jake
> > > >
> > > >
> > > >
> > > >
> > > >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> > > >
> > > >
> > > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> > >
> > >
> > >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question
Posted by Jacob Kjome <ho...@visi.com>.
Trying yet again. Is my question too newbie or something? I'm hoping for
a little direction here.
thanks,
Jake
At 09:46 PM 9/19/2005 -0500, you wrote:
>
>Trying again. Any takers? Here's a link to the beginning of the thread
>for better readability....
>
>http://www.mail-archive.com/bcel-user@jakarta.apache.org/msg00780.html
>
>
>Jake
>
>At 12:24 AM 9/3/2005 -0500, you wrote:
> >
> >Is there someone that can comment on this? I'm sure I'm just missing
> >something small. But even though it is small, I'm still dead in the water
> >until I get it figured out.
> >
> >thanks,
> >
> >Jake
> >
> >At 09:59 AM 8/27/2005 -0500, you wrote:
> > >
> > >How do I get this...
> > >
> > >private void createMethod_11() {
> > > InstructionList il = new InstructionList();
> > > MethodGen method = new MethodGen(ACC_STATIC | ACC_FINAL,
> > >Type.VOID, Type.NO_ARGS, new String[] {}, "<clinit>",
> > > className, il, _cp);
> > > il.append(_factory.createFieldAccess(className, "class$L" +
> > >className.replace('.', '$'), new ObjectType(
> > > "java.lang.Class"), Constants.GETSTATIC));
> > > il.append(_factory.createFieldAccess(className,
> > >"XMLC_GENERATED_CLASS",
> > > new ObjectType("java.lang.Class"),
Constants.PUTSTATIC));
> > > il.append(_factory.createFieldAccess(className,
> > >
> > >"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
> > >
> > >new ObjectType("java.lang.Class"),
> > > Constants.GETSTATIC));
> > >
> > >il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFacto
ryCa
> >che",
> > > "getFactory", new
> > >ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[] { new
> > >ObjectType(
> > > "java.lang.Class") }, Constants.INVOKESTATIC));
> > > il.append(_factory.createFieldAccess(className,
"fDOMFactory", new
> > >ObjectType(
> > > "org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
> > >Constants.PUTSTATIC));
> > > il.append(InstructionFactory.createReturn(Type.VOID));
> > > method.setMaxStack();
> > > method.setMaxLocals();
> > > _cg.addMethod(method.getMethod());
> > > il.dispose();
> > > }
> > >
> > >to generate this...
> > >
> > > static {
> > > XMLC_GENERATED_CLASS =
$$XMLC_GENERATED$$.dyna.dyna01.html.class;
> > > fDOMFactory =
> > >XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTM
>LDom
> > >Factory.class);
> > > }
> > >
> > >currently, it is generating this...
> > >
> > > static final {
> > > XMLC_GENERATED_CLASS =
class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
> > > fDOMFactory =
> > >XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$Xe
>rces
> > >HTMLDomFactory);
> > > }
> > >
> > >
> > >The class was originally generated by the BCELifier (by someone else
on our
> > >team) based on an example generated XMLC ( http://xmlc.objectweb.org/ )
> > >class. We tweaked it for our purposes, but the code in the block above
> > >never really worked so we had it commented out (I also removed bits to
> > >avoid generating code that didn't need to be generated and got it slimmed
> > >down to the code you see above). However, that means that some
> > >functionality isn't available where it works just fine for the ASM2
version
> > >(built with the ASMifier). I would like the two to generate nearly
> > >identical code and this is the last little bit that I need to get
> > >working. Can someone please point out the syntax needed to generate the
> > >proper code (like the former, which is spit out by the ASM2 version)
rather
> > >than the improper code (like the latter, generated by the BCEL code
above,
> > >which is clearly incorrect, but I'm just not familiar enough with these
> > >bytecode tools to know what the proper syntax is).
> > >
> > >thanks,
> > >
> > >
> > >Jake
> > >
> > >
> > >
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> > >
> > >
> > >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> >
> >
> >
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question
Posted by Jacob Kjome <ho...@visi.com>.
Trying again. Any takers? Here's a link to the beginning of the thread
for better readability....
http://www.mail-archive.com/bcel-user@jakarta.apache.org/msg00780.html
Jake
At 12:24 AM 9/3/2005 -0500, you wrote:
>
>Is there someone that can comment on this? I'm sure I'm just missing
>something small. But even though it is small, I'm still dead in the water
>until I get it figured out.
>
>thanks,
>
>Jake
>
>At 09:59 AM 8/27/2005 -0500, you wrote:
> >
> >How do I get this...
> >
> >private void createMethod_11() {
> > InstructionList il = new InstructionList();
> > MethodGen method = new MethodGen(ACC_STATIC | ACC_FINAL,
> >Type.VOID, Type.NO_ARGS, new String[] {}, "<clinit>",
> > className, il, _cp);
> > il.append(_factory.createFieldAccess(className, "class$L" +
> >className.replace('.', '$'), new ObjectType(
> > "java.lang.Class"), Constants.GETSTATIC));
> > il.append(_factory.createFieldAccess(className,
> >"XMLC_GENERATED_CLASS",
> > new ObjectType("java.lang.Class"), Constants.PUTSTATIC));
> > il.append(_factory.createFieldAccess(className,
> >
> >"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
> >
> >new ObjectType("java.lang.Class"),
> > Constants.GETSTATIC));
> >
> >il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFactoryCa
>che",
> > "getFactory", new
> >ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[] { new
> >ObjectType(
> > "java.lang.Class") }, Constants.INVOKESTATIC));
> > il.append(_factory.createFieldAccess(className, "fDOMFactory", new
> >ObjectType(
> > "org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
> >Constants.PUTSTATIC));
> > il.append(InstructionFactory.createReturn(Type.VOID));
> > method.setMaxStack();
> > method.setMaxLocals();
> > _cg.addMethod(method.getMethod());
> > il.dispose();
> > }
> >
> >to generate this...
> >
> > static {
> > XMLC_GENERATED_CLASS = $$XMLC_GENERATED$$.dyna.dyna01.html.class;
> > fDOMFactory =
> >XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTM
LDom
> >Factory.class);
> > }
> >
> >currently, it is generating this...
> >
> > static final {
> > XMLC_GENERATED_CLASS = class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
> > fDOMFactory =
> >XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$Xe
rces
> >HTMLDomFactory);
> > }
> >
> >
> >The class was originally generated by the BCELifier (by someone else on our
> >team) based on an example generated XMLC ( http://xmlc.objectweb.org/ )
> >class. We tweaked it for our purposes, but the code in the block above
> >never really worked so we had it commented out (I also removed bits to
> >avoid generating code that didn't need to be generated and got it slimmed
> >down to the code you see above). However, that means that some
> >functionality isn't available where it works just fine for the ASM2 version
> >(built with the ASMifier). I would like the two to generate nearly
> >identical code and this is the last little bit that I need to get
> >working. Can someone please point out the syntax needed to generate the
> >proper code (like the former, which is spit out by the ASM2 version) rather
> >than the improper code (like the latter, generated by the BCEL code above,
> >which is clearly incorrect, but I'm just not familiar enough with these
> >bytecode tools to know what the proper syntax is).
> >
> >thanks,
> >
> >
> >Jake
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> >
> >
> >
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org
Re: BCEL newbie question
Posted by Jacob Kjome <ho...@visi.com>.
Is there someone that can comment on this? I'm sure I'm just missing
something small. But even though it is small, I'm still dead in the water
until I get it figured out.
thanks,
Jake
At 09:59 AM 8/27/2005 -0500, you wrote:
>
>How do I get this...
>
>private void createMethod_11() {
> InstructionList il = new InstructionList();
> MethodGen method = new MethodGen(ACC_STATIC | ACC_FINAL,
>Type.VOID, Type.NO_ARGS, new String[] {}, "<clinit>",
> className, il, _cp);
> il.append(_factory.createFieldAccess(className, "class$L" +
>className.replace('.', '$'), new ObjectType(
> "java.lang.Class"), Constants.GETSTATIC));
> il.append(_factory.createFieldAccess(className,
>"XMLC_GENERATED_CLASS",
> new ObjectType("java.lang.Class"), Constants.PUTSTATIC));
> il.append(_factory.createFieldAccess(className,
>
>"class$Lorg$enhydra$xml$xmlc$dom$xerces$XercesHTMLDomFactory",
>
>new ObjectType("java.lang.Class"),
> Constants.GETSTATIC));
>
>il.append(_factory.createInvoke("org.enhydra.xml.xmlc.dom.XMLCDomFactoryCache",
> "getFactory", new
>ObjectType("org.enhydra.xml.xmlc.dom.XMLCDomFactory"), new Type[] { new
>ObjectType(
> "java.lang.Class") }, Constants.INVOKESTATIC));
> il.append(_factory.createFieldAccess(className, "fDOMFactory", new
>ObjectType(
> "org.enhydra.xml.xmlc.dom.XMLCDomFactory"),
>Constants.PUTSTATIC));
> il.append(InstructionFactory.createReturn(Type.VOID));
> method.setMaxStack();
> method.setMaxLocals();
> _cg.addMethod(method.getMethod());
> il.dispose();
> }
>
>to generate this...
>
> static {
> XMLC_GENERATED_CLASS = $$XMLC_GENERATED$$.dyna.dyna01.html.class;
> fDOMFactory =
>XMLCDomFactoryCache.getFactory(org.enhydra.xml.xmlc.dom.xerces.XercesHTMLDom
>Factory.class);
> }
>
>currently, it is generating this...
>
> static final {
> XMLC_GENERATED_CLASS = class$L$$XMLC_GENERATED$$$dyna$dyna01$html;
> fDOMFactory =
>XMLCDomFactoryCache.getFactory(class$Lorg$enhydra$xml$xmlc$dom$xerces$Xerces
>HTMLDomFactory);
> }
>
>
>The class was originally generated by the BCELifier (by someone else on our
>team) based on an example generated XMLC ( http://xmlc.objectweb.org/ )
>class. We tweaked it for our purposes, but the code in the block above
>never really worked so we had it commented out (I also removed bits to
>avoid generating code that didn't need to be generated and got it slimmed
>down to the code you see above). However, that means that some
>functionality isn't available where it works just fine for the ASM2 version
>(built with the ASMifier). I would like the two to generate nearly
>identical code and this is the last little bit that I need to get
>working. Can someone please point out the syntax needed to generate the
>proper code (like the former, which is spit out by the ASM2 version) rather
>than the improper code (like the latter, generated by the BCEL code above,
>which is clearly incorrect, but I'm just not familiar enough with these
>bytecode tools to know what the proper syntax is).
>
>thanks,
>
>
>Jake
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: bcel-user-help@jakarta.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org