Java类中允许的最大代码行数? [英] Maximum lines of code permitted in a Java class?

查看:1249
本文介绍了Java类中允许的最大代码行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.java 文件包含多少行代码?它是否依赖于正在使用的JVM?

How many lines of code can a .java file contain? Does it depend on the JVM being used?

推荐答案

扩展 Jonas的回复,Java虚拟机规范,章节4.8对Java虚拟机代码的约束表示:

To extend upon Jonas's response, the Java Virtual Machine Specification, Section 4.8 Constraints on Java Virtual Machine Code says that:


$的Java虚拟机代码b $ b方法,实例初始化方法
(§3.9),或类或接口
初始化方法(§3.9)在
属性的代码数组中存储
一个类文件的method_info结构
。本节
描述了

Code_attribute结构内容相关的约束。

The Java virtual machine code for a method, instance initialization method (§3.9), or class or interface initialization method (§3.9) is stored in the code array of the Code attribute of a method_info structure of a class file. This section describes the constraints associated with the contents of the Code_attribute structure.

继续到4.8.1节,静态约束

Continuing to Section 4.8.1, Static Constraints


类文件
的静态约束是定义格式良好的那些
的文件。除了类文件的Java虚拟
机器代码上的
静态约束之外,这些
约束已在
previous部分中给出。类文件中Java虚拟
机器代码的静态
约束指定
如何在代码数组中布置Java虚拟机指令

是什么单个
指令的操作数必须是。

The static constraints on a class file are those defining the well-formedness of the file. With the exception of the static constraints on the Java virtual machine code of the class file, these constraints have been given in the previous section. The static constraints on the Java virtual machine code in a class file specify how Java virtual machine instructions must be laid out in the code array and what the operands of individual instructions must be.

代码数组中
指令的静态约束如下:
如下:

The static constraints on the instructions in the code array are as follows:

...


  • code_length项的值必须小于65536。

...

所以每个方法的方法确实有65535字节的字节码限制。 (请参阅下面的注释)

So a method does have a limit of 65535 bytes of bytecode per method. (see note below)

有关JVM的更多限制,请参阅章节4.10 Java虚拟机的限制

For more limitations to the JVM, see Section 4.10 Limitations of the Java Virtual Machine.

注意:尽管JVM的设计显然存在问题,但如果字节65535处的指令是1字节长的指令,则它不受异常处理程序的保护 - 这是列于第4.10节的脚注4中。

Note: Although there is apparently a problem with the design of the JVM, where if the instruction at byte 65535 is an instruction that is 1 byte long, it is not protected by exception handler - this is listed in footnote 4 of Section 4.10.

这篇关于Java类中允许的最大代码行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆