U E D R , A S I H C RSS

NewCompileError/2014_07_19 (rev. 1.5)

New Compile Error/2014_07_19

Djavap, jasmin(assembler for jvm)
javap : prints java's descriptions  
http://en.wikipedia.org/wiki/Java_bytecode

# cc(c컴파일러)로 어셈블리파일을 만듦
/usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/cc1plus -quiet -v -imultilib x86_64 -iprefix /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/ -D__DYNAMIC__ nca.cpp -fPIC -quiet -dumpbase nca.cpp -mmacosx-version-min=10.8.5 -m64 -mtune=core2 -auxbase nca -version -D__private_extern__=extern -o /var/folders/zn/v_hqwzws1nx4l19qsdz86xn80000gn/T//ccGprRXs.s

# .s 파일은 assembly 파일
/var/folders/zn/v_hqwzws1nx4l19qsdz86xn80000gn/T//ccGprRXs.s

# s파일로 다시 o 파일을 만듦
/usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/zn/v_hqwzws1nx4l19qsdz86xn80000gn/T//ccrYBpRg.o /var/folders/zn/v_hqwzws1nx4l19qsdz86xn80000gn/T//ccGprRXs.s

.c -> FE -> BE -> assembly file -> assembler -> machine code
| 여기까지가 cc의 역할


# ClassFileAnalyzer
.java ( javac )> .class
.j --(classFileAnalyzer/jasper/..) --> .class

classFileAnalyzer에 .class을 줘서 실행하면 assembly code가 생성됨


mnemonic : 작업 수행, opcode들이 mnemonic
- dup : stack의 탑을 스택에 복제,
directive : 지시어, assembler에게 지정하는 명령어, .으로 시작
opcode(operator)
operand

# bytecode instruction list (참고)

# new mnemonic과 invokespecial 다른점
- new는 객체를 메모리에 할당,
- invokespecial <init>은 할당된 객체를 초기화

# invokestatic은 this가 필요없다!
# invokevirtual

# invokespecial VS invokevirtual
invokespecial
- invokespecial은 스택의 top를 파라메터로 받고, 스택의 top에서 두번째를 this(init의 주체)로 쓴다. <- dup를 하는 이유
- 생성자는void return
invokevirtual
- 모든 객체의 함수는 invokevirtual
- virtual이란 실행될 함수를 compile 시간에 결정할 수 없고 run time에 결정. (vtable lookup, c는 virtual 함수만 vtable에 기록됨)
invokeinterface
- 구체 클래스를 this로 받아야함

# 레퍼런스 타입 (참고)
Ljava/io/InputStream <- java/io/InputStream의 레퍼런스
- 스택에 객체의 주소가 들어있음. premitive 변수가 아니면 전부 레퍼런스 타입
- 메서드의 위치를 나타낼때는 java/io/InputStream/read 이런식으로.


# jvm의 data type
int : I
int[] : [I
String : Ljava/lang/string;
String[][] : [[Ljava/lang/string;

# jvm의 함수
java/lang/string.length(V)I <- bytecode는 알수없는 코드로 구분, jasmin은 /로 구분
() 괄호안에 파라메터

astore_# <- 코드에 선언된 #번째 지역변수에 저장.
aload_# <- 코드에 선언된 #번째 지역변수에 저장된 값을 가져옴.



* (1+2)*3.1을 jasmin assembly로 나타내면
getstatic java/lang/system/out Ljava/io/printstream;

iconst_1
iconst_2
iadd
i2d
ldc 3.1
dmul

invokevirtual java/io/printstream/print(D)V
return
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:51
Processing time 0.0322 sec