Technical Notes

Generated Code Exceeds Java Limits

There are cases when the generated Java code exceeds Java limits and module compilation will fail with an exception like:

Caused by: java.lang.RuntimeException:
    Compiling "translationUtils_589309CA2A3A2B4C11A70745E6433330":
    Code of method "fieldMethod0(Lcom/streambase/sb/Tuple;Lcom/streambase/sb/runtime/CaptureManager;Lcom/streambase/sb/runtime/RuntimeEnv;[Lcom/streambase/sb/Schema$Field;Lcom/streambase/cache/SharedDataClass_589309CA2A3A2B4C11A70745E6433330;)V"
    of class "com.streambase.cache.translationUtils_589309CA2A3A2B4C11A70745E6433330" grows beyond 64 KB

The typical cause of this failure is a very large schema definition.

When this error occurs these system properties can be used to force the generated code to be refactored to work-around the Java limits.

System Property Values Description
streambase.codegen.allow-refactoring true to enable refactoring, false to disable. Default value is false. Enable refactoring.
streambase.codegen.n-stmts-limit Positive integer > 1. Default value is 300. Maximum number of statements in a block. streambase.codegen.allow-refactoring must be true.
streambase.codegen.broken-method-names Comma separated list of fully-qualified-method-name:refactor-value or simple-method-name:refactor-value values. refactor-value must be less than the value of streambase.codegen.n-stmts-limit. Maximum number of statements in a block for a specific method. streambase.codegen.allow-refactoring must be true.

The streambase.codegen.n-stmts-limit system property is applied to all generated methods, not just the ones that exceed the Java constraints. Specific methods can be refactored using the streambase.codegen.broken-method-names system property. The streambase.codegen.broken-method-names system property is the recommended mechanism for resolving compilation failures.

Refactoring blocks into fewer statements generates more entries in the JVM constant pool because more methods are generated.

When a compilation failure of generated source occurs because of a Java constraint violation, the recommended approach is to take these steps in order, recompiling after each change.

  1. Enable the streambase.codegen.allow-refactoring system property, e.g. -Dstreambase.codegen.allow-refactoring=true
  2. Optionally fine tune the statement block size used for refactoring specific methods using the streambase.codegen.broken-method-names system property and these steps:
    1. Enable the streambase.codegen.broken-method-names system property for the specific failed method, e.g. -Dstreambase.codegen.broken-method-names=com.streambase.cache.translationUtils.fieldMethod0:10
    2. Add additional methods to the streambase.codegen.broken-method-names system property for additional failed methods, e.g. -Dstreambase.codegen.broken-method-names=com.streambase.cache.translationUtils.fieldMethod0:10,fieldMethod1:10
    3. Continue adding methods until all compilation failures are resolved.
  3. Optionally change the default value of the streambase.codegen.n-stmts-limit system property to change the refactoring block size of all methods. Reducing this value from the default value may avoid exceeding Java constraints, e.g. -Dstreambase.codegen.n-stmts-limit=150

Individual Method Refactor Value

The refactor-value set in the streambase.codegen.broken-method-names system property is calculated as the value of the streambase.codegen.n-stmts-limit system property divided by the specified refactor-value. For example if streambase.codegen.n-stmts-limit is set to 100 and the refactor-value is set to 10, the method will be refactored into blocks with a maximum of 10 (100/10) statements.