@@ -29,10 +29,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
29
29
30
30
val phaseName = " jvm"
31
31
32
- case class WorkUnit (label : String , jclassName : String , jclass : asm.ClassWriter , outF : AbstractFile )
33
-
34
- type WorkUnitQueue = _root_.java.util.concurrent.LinkedBlockingQueue [WorkUnit ]
35
-
36
32
/** Create a new phase */
37
33
override def newPhase (p : Phase ): Phase = new AsmPhase (p)
38
34
@@ -152,44 +148,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
152
148
}
153
149
}
154
150
155
- // -----------------------------------------------------------------------------------------
156
- // Allow overlapping disk write of classfiles with building of the next classfiles.
157
- // -----------------------------------------------------------------------------------------
158
-
159
- val q = new WorkUnitQueue (500 )
160
-
161
- class WriteTask (bytecodeWriter : BytecodeWriter ) extends _root_.java.lang.Runnable {
162
-
163
- def run () {
164
- var stop = false
165
- try {
166
- while (! stop) {
167
- val WorkUnit (label, jclassName, jclass, outF) = q.take
168
- if (jclass eq null ) { stop = true }
169
- else { writeIfNotTooBig(label, jclassName, jclass, outF) }
170
- }
171
- } catch {
172
- case ex : InterruptedException => throw ex
173
- }
174
- }
175
-
176
- private def writeIfNotTooBig (label : String , jclassName : String , jclass : asm.ClassWriter , outF : AbstractFile ) {
177
- try {
178
- val arr = jclass.toByteArray()
179
- bytecodeWriter.writeClass(label, jclassName, arr, outF)
180
- } catch {
181
- case e : java.lang.RuntimeException if (e.getMessage() == " Class file too large!" ) =>
182
- // TODO check where ASM throws the equivalent of CodeSizeTooBigException
183
- log(" Skipped class " + jclassName+ " because it exceeds JVM limits (it's too big or has methods that are too long)." )
184
- }
185
- }
186
-
187
- }
188
-
189
- // -----------------------------------------------------------------------------------------
190
- // what AsmPhase does.
191
- // -----------------------------------------------------------------------------------------
192
-
193
151
override def run () {
194
152
195
153
if (settings.debug.value)
@@ -203,14 +161,10 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
203
161
var sortedClasses = classes.values.toList sortBy (" " + _.symbol.fullName)
204
162
205
163
debuglog(" Created new bytecode generator for " + classes.size + " classes." )
206
- val bytecodeWriter = initBytecodeWriter(sortedClasses filter isJavaEntryPoint)
207
- val needsOutfileForSymbol = bytecodeWriter.isInstanceOf [ClassBytecodeWriter ]
208
-
209
- val plainCodeGen = new JPlainBuilder (q, needsOutfileForSymbol)
210
- val mirrorCodeGen = new JMirrorBuilder (q, needsOutfileForSymbol)
211
- val beanInfoCodeGen = new JBeanInfoBuilder (q, needsOutfileForSymbol)
212
-
213
- new _root_.java.lang.Thread (new WriteTask (bytecodeWriter)).start()
164
+ val bytecodeWriter = initBytecodeWriter(sortedClasses filter isJavaEntryPoint)
165
+ val plainCodeGen = new JPlainBuilder (bytecodeWriter)
166
+ val mirrorCodeGen = new JMirrorBuilder (bytecodeWriter)
167
+ val beanInfoCodeGen = new JBeanInfoBuilder (bytecodeWriter)
214
168
215
169
while (! sortedClasses.isEmpty) {
216
170
val c = sortedClasses.head
@@ -233,10 +187,6 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
233
187
classes -= c.symbol // GC opportunity
234
188
}
235
189
236
- q put WorkUnit (null , null , null , null )
237
-
238
- while (! q.isEmpty) { _root_.java.lang.Thread .sleep(10 ) }
239
-
240
190
bytecodeWriter.close()
241
191
classes.clear()
242
192
reverseJavaName.clear()
@@ -498,7 +448,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
498
448
val JAVA_LANG_STRING = asm.Type .getObjectType(" java/lang/String" )
499
449
500
450
/** basic functionality for class file building */
501
- abstract class JBuilder (wuQ : WorkUnitQueue , needsOutfileForSymbol : Boolean ) {
451
+ abstract class JBuilder (bytecodeWriter : BytecodeWriter ) {
502
452
503
453
val EMPTY_JTYPE_ARRAY = Array .empty[asm.Type ]
504
454
val EMPTY_STRING_ARRAY = Array .empty[String ]
@@ -554,6 +504,17 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
554
504
// utitilies useful when emitting plain, mirror, and beaninfo classes.
555
505
// -----------------------------------------------------------------------------------------
556
506
507
+ def writeIfNotTooBig (label : String , jclassName : String , jclass : asm.ClassWriter , sym : Symbol ) {
508
+ try {
509
+ val arr = jclass.toByteArray()
510
+ bytecodeWriter.writeClass(label, jclassName, arr, sym)
511
+ } catch {
512
+ case e : java.lang.RuntimeException if (e.getMessage() == " Class file too large!" ) =>
513
+ // TODO check where ASM throws the equivalent of CodeSizeTooBigException
514
+ log(" Skipped class " + jclassName+ " because it exceeds JVM limits (it's too big or has methods that are too long)." )
515
+ }
516
+ }
517
+
557
518
/** Specialized array conversion to prevent calling
558
519
* java.lang.reflect.Array.newInstance via TraversableOnce.toArray
559
520
*/
@@ -767,18 +728,11 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
767
728
}
768
729
}
769
730
770
- def enqueue (label : String , jclassName : String , jclass : asm.ClassWriter , sym : Symbol ) {
771
- val outF : scala.tools.nsc.io.AbstractFile = {
772
- if (needsOutfileForSymbol) getFile(sym, jclassName, " .class" ) else null
773
- }
774
- wuQ put WorkUnit (label, jclassName, jclass, outF)
775
- }
776
-
777
731
} // end of class JBuilder
778
732
779
733
780
734
/** functionality for building plain and mirror classes */
781
- abstract class JCommonBuilder (wuQ : WorkUnitQueue , needsOutfileForSymbol : Boolean ) extends JBuilder (wuQ, needsOutfileForSymbol ) {
735
+ abstract class JCommonBuilder (bytecodeWriter : BytecodeWriter ) extends JBuilder (bytecodeWriter ) {
782
736
783
737
def debugLevel = settings.debuginfo.indexOfChoice
784
738
@@ -1342,8 +1296,8 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
1342
1296
case class BlockInteval (start : BasicBlock , end : BasicBlock )
1343
1297
1344
1298
/** builder of plain classes */
1345
- class JPlainBuilder (wuQ : WorkUnitQueue , needsOutfileForSymbol : Boolean )
1346
- extends JCommonBuilder (wuQ, needsOutfileForSymbol )
1299
+ class JPlainBuilder (bytecodeWriter : BytecodeWriter )
1300
+ extends JCommonBuilder (bytecodeWriter )
1347
1301
with JAndroidBuilder {
1348
1302
1349
1303
val MIN_SWITCH_DENSITY = 0.7
@@ -1499,7 +1453,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
1499
1453
1500
1454
addInnerClasses(clasz.symbol, jclass)
1501
1455
jclass.visitEnd()
1502
- enqueue (" " + c.symbol.name, thisName, jclass, c.symbol)
1456
+ writeIfNotTooBig (" " + c.symbol.name, thisName, jclass, c.symbol)
1503
1457
1504
1458
}
1505
1459
@@ -2938,7 +2892,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
2938
2892
2939
2893
2940
2894
/** builder of mirror classes */
2941
- class JMirrorBuilder (wuQ : WorkUnitQueue , needsOutfileForSymbol : Boolean ) extends JCommonBuilder (wuQ, needsOutfileForSymbol ) {
2895
+ class JMirrorBuilder (bytecodeWriter : BytecodeWriter ) extends JCommonBuilder (bytecodeWriter ) {
2942
2896
2943
2897
private var cunit : CompilationUnit = _
2944
2898
def getCurrentCUnit (): CompilationUnit = cunit;
@@ -2984,15 +2938,15 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
2984
2938
2985
2939
addInnerClasses(modsym, mirrorClass)
2986
2940
mirrorClass.visitEnd()
2987
- enqueue (" " + modsym.name, mirrorName, mirrorClass, modsym)
2941
+ writeIfNotTooBig (" " + modsym.name, mirrorName, mirrorClass, modsym)
2988
2942
}
2989
2943
2990
2944
2991
2945
} // end of class JMirrorBuilder
2992
2946
2993
2947
2994
2948
/** builder of bean info classes */
2995
- class JBeanInfoBuilder (wuQ : WorkUnitQueue , needsOutfileForSymbol : Boolean ) extends JBuilder (wuQ, needsOutfileForSymbol ) {
2949
+ class JBeanInfoBuilder (bytecodeWriter : BytecodeWriter ) extends JBuilder (bytecodeWriter ) {
2996
2950
2997
2951
/**
2998
2952
* Generate a bean info class that describes the given class.
@@ -3113,7 +3067,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
3113
3067
addInnerClasses(clasz.symbol, beanInfoClass)
3114
3068
beanInfoClass.visitEnd()
3115
3069
3116
- enqueue (" BeanInfo " , beanInfoName, beanInfoClass, clasz.symbol)
3070
+ writeIfNotTooBig (" BeanInfo " , beanInfoName, beanInfoClass, clasz.symbol)
3117
3071
}
3118
3072
3119
3073
} // end of class JBeanInfoBuilder
0 commit comments