Java “too many constants” JVM error

后端 未结 4 1908
广开言路
广开言路 2020-12-16 19:51

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

With one of our test cases,

4条回答
  •  爱一瞬间的悲伤
    2020-12-16 20:26

    From: JVM Spec

    you can see that the classfile.constant_pool_count has a 'u2' type, which limits it to 65535 entries

    ClassFile {
        u4 magic;
        u2 minor_version;
        u2 major_version;
        u2 constant_pool_count;
        cp_info constant_pool[constant_pool_count-1];
        u2 access_flags;
        u2 this_class;
        u2 super_class;
        u2 interfaces_count;
        u2 interfaces[interfaces_count];
        u2 fields_count;
        field_info fields[fields_count];
        u2 methods_count;
        method_info methods[methods_count];
        u2 attributes_count;
        attribute_info attributes[attributes_count];
    }
    

提交回复
热议问题