KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > OptimizeTest


1 /* OptimizeTest Copyright (C) 1999 Jochen Hoenicke.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; see the file COPYING. If not, write to
15  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
16  *
17  * $Id: OptimizeTest.java,v 1.7 1999/08/19 15:16:59 jochen Exp $
18  */

19
20
21 public class OptimizeTest {
22
23     public final int getInlined(String JavaDoc str, int i) {
24     return str.charAt(i);
25     }
26
27     public final int getInlined(String JavaDoc str, int i, OptimizeTest t) {
28     return str.charAt(i) + t.getInlined(str, i) + i;
29     }
30
31
32     public final int complexInline(String JavaDoc str, int i) {
33     System.err.println("");
34     return str.charAt(i)+str.charAt(-i);
35     }
36
37     public int notInlined(String JavaDoc str, int i, OptimizeTest t) {
38     return str.charAt(i) + t.getInlined(str, i);
39     }
40     
41     public final void longInline(String JavaDoc str, int i) {
42     str.replace('a','b');
43     System.err.println(str.concat(String.valueOf(str.charAt(i))));
44     }
45
46     public int g;
47    
48     /**
49      * This is a really brutal test. It shows that side effects can
50      * make the handling of inlined methods really, really difficult.
51      */

52     public final int sideInline(int a) {
53     return g++ + a;
54     }
55
56     public void main(String JavaDoc[] param) {
57     OptimizeTest ot = new OptimizeTest();
58
59     System.err.println(ot.getInlined("abcde".replace('a','b'), param.length));
60     System.err.println(ot.getInlined("Hallo", ot.notInlined(param[1], 10 - ot.getInlined(param[0], 0, new OptimizeTest()), ot)));
61     System.err.println(ot.complexInline("ollah", param.length));
62     System.err.println("result: "+(g++ + sideInline(g) + g++) + "g: "+g);
63     longInline("Hallo", 3);
64     System.err.println("result:"+
65                (g++ + InlineTest
66                 .difficultSideInline(this, g)
67                 + g++) + "g: "+g);
68     // This was a check which methods are inlined. The result:
69
// Only methods in the same package or in sub packages.
70
// System.err.println("result:"+
71
// (g++ + inline.InlineTest
72
// .difficultSideInline(this, g)
73
// + g++) + "g: "+g);
74
// System.err.println("result:"+
75
// (g++ + jode.InlineTest
76
// .difficultSideInline(this, g)
77
// + g++) + "g: "+g);
78
}
79 }
80
Popular Tags