Re: trouble with LDC
Roberto Andrioli <[email protected]> Sun, 08 Oct 2017 17:18:04 +0000
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CAKJVBvCfzaqbxvzV6Z5_w3+2f9zVVL5YWYonniT48ZEsdyCPNg@mail.gmail.com> |
Simon, you are sure that is not using a final field?
In this case, the compiler will encode the string in the constant pool.
There's no way to verify the owner. But if the field is not final, it value
can be changed and the compiler can't encode it in the constant pool.
Looking in your example:
```
class C {
static String s = "abc" ;
}
class R {
public void method()
{
String s = C.s ;
}
}
```
and running `javap` in the method `R.method()`
```
0: getstatic #2 // Field C.s:Ljava/lang/String;
3: astore_1
4: return
```
Here is obvious that there is no `ldc` instruction. So ASM will not call `
visitLdcInsn(cst)`.
On Sun, Oct 8, 2017 at 2:00 PM Simon IJskes <[email protected]> wrote:
> I can see the owner in the constant pool, with an index unused in the
> code, so i guess at runtime the jvm verifies via the constant pool as well.
>
> On 08-10-17 18:56, dbrosIus wrote:
> > What's worse is the same thing happens for static final fields from
> > other classes, so you can never know for sure.
> >
> > -------- Original message --------
> > From: Simon IJskes <[email protected]>
> > Date: 10/8/17 11:57 AM (GMT-05:00)
> > To: [email protected]
> > Subject: [asm] trouble with LDC
> >
> > Hi,
> >
> > i'm making a dependency verifier based on ASM6.0.
> >
> > I'm using class files generated by 1.8.0_144.
> >
> > // adhoq example:
> >
> > class C {
> > static String c = "abc" ;
> > }
> >
> > class R {
> >
> > public void method()
> > {
> > String s = C.s ;
> > }
> >
> > } ;
> >
> > When R is parsed by ClassReader, ending up in MethodVisitor, the
> >
> > public void visitLdcInsn( Object cst )
> >
> > is passed a String with the value "abc". No way for the visitor to find
> > out its 'owner' was C. The javap disassembly reveals:
> >
> > ldc #7
> >
> > constant pool:
> > #7 = String #74
> > #74 = Utf8 abc
> >
> > so, indeed no ref to the owner C.
> >
> > i think, the only way to accurately verify the dependency is by walking
> > the constant pool. but how to access these? any hints? other ways to
> > find the owner?
> >
> > Thanks,
> > Simon
> >
> >
> > --
> > You receive this message as a subscriber of the [email protected] mailing
> list.
> > To unsubscribe: mailto:[email protected]
> > For general help: mailto:[email protected]?subject=help
> > OW2 mailing lists service home page: http://www.ow2.org/wws
>
>
> --
> You receive this message as a subscriber of the [email protected] mailing list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws