Skip to content

Commit

Permalink
Split up constant pool-stored persisted IR so we don't blow limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Apr 20, 2015
1 parent 8f642a2 commit d8bb622
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/ruby/stdlib/jruby/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def compile_files_with_options(filenames, options = default_options)
IRWriter.persist(stream, scope)
string = String.from_java_bytes(bytes.to_byte_array, 'BINARY')

# bust it up into 32k-1 chunks
pieces = string.scan(/.{1,32767}/m)

cls = ClassWriter.new(ClassWriter::COMPUTE_MAXS | ClassWriter::COMPUTE_FRAMES)
cls.visit(
Opcodes::V1_7,
Expand All @@ -185,7 +188,17 @@ def compile_files_with_options(filenames, options = default_options)
main.astore(1)
main.aload(1)
main.aload(1)
main.ldc(string)

# put String back together
main.newobj("java/lang/StringBuilder")
main.dup
main.invokespecial("java/lang/StringBuilder", "<init>", "()V")
pieces.each do |piece|
main.ldc(piece)
main.invokevirtual("java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;")
end
main.invokevirtual("java/lang/Object", "toString", "()Ljava/lang/String;")

main.ldc("ISO-8859-1")
main.invokevirtual("java/lang/String", "getBytes", "(Ljava/lang/String;)[B")
main.invokestatic("org/jruby/ir/runtime/IRRuntimeHelpers", "decodeScopeFromBytes", "(Lorg/jruby/Ruby;[B)Lorg/jruby/ir/IRScope;")
Expand Down

0 comments on commit d8bb622

Please sign in to comment.