Bug 407349 - [inline] Inline Method could avoid array creation if varargs argument is passed on
Summary: [inline] Inline Method could avoid array creation if varargs argument is pass...
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2.1   Edit
Hardware: All All
: P5 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-06 20:20 EDT by Zorzella Mising name CLA
Modified: 2013-05-07 12:27 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zorzella Mising name CLA 2013-05-06 20:20:08 EDT
See code below. If "bar" is inlined, the resulting code is all messed up -- it thinks it needs to create arrays of the arguments:

******** BEFORE INLINE *********

class Foo {

	public void foo() {
		bar("b");
		bar();
	}
	
	public void bar(Object... args) {
		baz(args);
	}

	public void baz(Object... args) {
		System.out.println(args);
	}
}

******** AFTER INLINE ********


class Foo {

	public void foo() {
		Object[] args = { "b" };
		baz(args);
		Object[] args1 = {};
		baz(args1);
	}
	
	public void baz(Object... args) {
		System.out.println(args);
	}
}
Comment 1 Jay Arthanareeswaran CLA 2013-05-07 04:23:23 EDT
I don't know if you can call it all messed up. Agreed, we can do it with out the array. Just having a quick glance at CallInliner, this may be the intended behavior but I don't know what the reason could be.
Comment 2 Markus Keller CLA 2013-05-07 08:45:44 EDT
The refactoring is correct, since the invocation of the varargs method 'bar' implicitly creates the array.

In this special case where bar's args is not used for anything else and is directly passed to another varargs method (at most once), we could be smarter and avoid the array creation.

Small deviations from this special case already require the array variable (e.g. calling 'baz(args)' twice or accessing 'args.length').
Comment 3 Zorzella Mising name CLA 2013-05-07 12:27:30 EDT
I apologize for the sloppy "all messed up" remark (since it's functionally equivalent). I should have said it violates the principle of least astonishment, in this particular case. Thanks for looking into it. I also forgot the expected output:

******** EXPECTED AFTER INLINE ********

class Foo {

	public void foo() {
		baz("b");
		baz();
	}
	
	public void baz(Object... args) {
		System.out.println(args);
	}
}