This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in CodeAttr.emitElse(..)



The CodeAttr class's handling of its 'stack_types' field seems pretty
sketchy.  A large number of the methods in CodeAttr assume that the
field has been initialized to point to an appropriately sized array,
but this invariant is not maintained throughout the class.

Here is a snippet of Scheme code that demonstrates one instance of
this problem, though I suspect there are others.

(lambda (x u)
  (let ((y (lambda (z) x z)))
    (if #t x u)
    (y x)))

[[ stack trace resulting from interpreting the above expression is at
   end of the email ]]


The only place that 'stack_types' seems to be intialized is in the
method pushType(Type).  I am not sure whether Per intended to insert
null-checks around every access to 'stack_types', or if there was some
other initialization strategy he was intending.  

There is the following note above the field's declaration:

  // In hindsight, maintaining stack_types is more hassle than it is worth.
  // Instead, better to just keep track of SP, which should catch most
  // stack errors, while being more general and less hassle.  FIXME.
  Type[] stack_types;

So it seems that the real solution is to get rid of stack_types.  That
seems like a somewhat large non-localized change though.  In the
meantime, is the correct fix just to add guards around the calls to
System.arraycopy, or to preinitialize 'stack_types', or... ?

-Felix
       

-- STACK TRACE FROM KAWA when interpreting the above expression --

<stdin>:3:6: internal error while compiling - caught: java.lang.NullPointerException
java.lang.NullPointerException
	at java.lang.System.arraycopy(Native Method)
	at gnu.bytecode.CodeAttr.emitElse(CodeAttr.java:1347)
	at gnu.expr.IfExp.compile(IfExp.java:115)
	at gnu.expr.IfExp.compile(IfExp.java:51)
	at gnu.expr.Expression.compileNotePosition(Expression.java:60)
	at gnu.expr.Expression.compileWithPosition(Expression.java:47)
	at gnu.expr.BeginExp.compile(BeginExp.java:79)
	at gnu.expr.Expression.compileWithPosition(Expression.java:50)
	at gnu.expr.LetExp.compile(LetExp.java:73)
	at gnu.expr.Expression.compileNotePosition(Expression.java:60)
	at gnu.expr.Expression.compileWithPosition(Expression.java:47)
	at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1411)
	at gnu.expr.LambdaExp.compileAsMethod(LambdaExp.java:1383)
	at gnu.expr.LambdaExp.compileSetField(LambdaExp.java:577)
	at gnu.expr.LambdaExp.compile(LambdaExp.java:673)
	at gnu.expr.Expression.compileNotePosition(Expression.java:60)
	at gnu.expr.Expression.compileWithPosition(Expression.java:47)
	at gnu.expr.LambdaExp.compileBody(LambdaExp.java:1411)
	at gnu.expr.Compilation.addClass(Compilation.java:1154)
	at gnu.expr.Compilation.<init>(Compilation.java:633)
	at gnu.expr.ModuleExp.evalToClass(ModuleExp.java:70)
	at gnu.expr.ModuleExp.eval(ModuleExp.java:38)
	at gnu.expr.ModuleExp.evalModule(ModuleExp.java:180)
	at kawa.Shell.run(Shell.java:77)
	at kawa.Shell.run(Shell.java:32)
	at kawa.Shell.run(Shell.java:19)
	at kawa.repl.main(repl.java:372)



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]