This discussion is archived
7 Replies Latest reply: Dec 7, 2010 11:11 AM by jschellSomeoneStoleMyAlias RSS

Strata in Source Code and Bytecode

815652 Newbie
Currently Being Moderated
Hi,

I have a question about the Location class in the JDI. The Location class has the notion of a stratum for specifying a source code level when interfacing with the debugger. This appears to be so that I can translate source code from some language "X" to the Java language, then compile Java to bytecode, and finally use the Location class in conjunction with the JDI to set breakpoints and get line numbers associated with language "X" in the class file/bytecode.

So from my reading of the JDK, it appears that I can get stratum-specific information from the class file. However, I haven't yet figured out how to get stratum-specific information into the class file in the first place. So I have two questions, really:

First, how is stratum-specific information specified in translator-generated java source code such that the java compiler can include that information in the class file's debug information?

Second, how are strata specified in the class file itself? I see documentation for line number information in the VM spec, but nothing on how to indicate strata.

Thanks in advance for any help.

Jim
  • 1. Re: Strata in Source Code and Bytecode
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    My guess - attribute_info.

    There are defined values for that but others can exist and the VM must explicitly ignore them.

    But that is just a guess based on a quick look just now. At one time I looked a bit more closely as to where debug info must be stored and the is some location that allows for arbritrary data storage.
  • 2. Re: Strata in Source Code and Bytecode
    815652 Newbie
    Currently Being Moderated
    I agree, attribute_info seems like the logical place/means to store strata information. In fact, more specifically, the LineNumberTable attribute seems like it ought to have a facility for mapping a line number to a stratum, but I haven't seen anything like that in the spec. I'm wondering if there is some auxilliary documentation I should refer to for this kind of thing. Or could it be that this is just an unimplemented feature? Or maybe it's just called something else in the spec, and I've overlooked it.

    Thanks again for your help.

    Jim
  • 3. Re: Strata in Source Code and Bytecode
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    812649 wrote:
    I agree, attribute_info seems like the logical place/means to store strata information. In fact, more specifically, the LineNumberTable attribute seems like it ought to have a facility for mapping a line number to a stratum, but I haven't seen anything like that in the spec.
    Debug info isn't in the spec.
    I'm wondering if there is some auxilliary documentation I should refer to for this kind of thing.
    Doubt it. It is intended to allow for unknown usage. One can't spec unknown usage.
  • 4. Re: Strata in Source Code and Bytecode
    815652 Newbie
    Currently Being Moderated
    Are we talking about the same spec? The LineNumberTable attribute sounds like debug info to me, and it's defined at 4.7.8 of the JVM spec. In any case, for the stratum parameter of of Location.lineNumber (defined in the JDI section of the JDK docs) to be useful, the stratum for a line number has to be recorded somewhere such that Location.lineNumber can recognize and access it.

    Edited by: 812649 on Dec 3, 2010 2:11 PM
  • 5. Re: Strata in Source Code and Bytecode
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    812649 wrote:
    Are we talking about the same spec? The LineNumberTable attribute sounds like debug info to me, and it's defined at 4.7.8 of the JVM spec.
    Yes and no. I don't think that used to be in there.
    In any case, for the stratum parameter of of Location.lineNumber (defined in the JDI section of the JDK docs) to be useful, the stratum for a line number has to be recorded somewhere such that Location.lineNumber can recognize and access it.
    Given that my response above was a guess, and you thought it sounded likely just get a real class file reader and look to see what values are in the attribute section. If it is there, either as some odd variation of the debug stuff, or another type of attribute then problem solved. If not there then the reader should help to determine where it actually is.
  • 6. Re: Strata in Source Code and Bytecode
    815652 Newbie
    Currently Being Moderated
    A class file reader might be helpful if I had an example class file which actually contained strata information. In that case, I think even a hex dump would do just fine. However, I think what I really need is example java source code with embedded strata information. Unfortunately, I'm not aware of any existing program that actually outputs strata. Everything I've seen seems to compile straight to bytecode. Maybe that's what I should do as well (write out bytecode instead of Java), but I wanted to see if using strata layers via generated Java was even an option. Does anyone know of an existing program that outputs strata information?

    Edited by: 812649 on Dec 6, 2010 1:52 PM
  • 7. Re: Strata in Source Code and Bytecode
    jschellSomeoneStoleMyAlias Expert
    Currently Being Moderated
    I really need is example java source code with embedded strata information.
    I suspect that doesn't exist. If it does I would like to see it as well.
    A class file reader might be helpful if I had an example class file which actually contained strata information
    Try Groovy and/or AspectJ. There are other variants as well but you should only pick those that have a following and which are up to date.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points