0

Given a java class file, we can use hexdump or od to know its jdk version, But can we know the 64bit or 32bit information given a java class file?

I want to know if java class file has this field like version field?

If the bytecodes are agnostic of the word size, then when you od a class file, it's like:

0000000 feca beba 0000 3100 6300 0009 0019 0946 0000020 1900 4700 0009 0019 0948 1900 4900 0009 0000040 0019 094a 1900 4b00 000a 001a 074c 4d00

The first line is about 2*8 bytes, Why the second line address is 0000020?

hongchangfirst
  • 245
  • 3
  • 17
  • 3
    It is duplicate of http://stackoverflow.com/questions/2062020/how-can-i-tell-if-im-running-in-64-bit-jvm-or-32-bit-jvm-from-within-a-program – Kulbhushan Singh Aug 12 '15 at 06:58
  • I don't think so, OP is asking about the class file, the reference question is concerned about runtime. – morpheus05 Aug 12 '15 at 06:59
  • 1
    See also http://stackoverflow.com/q/18713591/4856258 – Tagir Valeev Aug 12 '15 at 07:04
  • if the bytecodes were compiled specifically for an architecture then how can it run on any platforms? – phuclv Aug 12 '15 at 08:34
  • @KulbhushanSingh - No it isn't. This question is asking about the >>compilation<< platform, not the execution platform. These are different questions with different answers. – Stephen C Aug 12 '15 at 10:33

3 Answers3

5

But can we know the 64bit or 32bit information given a java class file?

No you cannot tell.

  • Java bytecodes are "agnostic" of the word size. The same .class files can be loaded and run on either a 32 or 64 bit JVM. It doesn't matter what platform they were compiled on1.
  • There is nothing in the javap output that tells you what java compiler was used. (You can intuit the Java major version from the classfile version, but that's not definitive, and it is not what we are talking about ...)
  • The JVM specification does not define any standard "attributes" to encode the java compiler version, or whether it was running on a 32 or 64 bit JVM.
  • I couldn't find any trace of a compiler version string in a .class file using UNIX / Linux utilities such as strings or od.

Followup:

Why the second line address is 0000020?

It is in octal. Please refer to man 1 od for details. (Historically, od is a contraction of "octal dump".)


1 - Ignoring classfile version issues ...

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • If the bytecodes are agnostic of the word size, then when you od a class file, it's like: ` 0000000 feca beba 0000 3100 6300 0009 0019 0946 0000020 1900 4700 0009 0019 0948 1900 4900 0009 0000040 0019 094a 1900 4b00 000a 001a 074c 4d00` The first line is about 2*8 bytes, Why the second line address is 0000020? – hongchangfirst Aug 12 '15 at 07:22
2

The Java .class-files are platform-independent. In particular the same class file can be executed both on 32bit and 64bit architecture. Thus there's no such field inside the class file as it's not necessary.

Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
0

The byte code of the class file is special VM byte code and has nothing to do with the underlying architecture. Therefore you don't need to determine this information. You can compile your java program with a 64bit JDK and run it on a JRE_32 bit.

morpheus05
  • 4,772
  • 2
  • 32
  • 47
  • You're right of course, but the question contains no hint to what the OP actually wants the information for. As such it is only an assumption that this has anything to do with running the application. It might as well be just for reporting purposes, for example. – Gimby Aug 12 '15 at 07:26
  • I just curious about that if we can know the compiled jdk 64 or 32 information given only the class file. – hongchangfirst Aug 12 '15 at 07:37