java - Java 6 类加载速度有哪些?

标签 java performance jvm classloader

ProGuard主页列表作为一项功能:

  • 重新定位和预验证 Java 6 的现有类文件,以采取 充分利用 Java 6 更快的类加载。

this 指的是 Java 6 有什么不同?

重要吗?

它对通过默认类加载器的同步方面的多线程导致的速度降低有影响吗?

最佳答案

作为ProGuard FAQ hints :

the Java 6 compiler add preverification information to the class files

查看 Java Virtual Machine Specification Verification by Type Checking部分:

If a Java virtual machine implementation ever attempts to perform verification by type inference on version 50.0 class files, it must do so in all cases where verification by typechecking fails.

This means that a Java virtual machine implementation cannot choose to resort to type inference in once case and not in another. It must either reject class files that do not verify via typechecking, or else consistently failover to the type inferencing verifier whenever typechecking fails.

The type checker requires a list of stack map frames for each method with a Code attribute. The type checker reads the stack map frames for each such method and uses these maps to generate a proof of the type safety of the instructions in the Code attribute.

从 Java 6、类文件 50.0 及更高版本开始,JVM 可以在类文件验证期间使用类型检查或类型推断。在尝试了解性能优势之前,什么是类型检查和类型推断?本文,Type-Checking and Type-Inference for Object-Oriented Programming Languages状态:

A type system is an important part of a programming language. Languages that rely completely on run-time type-checking provide a high degree of flexibility but must usually sacrifice performance to do so.

来自维基百科 Type inference :

Type inference is the ability to automatically deduce, either partially or fully, the type of an expression at compile time. [...]

To obtain the information required to infer the type of an expression, the compiler either gathers this information as an aggregate and subsequent reduction of the type annotations given for its subexpressions, or through an implicit understanding of the type of various atomic values [...].

OpenJDK HotSport Runtime Overview解释得很好:

There are currently two methods of analyzing the bytecodes to determine the types and number of operands that will be present for each instruction. The traditional method is called “type inference”, and operates by performing an abstract interpretation of each bytecode and merging type states at branch targets or exception handles. The analysis iterates over the bytecode until a steady state for the types are found. If a steady state cannot be found, or if the resulting types violate some bytecode constraint, then a VerifyError is thrown. [...]

New in JDK6 is the second method for verification which is called “type verification”. In this method the Java compiler provides the steady-state type information for each branch or exception target, via the code attribute, StackMapTable. The StackMapTable consists of a number of stack map frames, each which indicates the types of the items on the expression stack and in the local variables at some offset in the method. The JVM needs to then only perform one pass through the bytecode to verify the correctness of the types to verify the bytecode. [...]

类型检查意味着 JVM 可以通过类文件来验证类型系统;类型推断需要多次通过。这是显着的性能节省吗?它可能与应用程序中的类总数以及小于 50.0 (Java 6) 和 50.0 及更高版本的类文件数量有关。如果您的应用程序不是性能关键型应用程序,我不会担心;如果是,那么您可以运行一些基准测试,比较将应用程序编译为 Java 5 和 Java 6 类文件时的性能差异。

关于java - Java 6 类加载速度有哪些?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10724942/

相关文章:

multithreading - Numba 是 "only"将我的代码改进了 4 倍。它能做得更好吗?

python - 方法是否用类实例化,消耗大量内存(在 Scala 中)?

java - 是否有 -noverify jvm 标志的替代方案?

java - <小程序> 与 <对象>

mysql - 为什么 Solr 5.3.x 中的导入过程非常慢?

android - 通过 intents 传递大量数据时崩溃 - extras 包是否有大小限制?

java - java进程中有很多线程

java - 切换垂直 JScrollBar 最小/最大位置

java - HomeFragment 无法转换为 Fragment

java - eXist xml db : java. lang.NoClassDefFoundError: org/apache/ws/commons/serialize/DOMSerializer