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

Java 是否会在堆栈顶部创建操作和变量?,java,heap-memory,stack-memory,Java,Heap Memory,Stack Memory,根据我从这些链接(、、和)中了解到的情况,当有方法时,将创建堆栈块。然而,我感到困惑的是操作和int。它们是否会在堆栈顶部,因为我也从中了解到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 x

根据我从这些链接(、、和)中了解到的情况,当有方法时,将创建堆栈块。然而,我感到困惑的是操作和int。它们是否会在堆栈顶部,因为我也从中了解到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个add操作以及20个整数将位于堆栈的顶部?当我返回“y”变量时,会弹出bar()方法堆栈块吗?请纠正我。谢谢。

这些值进入堆栈。运算符位于指令流中。大概是这样的:

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
这些值进入堆栈。运算符位于指令流中。大概是这样的:

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

谢谢你的回答。这是否意味着“x1+x2”被视为add()堆栈块并被推到bar()堆栈块的顶部?因为我有20个值,这意味着我有19个add()堆栈块,对吗?或者它们会在某个时候突然出现?我不知道你所说的“堆栈块”是什么意思,但你可以从我发布的伪字节码中看到,在这种情况下,堆栈上的项目不会超过两个。谢谢。很抱歉迟了答复。在编辑了答案后,我已经理解了你的意思。另外,我引用了激活记录堆栈的这个链接()。这和你问的差不多,对吗?谢谢你的回答。这是否意味着“x1+x2”被视为add()堆栈块并被推到bar()堆栈块的顶部?因为我有20个值,这意味着我有19个add()堆栈块,对吗?或者它们会在某个时候突然出现?我不知道你所说的“堆栈块”是什么意思,但你可以从我发布的伪字节码中看到,在这种情况下,堆栈上的项目不会超过两个。谢谢。很抱歉迟了答复。在编辑了答案后,我已经理解了你的意思。另外,我引用了激活记录堆栈的这个链接()。这和你说的差不多,对吗?