[m-rev.] diff: split scalar init code in java

Peter Wang novalazy at gmail.com
Mon Jan 24 16:29:39 AEDT 2011


Branches: main, 11.01

compiler/mlds_to_java.m:
        Divide the generated Java code to initialise scalar data into small
        methods to avoid running into the maximum method size limit.

diff --git a/compiler/mlds_to_java.m b/compiler/mlds_to_java.m
index 4600e4f..907874f 100644
--- a/compiler/mlds_to_java.m
+++ b/compiler/mlds_to_java.m
@@ -2541,11 +2541,18 @@ output_scalar_common_data(Info, Indent, ScalarCellGroupMap, !IO) :-
         digraph.init, Graph, map.init, Map, !IO),
 
     ( digraph.tsort(Graph, SortedScalars0) ->
+        % Divide into small methods to avoid running into the maximum method
+        % size limit.
+        list.reverse(SortedScalars0, SortedScalars),
+        list.chunk(SortedScalars, 1000, ScalarChunks),
+        list.foldl2(output_scalar_init_method(Info, Indent, Map),
+            ScalarChunks, 0, NumChunks, !IO),
+
+        % Call the individual methods.
         indent_line(Indent, !IO),
         io.write_string("static {\n", !IO),
-        list.reverse(SortedScalars0, SortedScalars),
-        list.foldl(output_scalar_init(Info, Indent + 1, Map),
-            SortedScalars, !IO),
+        int.fold_up(output_call_scalar_init_method(Indent + 1),
+            0, NumChunks - 1, !IO),
         indent_line(Indent, !IO),
         io.write_string("}\n", !IO)
     ;
@@ -2671,6 +2678,18 @@ add_scalar_deps_rval_const(FromScalar, RvalConst, !Graph) :-
         )
     ).
 
+:- pred output_scalar_init_method(java_out_info::in, indent::in,
+    map(mlds_scalar_common, mlds_initializer)::in,
+    list(mlds_scalar_common)::in, int::in, int::out, io::di, io::uo) is det.
+
+output_scalar_init_method(Info, Indent, Map, Scalars,
+        ChunkNum, ChunkNum + 1, !IO) :-
+    indent_line(Indent, !IO),
+    io.format("static void MR_init_scalars_%d() {\n", [i(ChunkNum)], !IO),
+    list.foldl(output_scalar_init(Info, Indent + 1, Map), Scalars, !IO),
+    indent_line(Indent, !IO),
+    io.write_string("}\n", !IO).
+
 :- pred output_scalar_init(java_out_info::in, indent::in,
     map(mlds_scalar_common, mlds_initializer)::in, mlds_scalar_common::in,
     io::di, io::uo) is det.
@@ -2684,6 +2703,13 @@ output_scalar_init(Info, Indent, Map, Scalar, !IO) :-
     output_initializer_body(Info, Initializer, yes(Type), !IO),
     io.write_string(";\n", !IO).
 
+:- pred output_call_scalar_init_method(int::in, int::in, io::di, io::uo)
+    is det.
+
+output_call_scalar_init_method(Indent, ChunkNum, !IO) :-
+    indent_line(Indent, !IO),
+    io.format("MR_init_scalars_%d();\n", [i(ChunkNum)], !IO).
+
 :- pred output_vector_common_data(java_out_info::in, indent::in,
     ml_vector_cell_map::in, io::di, io::uo) is det.
 

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list