Syncleus / aparapi

The New Official Aparapi: a framework for executing native Java and Scala code on the GPU.
http://aparapi.com
Apache License 2.0
466 stars 59 forks source link

Fix: Fix arrays of AtomicInteger stored on local variables no longer … #139

Closed CoreRasurae closed 6 years ago

CoreRasurae commented 6 years ago

…fail with type cast exception - Partial fix for (refs #138)

Currently Aparapi fails with a type cast exception on Arrays that are used as local variables, this was verified with arrays of AtomicInteger, but could possibly happen with other types. Since not all array variables are stored on class instance fields, AccessField type bytecode instructions, the ones that were stored on local variables use different bytecode instruction (LocalVariableConstIndexAccessor) and a type cast exception was generated. This fix adds support for I_ALOAD, I_ALOAD_0, I_ALOAD_1, I_ALOAD_2 and I_ALOAD_3 bytecode instructions which are used when arrays are stored as local variables.

This also provides a partial fix for #138

codecov-io commented 6 years ago

Codecov Report

Merging #139 into master will decrease coverage by 0.05%. The diff coverage is 14.28%.

@@             Coverage Diff              @@
##             master     #139      +/-   ##
============================================
- Coverage     46.44%   46.39%   -0.06%     
  Complexity      892      892              
============================================
  Files            60       60              
  Lines          9866     9877      +11     
  Branches       1608     1612       +4     
============================================
  Hits           4582     4582              
- Misses         4823     4832       +9     
- Partials        461      463       +2
CoreRasurae commented 6 years ago

@freemo Just made one last fix, this is now ready for merging. Previous commit didn't support I_ALOAD. It turns out that local variable arguments like are handled differently, that is, if array is the first argument func(arr, index) then I_ALOAD_0 is used. However for the second argument in func(index, arr) then I_ALOAD_1 is used, if func(index, indexA, arr) then I ALOAD_2 is used and so on, until index 4, at index 4, I_ALOAD is used instead, which supports non-const indexing (index > 3), so that the instruction has an additional field for specifying an 8 bit index of the local variable argument.