Java recursion with jsr command

I am using Jasmin Java assembler to compile a toy language. But when I use the jsr instruction to return to the subroutine and run the Jasmin output using java, I get the error "Recursive call to jsr record" error. Here is the Jasmin code (it computes 5! (I missed the class definitions, all this in the main method)):

f:
   swap
   istore 2
   iload 2
   ifeq label0
   iload 2
   iload 2
   ldc 1
   isub
   jsr f
   istore 1
   istore 2
   iload 1
   iload 2
   imul
   goto label1
label0:
   ldc 1
label1:
   swap
   astore 0
   ret 0
main:
   ldc 5
   jsr f
   istore 1
   iload 1
+3
source share
1 answer

Recursive jsr explicitly forbidden & sect; 4.8.2 JVM specifications :

jsr jsr_w , . ( try-finally- finally. Java . 4.9.6.)

-, , .

+10

Source: https://habr.com/ru/post/1793696/


All Articles