Java“太多常数” JVM错误 [英] Java "too many constants" JVM error

查看:198
本文介绍了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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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