Re: Late binding of integer constants?
Roberto Andrioli <[email protected]> Thu, 16 Nov 2017 13:55:07 +0000
| Newsgroups | gmane.comp.java.objectweb.asm |
|---|---|
| Message-ID | <CAKJVBvBnEdw5dp9K=Q0bMnt0A-z3A_yA+okVH00cfo2QYY5EJQ@mail.gmail.com> |
Petter, During compile time a constant (final) static field were used, so javac inline the value. At runtime the class SpHttpStatus is not used. I believe that the unique way to extract the info that the constant came from SpHttpStatus class is by source code analysis. But the ibrary can init the constant in a static block, and the inline will not occur. The JaCoCo guys did some think like this: see https://github.com/jacoco/jacoco/pull/474 On Thu, Nov 16, 2017, 11:35 AM <[email protected]> wrote: > Hi, > > The following source code: > > if (response.getStatus() == SpHttpStatus.SC_OK) > > Leads to the following byte code: > > 1: invokevirtual #3 // Method /redacted/ > Response.getStatus:()I > 4: sipush 200 > 7: if_icmpne 18 > > In other words, the SpHttpStatus.SC_OK constant has been inlined and > replaced > with its value. However, that constant is defined in a different module > than > the calling code, meaning that if at runtime, a version with a different > value > is used, things will break. I didn't expect that (I was expecting late > binding) - does anyone on this list know something about the rationale for > this? > > Another question, probably more suitable for this mailing list: The > problem I > am trying to solve is to automatically trim/correct inter-project > dependencies > by looking into the bytecode of the classes to see which external classes > are > actually referenced. This particular thing makes it hard for me to extract > the > fact that this code references the SpHttpStatus class. That fact is noted > in > the constant pool, but I don't see an easy way of accessing that > information - > is there a good way to do that? > > Thanks, > Petter > > -- > 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