简体   繁体   English

如何在加载类时JVM验证没有潜在的操作数堆栈溢出?

[英]How can the JVM verify there's no potential operand stack overflow when loading a class?

Going over some presentation, I've come across the following claim: When the JVM loads a class, it can analyze its content and make sure there's no overflow or underflow of the operand stack . 经过一些演示,我遇到了以下声明:当JVM加载一个类时,它可以分析其内容并确保操作数堆栈没有溢出或下溢 I've found a lot of sources that make the same claim, but without specifying how it's done. 我发现很多来源都提出了相同的主张,但没有说明它是如何完成的。

It is unclear to me how such verification can be made using static analysis. 我不清楚如何使用静态分析进行此类验证。 Say I have a (malicious) method that gets some value as an argument, and uses it to perform a series of pops. 假设我有一个(恶意)方法,它可以获得一些值作为参数,并使用它来执行一系列弹出。 At load time, the number of iterations is not known, as it depends on the argument given by the method's caller. 在加载时,迭代次数是未知的,因为它取决于方法调用者给出的参数。 Therefore, it seems to me that only at runtime should it be possible to determined whether there will be an underflow or not. 因此,在我看来,只有在运行时才能确定是否会出现下溢。 What am I missing here? 我在这里错过了什么?

You can find basic description of the Bytecode Verifier in Java Virtual Machine specification . 您可以在Java虚拟机规范中找到Bytecode Verifier的基本描述。

To put it simple, stack depth is known at every branching point, and two execution paths merging at the same merge point must also have the same stack depth. 简单来说,堆栈深度在每个分支点都是已知的,并且在同一个合并点处合并的两个执行路径也必须具有相同的堆栈深度。 So, the verifier won't allow you to perform series of pops without corresponding puts. 因此,验证者不允许您在没有相应的放置的情况下执行一系列弹出。

The code of the method is split into execution blocks. 该方法的代码被分成执行块。 A "block" is a sequence of instructions that can be executed without jumping out or into. “块”是一系列指令,可以在不跳出或跳入的情况下执行。 The blocks build a directed graph of all possible execution paths. 这些块构建了所有可能执行路径的有向图。

A block always expects a certain stack size at its beginning and has a fixed stack size at its end (beginning + all the pushes - all the pops). 块总是期望在其开始时具有特定的堆栈大小并且在其末尾具有固定的堆栈大小(开始+所有推送 - 所有弹出)。 The verifier checks that for all blocks 'a' that can be reached from a given block 'b', the end stack-size of b matches the beginning stack-size of a. 验证器检查对于从给定块'b'可以到达的所有块'a',b的结束堆栈大小匹配a的开始堆栈大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jvm字大小和操作数堆栈 - jvm word size and operand stack JVM中操作数栈的作用是什么? - What is the role of operand stack in JVM? 如何在Javassist上获取JVM指令对其进行操作的操作数堆栈上的值? - How to get the values on operand stack which the JVM instruction operates on with Javassist? 我应该如何解释 JVM 指令集文档中的“操作数堆栈”? - How should I interpret “Operand Stack” in JVM Instruction Set docs? Switch 语句 - JVM 内存分配、堆栈溢出 - Switch statements - JVM memory allocation, stack overflow 如何在Sun的JVM中禁用延迟类加载/初始化? - How do you disable lazy class loading/initialization in Sun's JVM? JVM中的分段错误会导致堆栈溢出,但仅限于VMWare - Segmentation fault in JVM for stack overflow, but only on VMWare JVM什么时候在堆栈跟踪中省略行信息,如何防止它? - When does the JVM omit line info in a stack trace and how can I prevent it? 当JVM类路径中的类尝试访问Web应用程序库中可用的类时,如何克服Java中的类加载问题 - how to overcome class loading issues in java when a class in JVM class path tries to access the class available in a web applications lib 如何解决此堆栈溢出错误? - How can I solve this Stack Overflow error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM