Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
* Multi type dispatcher for binary expression backend combining indy and static compilation
*
* @since 2.5.0
* @deprecated 6.0.0
*/
@Deprecated(since = "6.0.0")
public class IndyStaticTypesMultiTypeDispatcher extends StaticTypesBinaryExpressionMultiTypeDispatcher {

Check warning on line 42 in src/main/java/org/codehaus/groovy/classgen/asm/indy/sc/IndyStaticTypesMultiTypeDispatcher.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=apache_groovy&issues=AZ5BMcqnc-PA8pjUJITA&open=AZ5BMcqnc-PA8pjUJITA&pullRequest=2546
/**
* Creates a dispatcher that combines static compilation and indy array access.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import org.codehaus.groovy.classgen.asm.TypeChooser;
import org.codehaus.groovy.classgen.asm.UnaryExpressionHelper;
import org.codehaus.groovy.classgen.asm.WriterController;
import org.codehaus.groovy.classgen.asm.indy.sc.IndyStaticTypesMultiTypeDispatcher;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.objectweb.asm.ClassVisitor;

import static org.codehaus.groovy.transform.sc.StaticCompilationVisitor.isStaticallyCompiled;
Expand Down Expand Up @@ -91,11 +89,7 @@ public void init(final AsmClassGenerator asmClassGenerator, final GeneratorConte
this.lambdaWriter = new StaticTypesLambdaWriter(this);
this.methodReferenceExpressionWriter = new StaticTypesMethodReferenceExpressionWriter(this);
this.unaryExpressionHelper = new StaticTypesUnaryExpressionHelper(this);

CompilerConfiguration config = cn.getCompileUnit().getConfig();
this.binaryExpressionHelper = config.isIndyEnabled()
? new IndyStaticTypesMultiTypeDispatcher(this)
: new StaticTypesBinaryExpressionMultiTypeDispatcher(this);
this.binaryExpressionHelper = new StaticTypesBinaryExpressionMultiTypeDispatcher(this);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.codehaus.groovy.classgen.asm.sc
import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
import org.junit.jupiter.api.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
import org.junit.jupiter.params.provider.ValueSource

import static org.codehaus.groovy.control.CompilerConfiguration.DEFAULT as config
Expand All @@ -32,41 +33,59 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue
final class CombinedIndyAndStaticCompilationTest extends AbstractBytecodeTestCase {

@ParameterizedTest
@ValueSource(strings=['byte','short','int','long','float','double','boolean','char'])
void testArrayRead(String type) {
@CsvSource([
'byte, bArray, B',
'short, sArray, S',
'int, intArray, I',
'long, lArray, J',
'float, fArray, F',
'double, dArray, D',
'boolean, zArray, Z',
'char, cArray, C',
'Object, objectArray, Ljava/lang/Object;'])
void testArrayRead(String typeSource, String namePart, String typeByteCode) {
assumeTrue config.indyEnabled

def bytecode = compile method:'test', """
@groovy.transform.CompileStatic
void test() {
${type}[] array = new ${type}[10]
${type} x = array[0]
${typeSource}[] array = new ${typeSource}[10]
${typeSource} x = array[0]
}
"""
int offset = bytecode.indexOf('--BEGIN--') + 4
assert bytecode.indexOf('INVOKEDYNAMIC', offset) > offset
assert bytecode.indexOf('INVOKEDYNAMIC', offset) < bytecode.indexOf('--END--')
assert bytecode.indexOf(createGetter(typeByteCode, namePart), offset) > offset
assert bytecode.indexOf(createGetter(typeByteCode, namePart), offset) < bytecode.indexOf('--END--')
}

@ParameterizedTest
@ValueSource(strings=['byte','short','int','long','float','double','boolean','char'])
void testArrayWrite(String type) {
@CsvSource([
'byte, bArray, B',
'short, sArray, S',
'int, intArray, I',
'long, lArray, J',
'float, fArray, F',
'double, dArray, D',
'boolean, zArray, Z',
'char, cArray, C',
'Object, objectArray, Ljava/lang/Object;'])
void testArrayWrite(String typeSource, String namePart, String typeByteCode) {
assumeTrue config.indyEnabled

def bytecode = compile method:'test', """
@groovy.transform.CompileStatic
void test() {
${type}[] array = new ${type}[10]
${typeSource}[] array = new ${typeSource}[10]
array[0] = 1
}
"""
int offset = bytecode.indexOf('--BEGIN--') + 4
assert bytecode.indexOf('INVOKEDYNAMIC', offset) > offset
assert bytecode.indexOf('INVOKEDYNAMIC', offset) < bytecode.indexOf('--END--')
assert bytecode.indexOf(createSetter(typeByteCode, namePart), offset) > offset
assert bytecode.indexOf(createSetter(typeByteCode, namePart), offset) < bytecode.indexOf('--END--')
}

@ParameterizedTest
@ValueSource(strings=['byte','short','int','long','float','double','char'])
@ValueSource(strings=['byte','short','int','long','float','double','char','Object'])
void testNegativeIndex(String type) {
assertScript """
@groovy.transform.CompileStatic
Expand Down Expand Up @@ -149,4 +168,15 @@ final class CombinedIndyAndStaticCompilationTest extends AbstractBytecodeTestCas
assert bytecode.indexOf('INVOKESTATIC ', offset) > offset
assert bytecode.indexOf('INVOKESTATIC ', offset) < bytecode.indexOf('RETURN', offset)
}

private String createSetter(String typeByteCode, String namePart) {
return "INVOKESTATIC org/codehaus/groovy/runtime/BytecodeInterface8." +
namePart + "Set ([" + typeByteCode + "I" + typeByteCode + ")V"
}

private String createGetter(String typeByteCode, String namePart) {
return "INVOKESTATIC org/codehaus/groovy/runtime/BytecodeInterface8." +
namePart + "Get ([" + typeByteCode + "I)" + typeByteCode

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,7 @@ final class StaticCompilationTest extends AbstractBytecodeTestCase {
'ALOAD 1',
'ICONST_0',
'ILOAD 2',
'INVOKEDYNAMIC set([III)V [',
'// handle kind 0x6 : INVOKESTATIC',
'org/codehaus/groovy/vmplugin/v8/IndyInterface.staticArrayAccess',
'// arguments: none',
']',
'INVOKESTATIC org/codehaus/groovy/runtime/BytecodeInterface8.intArraySet ([III)V',
'L1',
'LINENUMBER 4',
'RETURN'
Expand Down
Loading