Java“常量太多"JVM 错误

Java quot;too many constantsquot; JVM error(Java“常量太多JVM 错误)

本文介绍了Java“常量太多"JVM 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个在运行时生成和编译类的应用程序.这有时会产生大量的生成代码.

I'm developing an application that generates and compiles classes at runtime. This will sometimes create huge amounts of generated code.

对于我们的一个测试用例,我从 JVM 收到一个错误:

With one of our test cases, I'm getting an error from the JVM:

TestClass.java:83865: too many constants

就这个.我看过其他关于类似错误的报告,但在这些情况下,错误消息会抱怨常量池.但在这种情况下它不会.

Just this. I've seen other reports about a similar error, but on those cases the error message complains about the constant pool. But in this case it doesn't.

如果这意味着达到了 JVM 的常量池的限制,那是什么意思?我的意思是,就 Java 代码而言,这些常量是什么类型的?类方法?领域?字面意思?我没有静态或最终方法,也没有字段.

If this means that the limit on the JVM's constant pool was reached, what does it mean? I mean, what kind of constants are these in terms of Java code? Class methods? Fields? Literals? I have no static or final methods nor fields.

你能给我一些线索吗?

将代码拆分为多个类已在计划中.虽然不是因为这个确切的原因.

Splitting the code into multiple classes is already in schedule. Although it wasn't for this exact reason.

我知道常量池的限制,我的疑问正是其中的内容.生成的代码没有超过 10000 个方法+字段.

I' aware of the limits of the constant pool, my doubt was exactly what goes into into. The generated code doesn't have more that about 10000 methods+fields.

我怀疑文字是否也进入常量池,因为这是我看到将此数字提高到 65K 的唯一原因.好像是这样.

My doubt is if literals also go to the constant pool or not, since that's the only reason I see to raise this number up to 65K. It seems so.

推荐答案

http://en.wikipedia.org/wiki/Java_class_file#The_constant_pool

常量池包括数字、字符串、方法名、字段名、类名、对类和方法的引用……基本上一切.

The constant pool includes numbers, strings, method names, field names, class names, references to classes and methods...basically everything.

最多可以有 65536 个.

There can be at most 65536 of them.

这篇关于Java“常量太多"JVM 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Java“常量太多"JVM 错误

基础教程推荐