You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

1

Tuesday, January 13th 2009, 10:04pm

Jabaco compiler does not optimize

Hi all,

to experiment with the optimization capabilities of the Jabaco compiler, I played around with Jabaco using the following:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Option Explicit 
Public Sub main(ByJava args() As String) 
Dim a As Integer 
Dim s As String 
Dim b As Boolean 

a = a 
a = 0 + a 
a = a + 0 
a = 1 * a 
a = a * 1 
a = 3 * 2 

s = s 
s = s & "" 
s = "" & s 
s = "a" & "b" 

If False And b Then 
b = False And b 
b = b And False 
b = True Or b 
b = b Or True 
End If 

' resulting java byte code 
' does not show any optimization 
' int a = 0; 
' String s = ""; 
' a = a; 
' a = 0 + a; 
' a += 0; 
' a = 1 * a; 
' a *= 1; 
' a = 3 * 2; 
' s = s; 
' s = VBString.appendStrings(s, ""); 
' s = VBString.appendStrings("", s); 
' s = VBString.appendStrings("a", "b"); 


' If(False & b) 
' { 
' b = False & b; 
' b &= False; 
' b = True | b; 
' b |= True; 
' } 

' for comparison: 
' result of a Java compilation (JDK 1.5) 
' a = a; 
' a = 0 + a; 
' a = a + 0; 
' a = 1 * a; 
' a = a * 1; 
' a = 6; // 2 * 3 folded to 6; VB6 does the same 
' s = s; 
' s = (New StringBuilder()).append(s).append("").toString(); 
' s = (New StringBuilder()).append("").append(s).toString(); 
' s = "ab"; // "a" + "b" folded to "ab" 
' If(False & b) 
' { 
' b = False & b; 
' b &= False; 
' b = True | b; 
' b |= True; 
' } 

End Sub


The result:

Jabaco does not perform any (?) optimization during compilation. It should be noted, however, that neither the Javac compiler of JDK 1.5 nor the original VB6 compiler do perform optimization. There are small exceptions: Javac as well as VB do constant folding, i.e. they translate experessions like "2*3" to "6" at compile time. Javac resolves concatenation of string literals at compile time.

Optimization may become important when it comes to evaluation of boolean expressions in if .. then .. end if constructs. Jabaco does not support "shut cut" mode. The full boolean expression with all constituent parts is evaluated even if the false/true result can be determined early. A "c" program would not evaluate "b()" in expression "a() && b()" unless "a()" returns a non-zero TRUE value. Jabaco evaluate "a()" and "b()" in expression "a() AND b()" regardless of the return value of "a()".

Happy optimizing and experimenting!

A1880

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

2

Tuesday, January 13th 2009, 11:05pm

Thank you for testing...

Quoted

Jabaco does not perform any (?) optimization during compilation.
There are many possibilities to optimize the bytecode. I'll support few methods in future - but - this feature have a very low priority for the Jabaco project. The compile-time optimization is unnecessary for newer JVM-versions. The Sun JVM does that job very well and your performance grow on every Java update. Get more informations at the Java Performance Portal

Quoted

A "c" program would not evaluate "b()" in expression "a() && b()" unless "a()" returns a non-zero TRUE value.
I have to think about that. The developer must be able to select which optimization should be done by the compiler. Eg. I don't recommend - but maybe the user would like to set/change some global variables in the b-method...

Rate this thread
WoltLab Burning Board