是否会在堆栈顶部创建操作和变量?

时间:2017-11-20 23:57:11

标签: java stack heap

根据我对这些链接的理解(first linksecond linkthird link),当有方法时,将创建堆栈块。但是,我感到困惑的是关于操作和int。它们是否会在堆栈之上,因为我也从这个web site读取了关于int add的操作。网站声明“value1和value2必须是int类型。值从操作数堆栈中弹出.int结果是value1 + value2。结果被推送到操作数堆栈。”

假设我有这种类型的代码:

public static int bar (int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16, int x17, int x18, int x19, int x20){
int y = x1+x2+x3+x4+x5+x6+x7+x8+x9+x10+x11+x12+x13+x14+x15+x16+x17+x18+x19+x20; 
return y;
}

这是否意味着bar()堆栈块将被创建为最下面的,然后19个添加操作位于堆栈顶部以及20整数?当我返回“y”变量时,是否会弹出bar()方法堆栈块?请指正。谢谢。

1 个答案:

答案 0 :(得分:0)

进入堆栈。运算符在指令流中。像这样:

PUSH x1
PUSH X2
; ADD adds the two top items on the stack, pops them, and pushes the result
ADD    ; now x1+x2 is on top of the stack
PUSH X3
ADD    ; now x1+x2+x2 is on top of the stack.
; etcetera
POP Y ; Stores the final sum into Y
相关问题