Java Bytecode Class Definition

I am currently working on a project that is analyzing byte code. I came across a code,

char[] buff = new char[1]; //some code tainting the buff return (new String(buff)); 

in byte code I found the corresponding mapping of new String(buff) to be

 Ljava/lang/StringValue.cache 

can any of you explain where this cache field comes from in the script?


this is from jdk i.6, StringValue . as described: "This class consists solely of static methods that work with character arrays used by strings to store values."

Can anyone tell about this? What is his real purpose? I think this is mainly due to the character buffer used by it, which is passed to the string as an argument. This class does not alter the contents of the buffer; rather, I believe that this is just a gateway to illustrate that the contents of the buffer are intended only to initialize a string.

+4
source share
3 answers

This should not be possible. Here, the sequence you posted looks after compiling with recent Javac.

 iconst_1 newarray char astore_1 new java/lang/String dup aload_1 invokespecial java/lang/String <init> ([C)V areturn 

In addition, java/lang/StringValue does not even exist, at least from jre1.7.0_17. In addition, the presence of a period indicates that probably one of Jasmin combined the class / method tokens, in which case it really refers to the class in the Ljava package, no matter what it should be.

There are two main possibilities: either a broken compiler or a broken disassembler. If you put a class file here, we can at least figure out which one is dealing.

+2
source

This is explicitly a method that returns a cached string if it already exists with the same contents. Like String.intern ().

0
source

Bytecode is an intermediate representation of Java programs, just as assembler is an intermediate representation of C or C ++ programs. The most knowledgeable C and C ++ programmers know the set of processor assembler instructions for which they are compiled. This knowledge is critical when debugging and tuning performance and memory usage. Knowing the assembler instructions that the compiler generates for the source code you write helps you understand how you could otherwise code to achieve memory or performance goals. In addition, when tracking a problem, it is often useful to use a debugger to demonstrate the source code and execute the assembler code that is being executed.

0
source

All Articles