View | Details | Raw Unified | Return to bug 114894 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java (-15 / +1598 lines)
Lines 16-21 Link Here
16
16
17
import org.eclipse.jdt.core.ToolFactory;
17
import org.eclipse.jdt.core.ToolFactory;
18
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
18
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
19
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
19
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
20
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
20
import org.eclipse.jdt.core.tests.util.Util;
21
import org.eclipse.jdt.core.tests.util.Util;
21
22
Lines 1405-1410 Link Here
1405
			},
1406
			},
1406
			"");
1407
			"");
1407
	String expectedOutput =
1408
	String expectedOutput =
1409
		"  // Method descriptor #15 (Ljava/lang/String;Ljava/lang/String;[LX$IContributionItem;)V\n" + 
1410
		"  // Stack: 3, Locals: 8\n" + 
1408
		"  public static void findInsertionPoint(java.lang.String startId, java.lang.String sortId, X.IContributionItem[] items);\n" + 
1411
		"  public static void findInsertionPoint(java.lang.String startId, java.lang.String sortId, X.IContributionItem[] items);\n" + 
1409
		"      0  iconst_0\n" + 
1412
		"      0  iconst_0\n" + 
1410
		"      1  istore_3 [insertIndex]\n" + 
1413
		"      1  istore_3 [insertIndex]\n" + 
Lines 1433-1453 Link Here
1433
		"     43  iconst_1\n" + 
1436
		"     43  iconst_1\n" + 
1434
		"     44  iadd\n" + 
1437
		"     44  iadd\n" + 
1435
		"     45  istore 5 [nX]\n" + 
1438
		"     45  istore 5 [nX]\n" + 
1436
		"     47  goto 129\n" + 
1439
		"     47  goto 123\n" + 
1437
		"     50  aload_2 [items]\n" + 
1440
		"     50  aload_2 [items]\n" + 
1438
		"     51  iload 5 [nX]\n" + 
1441
		"     51  iload 5 [nX]\n" + 
1439
		"     53  aaload\n" + 
1442
		"     53  aaload\n" + 
1440
		"     54  astore 6 [item]\n" + 
1443
		"     54  astore 6 [item]\n" + 
1441
		"     56  aload 6 [item]\n" + 
1444
		"     56  aload 6 [item]\n" + 
1442
		"     58  invokeinterface X$IContributionItem.isSeparator() : boolean [28] [nargs: 1]\n" + 
1445
		"     58  invokeinterface X$IContributionItem.isSeparator() : boolean [28] [nargs: 1]\n" + 
1443
		"     63  ifne 140\n" + 
1446
		"     63  ifne 134\n" + 
1444
		"     66  aload 6 [item]\n" + 
1447
		"     66  aload 6 [item]\n" + 
1445
		"     68  invokeinterface X$IContributionItem.isGroupMarker() : boolean [32] [nargs: 1]\n" + 
1448
		"     68  invokeinterface X$IContributionItem.isGroupMarker() : boolean [32] [nargs: 1]\n" + 
1446
		"     73  ifeq 79\n" + 
1449
		"     73  ifeq 79\n" + 
1447
		"     76  goto 140\n" + 
1450
		"     76  goto 134\n" + 
1448
		"     79  aload 6 [item]\n" + 
1451
		"     79  aload 6 [item]\n" + 
1449
		"     81  instanceof X$IActionSetContributionItem [35]\n" + 
1452
		"     81  instanceof X$IActionSetContributionItem [35]\n" + 
1450
		"     84  ifeq 140\n" + 
1453
		"     84  ifeq 134\n" + 
1451
		"     87  aload_1 [sortId]\n" + 
1454
		"     87  aload_1 [sortId]\n" + 
1452
		"     88  ifnull 117\n" + 
1455
		"     88  ifnull 117\n" + 
1453
		"     91  aload 6 [item]\n" + 
1456
		"     91  aload 6 [item]\n" + 
Lines 1459-1477 Link Here
1459
		"    106  invokevirtual java.lang.String.compareTo(java.lang.String) : int [40]\n" + 
1462
		"    106  invokevirtual java.lang.String.compareTo(java.lang.String) : int [40]\n" + 
1460
		"    109  iload 4 [compareMetric]\n" + 
1463
		"    109  iload 4 [compareMetric]\n" + 
1461
		"    111  if_icmpge 117\n" + 
1464
		"    111  if_icmpge 117\n" + 
1462
		"    114  goto 140\n" + 
1465
		"    114  goto 134\n" + 
1463
		"    117  iload 5 [nX]\n" + 
1466
		"    117  iload 5 [nX]\n" + 
1464
		"    119  istore_3 [insertIndex]\n" + 
1467
		"    119  istore_3 [insertIndex]\n" + 
1465
		"    120  goto 126\n" + 
1468
		"    120  iinc 5 1 [nX]\n" + 
1466
		"    123  goto 140\n" + 
1469
		"    123  iload 5 [nX]\n" + 
1467
		"    126  iinc 5 1 [nX]\n" + 
1470
		"    125  aload_2 [items]\n" + 
1468
		"    129  iload 5 [nX]\n" + 
1471
		"    126  arraylength\n" + 
1469
		"    131  aload_2 [items]\n" + 
1472
		"    127  if_icmplt 50\n" + 
1470
		"    132  arraylength\n" + 
1473
		"    130  goto 134\n" + 
1471
		"    133  if_icmplt 50\n" + 
1474
		"    133  astore_3\n" + 
1472
		"    136  goto 140\n" + 
1475
		"    134  return\n" + 
1473
		"    139  astore_3\n" + 
1476
		"      Exception Table:\n" + 
1474
		"    140  return\n";
1477
		"        [pc: 0, pc: 38] -> 133 when : java.lang.Exception\n" + 
1478
		"        [pc: 39, pc: 133] -> 133 when : java.lang.Exception\n" + 
1479
		"      Line numbers:\n" + 
1480
		"        [pc: 0, line: 16]\n" + 
1481
		"        [pc: 2, line: 17]\n" + 
1482
		"        [pc: 5, line: 18]\n" + 
1483
		"        [pc: 20, line: 19]\n" + 
1484
		"        [pc: 23, line: 20]\n" + 
1485
		"        [pc: 26, line: 17]\n" + 
1486
		"        [pc: 32, line: 22]\n" + 
1487
		"        [pc: 38, line: 23]\n" + 
1488
		"        [pc: 39, line: 25]\n" + 
1489
		"        [pc: 42, line: 30]\n" + 
1490
		"        [pc: 50, line: 31]\n" + 
1491
		"        [pc: 56, line: 32]\n" + 
1492
		"        [pc: 76, line: 34]\n" + 
1493
		"        [pc: 79, line: 36]\n" + 
1494
		"        [pc: 87, line: 37]\n" + 
1495
		"        [pc: 91, line: 38]\n" + 
1496
		"        [pc: 96, line: 39]\n" + 
1497
		"        [pc: 101, line: 38]\n" + 
1498
		"        [pc: 103, line: 40]\n" + 
1499
		"        [pc: 114, line: 41]\n" + 
1500
		"        [pc: 117, line: 43]\n" + 
1501
		"        [pc: 120, line: 30]\n" + 
1502
		"        [pc: 133, line: 48]\n" + 
1503
		"        [pc: 134, line: 49]\n" + 
1504
		"      Local variable table:\n" + 
1505
		"        [pc: 0, pc: 135] local: startId index: 0 type: java.lang.String\n" + 
1506
		"        [pc: 0, pc: 135] local: sortId index: 1 type: java.lang.String\n" + 
1507
		"        [pc: 0, pc: 135] local: items index: 2 type: X.IContributionItem[]\n" + 
1508
		"        [pc: 2, pc: 133] local: insertIndex index: 3 type: int\n" + 
1509
		"        [pc: 42, pc: 133] local: compareMetric index: 4 type: int\n" + 
1510
		"        [pc: 47, pc: 130] local: nX index: 5 type: int\n" + 
1511
		"        [pc: 56, pc: 120] local: item index: 6 type: X.IContributionItem\n" + 
1512
		"        [pc: 103, pc: 117] local: testId index: 7 type: java.lang.String\n";
1475
	
1513
	
1476
	try {
1514
	try {
1477
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
1515
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
Lines 2970-2975 Link Here
2970
		assertTrue(false);
3008
		assertTrue(false);
2971
	}	
3009
	}	
2972
}
3010
}
3011
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894
3012
public void test048() {
3013
	this.runConformTest(
3014
			new String[] {
3015
				"X.java",
3016
				"public class X {\n" + 
3017
				"	boolean bool() { return true; }\n" + 
3018
				"	void foo() {\n" + 
3019
				"		try {\n" + 
3020
				"			if (bool()) {\n" + 
3021
				"				return;\n" + 
3022
				"			}\n" + 
3023
				"		} catch (Exception e) {\n" + 
3024
				"		}\n" + 
3025
				"	}\n" + 
3026
				"	int foo2() {\n" + 
3027
				"		try {\n" + 
3028
				"			while (bool()) {\n" + 
3029
				"				return 0;\n" + 
3030
				"			}\n" + 
3031
				"		} catch (Exception e) {\n" + 
3032
				"		}\n" + 
3033
				"		return 1;\n" +
3034
				"	}\n" + 
3035
				"	long foo3() {\n" + 
3036
				"		try {\n" + 
3037
				"			do {\n" + 
3038
				"				if (true) return 0L;\n" + 
3039
				"			} while (bool());\n" + 
3040
				"		} catch (Exception e) {\n" + 
3041
				"		}\n" + 
3042
				"		return 1L;\n" +
3043
				"	}	\n" + 
3044
				"	float foo4() {\n" + 
3045
				"		try {\n" + 
3046
				"			for (int i  = 0; bool(); i++) {\n" + 
3047
				"				return 0.0F;\n" + 
3048
				"			}\n" + 
3049
				"		} catch (Exception e) {\n" + 
3050
				"		}\n" + 
3051
				"		return 1.0F;\n" +
3052
				"	}		\n" + 
3053
				"	double bar() {\n" + 
3054
				"		if (bool()) {\n" + 
3055
				"			if (bool())\n" + 
3056
				"				return 0.0;\n" + 
3057
				"		} else {\n" + 
3058
				"			if (bool()) {\n" + 
3059
				"				throw new NullPointerException();\n" + 
3060
				"			}\n" + 
3061
				"		}\n" + 
3062
				"		return 1.0;\n" +
3063
				"	}\n" + 
3064
				"	void baz(int i) {\n" + 
3065
				"		if (bool()) {\n" + 
3066
				"			switch(i) {\n" + 
3067
				"				case 0 : return;\n" + 
3068
				"				default : break;\n" + 
3069
				"			}\n" + 
3070
				"		} else {\n" + 
3071
				"			bool();\n" + 
3072
				"		}\n" + 
3073
				"	}\n" + 
3074
				"}\n",
3075
			},
3076
			"");
3077
	
3078
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
3079
		?	"  // Method descriptor #6 ()V\n" + 
3080
			"  // Stack: 1, Locals: 2\n" + 
3081
			"  void foo();\n" + 
3082
			"     0  aload_0 [this]\n" + 
3083
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3084
			"     4  ifeq 9\n" + 
3085
			"     7  return\n" + 
3086
			"     8  astore_1\n" + 
3087
			"     9  return\n" + 
3088
			"      Exception Table:\n" + 
3089
			"        [pc: 0, pc: 7] -> 8 when : java.lang.Exception\n" + 
3090
			"      Line numbers:\n" + 
3091
			"        [pc: 0, line: 5]\n" + 
3092
			"        [pc: 7, line: 6]\n" + 
3093
			"        [pc: 8, line: 8]\n" + 
3094
			"        [pc: 9, line: 10]\n" + 
3095
			"      Local variable table:\n" + 
3096
			"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
3097
			"  \n" + 
3098
			"  // Method descriptor #22 ()I\n" + 
3099
			"  // Stack: 1, Locals: 2\n" + 
3100
			"  int foo2();\n" + 
3101
			"     0  aload_0 [this]\n" + 
3102
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3103
			"     4  ifeq 10\n" + 
3104
			"     7  iconst_0\n" + 
3105
			"     8  ireturn\n" + 
3106
			"     9  astore_1\n" + 
3107
			"    10  iconst_1\n" + 
3108
			"    11  ireturn\n" + 
3109
			"      Exception Table:\n" + 
3110
			"        [pc: 0, pc: 7] -> 9 when : java.lang.Exception\n" + 
3111
			"      Line numbers:\n" + 
3112
			"        [pc: 0, line: 13]\n" + 
3113
			"        [pc: 7, line: 14]\n" + 
3114
			"        [pc: 9, line: 16]\n" + 
3115
			"        [pc: 10, line: 18]\n" + 
3116
			"      Local variable table:\n" + 
3117
			"        [pc: 0, pc: 12] local: this index: 0 type: X\n" + 
3118
			"  \n" + 
3119
			"  // Method descriptor #24 ()J\n" + 
3120
			"  // Stack: 2, Locals: 2\n" + 
3121
			"  long foo3();\n" + 
3122
			"    0  lconst_0\n" + 
3123
			"    1  lreturn\n" + 
3124
			"    2  astore_1\n" + 
3125
			"    3  lconst_1\n" + 
3126
			"    4  lreturn\n" + 
3127
			"      Line numbers:\n" + 
3128
			"        [pc: 0, line: 23]\n" + 
3129
			"        [pc: 2, line: 25]\n" + 
3130
			"        [pc: 3, line: 27]\n" + 
3131
			"      Local variable table:\n" + 
3132
			"        [pc: 0, pc: 5] local: this index: 0 type: X\n" + 
3133
			"  \n" + 
3134
			"  // Method descriptor #26 ()F\n" + 
3135
			"  // Stack: 1, Locals: 2\n" + 
3136
			"  float foo4();\n" + 
3137
			"     0  iconst_0\n" + 
3138
			"     1  istore_1 [i]\n" + 
3139
			"     2  goto 7\n" + 
3140
			"     5  fconst_0\n" + 
3141
			"     6  freturn\n" + 
3142
			"     7  aload_0 [this]\n" + 
3143
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
3144
			"    11  ifne 5\n" + 
3145
			"    14  goto 18\n" + 
3146
			"    17  astore_1\n" + 
3147
			"    18  fconst_1\n" + 
3148
			"    19  freturn\n" + 
3149
			"      Exception Table:\n" + 
3150
			"        [pc: 0, pc: 5] -> 17 when : java.lang.Exception\n" + 
3151
			"        [pc: 7, pc: 17] -> 17 when : java.lang.Exception\n" + 
3152
			"      Line numbers:\n" + 
3153
			"        [pc: 0, line: 31]\n" + 
3154
			"        [pc: 5, line: 32]\n" + 
3155
			"        [pc: 7, line: 31]\n" + 
3156
			"        [pc: 17, line: 34]\n" + 
3157
			"        [pc: 18, line: 36]\n" + 
3158
			"      Local variable table:\n" + 
3159
			"        [pc: 0, pc: 20] local: this index: 0 type: X\n" + 
3160
			"        [pc: 2, pc: 14] local: i index: 1 type: int\n" + 
3161
			"  \n" + 
3162
			"  // Method descriptor #30 ()D\n" + 
3163
			"  // Stack: 2, Locals: 1\n" + 
3164
			"  double bar();\n" + 
3165
			"     0  aload_0 [this]\n" + 
3166
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3167
			"     4  ifeq 16\n" + 
3168
			"     7  aload_0 [this]\n" + 
3169
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
3170
			"    11  ifeq 31\n" + 
3171
			"    14  dconst_0\n" + 
3172
			"    15  dreturn\n" + 
3173
			"    16  aload_0 [this]\n" + 
3174
			"    17  invokevirtual X.bool() : boolean [17]\n" + 
3175
			"    20  ifeq 31\n" + 
3176
			"    23  new java.lang.NullPointerException [31]\n" + 
3177
			"    26  dup\n" + 
3178
			"    27  invokespecial java.lang.NullPointerException() [33]\n" + 
3179
			"    30  athrow\n" + 
3180
			"    31  dconst_1\n" + 
3181
			"    32  dreturn\n" + 
3182
			"      Line numbers:\n" + 
3183
			"        [pc: 0, line: 39]\n" + 
3184
			"        [pc: 7, line: 40]\n" + 
3185
			"        [pc: 14, line: 41]\n" + 
3186
			"        [pc: 16, line: 43]\n" + 
3187
			"        [pc: 23, line: 44]\n" + 
3188
			"        [pc: 31, line: 47]\n" + 
3189
			"      Local variable table:\n" + 
3190
			"        [pc: 0, pc: 33] local: this index: 0 type: X\n" + 
3191
			"  \n" + 
3192
			"  // Method descriptor #35 (I)V\n" + 
3193
			"  // Stack: 1, Locals: 2\n" + 
3194
			"  void baz(int i);\n" + 
3195
			"     0  aload_0 [this]\n" + 
3196
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3197
			"     4  ifeq 32\n" + 
3198
			"     7  iload_1 [i]\n" + 
3199
			"     8  tableswitch default: 29\n" + 
3200
			"          case 0: 28\n" + 
3201
			"    28  return\n" + 
3202
			"    29  goto 37\n" + 
3203
			"    32  aload_0 [this]\n" + 
3204
			"    33  invokevirtual X.bool() : boolean [17]\n" + 
3205
			"    36  pop\n" + 
3206
			"    37  return\n" + 
3207
			"      Line numbers:\n" + 
3208
			"        [pc: 0, line: 50]\n" + 
3209
			"        [pc: 7, line: 51]\n" + 
3210
			"        [pc: 28, line: 52]\n" + 
3211
			"        [pc: 32, line: 56]\n" + 
3212
			"        [pc: 37, line: 58]\n" + 
3213
			"      Local variable table:\n" + 
3214
			"        [pc: 0, pc: 38] local: this index: 0 type: X\n" + 
3215
			"        [pc: 0, pc: 38] local: i index: 1 type: int\n"
3216
		:
3217
			"  // Method descriptor #6 ()V\n" + 
3218
			"  // Stack: 1, Locals: 2\n" + 
3219
			"  void foo();\n" + 
3220
			"     0  aload_0 [this]\n" + 
3221
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3222
			"     4  ifeq 9\n" + 
3223
			"     7  return\n" + 
3224
			"     8  astore_1\n" + 
3225
			"     9  return\n" + 
3226
			"      Exception Table:\n" + 
3227
			"        [pc: 0, pc: 7] -> 8 when : java.lang.Exception\n" + 
3228
			"      Line numbers:\n" + 
3229
			"        [pc: 0, line: 5]\n" + 
3230
			"        [pc: 7, line: 6]\n" + 
3231
			"        [pc: 8, line: 8]\n" + 
3232
			"        [pc: 9, line: 10]\n" + 
3233
			"      Local variable table:\n" + 
3234
			"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
3235
			"      Stack map table: number of frames 2\n" + 
3236
			"        [pc: 8, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
3237
			"        [pc: 9, same]\n" + 
3238
			"  \n" + 
3239
			"  // Method descriptor #23 ()I\n" + 
3240
			"  // Stack: 1, Locals: 2\n" + 
3241
			"  int foo2();\n" + 
3242
			"     0  aload_0 [this]\n" + 
3243
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3244
			"     4  ifeq 10\n" + 
3245
			"     7  iconst_0\n" + 
3246
			"     8  ireturn\n" + 
3247
			"     9  astore_1\n" + 
3248
			"    10  iconst_1\n" + 
3249
			"    11  ireturn\n" + 
3250
			"      Exception Table:\n" + 
3251
			"        [pc: 0, pc: 7] -> 9 when : java.lang.Exception\n" + 
3252
			"      Line numbers:\n" + 
3253
			"        [pc: 0, line: 13]\n" + 
3254
			"        [pc: 7, line: 14]\n" + 
3255
			"        [pc: 9, line: 16]\n" + 
3256
			"        [pc: 10, line: 18]\n" + 
3257
			"      Local variable table:\n" + 
3258
			"        [pc: 0, pc: 12] local: this index: 0 type: X\n" + 
3259
			"      Stack map table: number of frames 3\n" + 
3260
			"        [pc: 7, same]\n" + 
3261
			"        [pc: 9, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
3262
			"        [pc: 10, same]\n" + 
3263
			"  \n" + 
3264
			"  // Method descriptor #25 ()J\n" + 
3265
			"  // Stack: 2, Locals: 2\n" + 
3266
			"  long foo3();\n" + 
3267
			"    0  lconst_0\n" + 
3268
			"    1  lreturn\n" + 
3269
			"    2  astore_1\n" + 
3270
			"    3  lconst_1\n" + 
3271
			"    4  lreturn\n" + 
3272
			"      Line numbers:\n" + 
3273
			"        [pc: 0, line: 23]\n" + 
3274
			"        [pc: 2, line: 25]\n" + 
3275
			"        [pc: 3, line: 27]\n" + 
3276
			"      Local variable table:\n" + 
3277
			"        [pc: 0, pc: 5] local: this index: 0 type: X\n" + 
3278
			"      Stack map table: number of frames 2\n" + 
3279
			"        [pc: 0, same]\n" + 
3280
			"        [pc: 2, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
3281
			"  \n" + 
3282
			"  // Method descriptor #27 ()F\n" + 
3283
			"  // Stack: 1, Locals: 2\n" + 
3284
			"  float foo4();\n" + 
3285
			"     0  iconst_0\n" + 
3286
			"     1  istore_1 [i]\n" + 
3287
			"     2  goto 7\n" + 
3288
			"     5  fconst_0\n" + 
3289
			"     6  freturn\n" + 
3290
			"     7  aload_0 [this]\n" + 
3291
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
3292
			"    11  ifne 5\n" + 
3293
			"    14  goto 18\n" + 
3294
			"    17  astore_1\n" + 
3295
			"    18  fconst_1\n" + 
3296
			"    19  freturn\n" + 
3297
			"      Exception Table:\n" + 
3298
			"        [pc: 0, pc: 5] -> 17 when : java.lang.Exception\n" + 
3299
			"        [pc: 7, pc: 17] -> 17 when : java.lang.Exception\n" + 
3300
			"      Line numbers:\n" + 
3301
			"        [pc: 0, line: 31]\n" + 
3302
			"        [pc: 5, line: 32]\n" + 
3303
			"        [pc: 7, line: 31]\n" + 
3304
			"        [pc: 17, line: 34]\n" + 
3305
			"        [pc: 18, line: 36]\n" + 
3306
			"      Local variable table:\n" + 
3307
			"        [pc: 0, pc: 20] local: this index: 0 type: X\n" + 
3308
			"        [pc: 2, pc: 14] local: i index: 1 type: int\n" + 
3309
			"      Stack map table: number of frames 4\n" + 
3310
			"        [pc: 5, append: {int}]\n" + 
3311
			"        [pc: 7, same]\n" + 
3312
			"        [pc: 17, full, stack: {java.lang.Exception}, locals: {X}]\n" + 
3313
			"        [pc: 18, same]\n" + 
3314
			"  \n" + 
3315
			"  // Method descriptor #31 ()D\n" + 
3316
			"  // Stack: 2, Locals: 1\n" + 
3317
			"  double bar();\n" + 
3318
			"     0  aload_0 [this]\n" + 
3319
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3320
			"     4  ifeq 16\n" + 
3321
			"     7  aload_0 [this]\n" + 
3322
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
3323
			"    11  ifeq 31\n" + 
3324
			"    14  dconst_0\n" + 
3325
			"    15  dreturn\n" + 
3326
			"    16  aload_0 [this]\n" + 
3327
			"    17  invokevirtual X.bool() : boolean [17]\n" + 
3328
			"    20  ifeq 31\n" + 
3329
			"    23  new java.lang.NullPointerException [32]\n" + 
3330
			"    26  dup\n" + 
3331
			"    27  invokespecial java.lang.NullPointerException() [34]\n" + 
3332
			"    30  athrow\n" + 
3333
			"    31  dconst_1\n" + 
3334
			"    32  dreturn\n" + 
3335
			"      Line numbers:\n" + 
3336
			"        [pc: 0, line: 39]\n" + 
3337
			"        [pc: 7, line: 40]\n" + 
3338
			"        [pc: 14, line: 41]\n" + 
3339
			"        [pc: 16, line: 43]\n" + 
3340
			"        [pc: 23, line: 44]\n" + 
3341
			"        [pc: 31, line: 47]\n" + 
3342
			"      Local variable table:\n" + 
3343
			"        [pc: 0, pc: 33] local: this index: 0 type: X\n" + 
3344
			"      Stack map table: number of frames 2\n" + 
3345
			"        [pc: 16, same]\n" + 
3346
			"        [pc: 31, same]\n" + 
3347
			"  \n" + 
3348
			"  // Method descriptor #36 (I)V\n" + 
3349
			"  // Stack: 1, Locals: 2\n" + 
3350
			"  void baz(int i);\n" + 
3351
			"     0  aload_0 [this]\n" + 
3352
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3353
			"     4  ifeq 32\n" + 
3354
			"     7  iload_1 [i]\n" + 
3355
			"     8  tableswitch default: 29\n" + 
3356
			"          case 0: 28\n" + 
3357
			"    28  return\n" + 
3358
			"    29  goto 37\n" + 
3359
			"    32  aload_0 [this]\n" + 
3360
			"    33  invokevirtual X.bool() : boolean [17]\n" + 
3361
			"    36  pop\n" + 
3362
			"    37  return\n" + 
3363
			"      Line numbers:\n" + 
3364
			"        [pc: 0, line: 50]\n" + 
3365
			"        [pc: 7, line: 51]\n" + 
3366
			"        [pc: 28, line: 52]\n" + 
3367
			"        [pc: 32, line: 56]\n" + 
3368
			"        [pc: 37, line: 58]\n" + 
3369
			"      Local variable table:\n" + 
3370
			"        [pc: 0, pc: 38] local: this index: 0 type: X\n" + 
3371
			"        [pc: 0, pc: 38] local: i index: 1 type: int\n" + 
3372
			"      Stack map table: number of frames 4\n" + 
3373
			"        [pc: 28, same]\n" + 
3374
			"        [pc: 29, same]\n" + 
3375
			"        [pc: 32, same]\n" + 
3376
			"        [pc: 37, same]\n";
3377
	try {
3378
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
3379
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
3380
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
3381
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
3382
		int index = result.indexOf(expectedOutput);
3383
		if (index == -1 || expectedOutput.length() == 0) {
3384
			System.out.println(Util.displayString(result, 3));
3385
		}
3386
		if (index == -1) {
3387
			assertEquals("Wrong contents", expectedOutput, result);
3388
		}
3389
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
3390
		assertTrue(false);
3391
	} catch (IOException e) {
3392
		assertTrue(false);
3393
	}	
3394
}
3395
3396
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation
3397
public void test049() {
3398
	this.runConformTest(
3399
			new String[] {
3400
				"X.java",
3401
				"public class X {\n" + 
3402
				"	boolean bool() { return true; }\n" + 
3403
				"	void foo() {\n" + 
3404
				"		try {\n" + 
3405
				"			if (bool()) {\n" + 
3406
				"				throw new NullPointerException();\n" + 
3407
				"			}\n" + 
3408
				"		} catch (Exception e) {\n" + 
3409
				"		}\n" + 
3410
				"	}\n" + 
3411
				"	void foo2() {\n" + 
3412
				"		try {\n" + 
3413
				"			while (bool()) {\n" + 
3414
				"				throw new NullPointerException();\n" + 
3415
				"			}\n" + 
3416
				"		} catch (Exception e) {\n" + 
3417
				"		}\n" + 
3418
				"	}\n" + 
3419
				"	void foo3() {\n" + 
3420
				"		try {\n" + 
3421
				"			do {\n" + 
3422
				"				if (true) throw new NullPointerException();\n" + 
3423
				"			} while (bool());\n" + 
3424
				"		} catch (Exception e) {\n" + 
3425
				"		}\n" + 
3426
				"	}	\n" + 
3427
				"	void foo4() {\n" + 
3428
				"		try {\n" + 
3429
				"			for (int i  = 0; bool(); i++) {\n" + 
3430
				"				throw new NullPointerException();\n" + 
3431
				"			}\n" + 
3432
				"		} catch (Exception e) {\n" + 
3433
				"		}\n" + 
3434
				"	}		\n" + 
3435
				"	void bar() {\n" + 
3436
				"		if (bool()) {\n" + 
3437
				"			if (bool())\n" + 
3438
				"				throw new NullPointerException();\n" + 
3439
				"		} else {\n" + 
3440
				"			if (bool()) {\n" + 
3441
				"				throw new NullPointerException();\n" + 
3442
				"			}\n" + 
3443
				"		}\n" + 
3444
				"	}\n" + 
3445
				"	void baz(int i) {\n" + 
3446
				"		if (bool()) {\n" + 
3447
				"			switch(i) {\n" + 
3448
				"				case 0 : throw new NullPointerException();\n" + 
3449
				"				default : break;\n" + 
3450
				"			}\n" + 
3451
				"		} else {\n" + 
3452
				"			bool();\n" + 
3453
				"		}\n" + 
3454
				"	}\n" + 
3455
				"}\n",
3456
			},
3457
			"");
3458
	
3459
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
3460
		?	"  // Method descriptor #6 ()V\n" + 
3461
			"  // Stack: 2, Locals: 2\n" + 
3462
			"  void foo();\n" + 
3463
			"     0  aload_0 [this]\n" + 
3464
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3465
			"     4  ifeq 16\n" + 
3466
			"     7  new java.lang.NullPointerException [19]\n" + 
3467
			"    10  dup\n" + 
3468
			"    11  invokespecial java.lang.NullPointerException() [21]\n" + 
3469
			"    14  athrow\n" + 
3470
			"    15  astore_1\n" + 
3471
			"    16  return\n" + 
3472
			"      Exception Table:\n" + 
3473
			"        [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + 
3474
			"      Line numbers:\n" + 
3475
			"        [pc: 0, line: 5]\n" + 
3476
			"        [pc: 7, line: 6]\n" + 
3477
			"        [pc: 15, line: 8]\n" + 
3478
			"        [pc: 16, line: 10]\n" + 
3479
			"      Local variable table:\n" + 
3480
			"        [pc: 0, pc: 17] local: this index: 0 type: X\n" + 
3481
			"  \n" + 
3482
			"  // Method descriptor #6 ()V\n" + 
3483
			"  // Stack: 2, Locals: 2\n" + 
3484
			"  void foo2();\n" + 
3485
			"     0  aload_0 [this]\n" + 
3486
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3487
			"     4  ifeq 16\n" + 
3488
			"     7  new java.lang.NullPointerException [19]\n" + 
3489
			"    10  dup\n" + 
3490
			"    11  invokespecial java.lang.NullPointerException() [21]\n" + 
3491
			"    14  athrow\n" + 
3492
			"    15  astore_1\n" + 
3493
			"    16  return\n" + 
3494
			"      Exception Table:\n" + 
3495
			"        [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + 
3496
			"      Line numbers:\n" + 
3497
			"        [pc: 0, line: 13]\n" + 
3498
			"        [pc: 7, line: 14]\n" + 
3499
			"        [pc: 15, line: 16]\n" + 
3500
			"        [pc: 16, line: 18]\n" + 
3501
			"      Local variable table:\n" + 
3502
			"        [pc: 0, pc: 17] local: this index: 0 type: X\n" + 
3503
			"  \n" + 
3504
			"  // Method descriptor #6 ()V\n" + 
3505
			"  // Stack: 2, Locals: 2\n" + 
3506
			"  void foo3();\n" + 
3507
			"     0  new java.lang.NullPointerException [19]\n" + 
3508
			"     3  dup\n" + 
3509
			"     4  invokespecial java.lang.NullPointerException() [21]\n" + 
3510
			"     7  athrow\n" + 
3511
			"     8  astore_1\n" + 
3512
			"     9  return\n" + 
3513
			"      Exception Table:\n" + 
3514
			"        [pc: 0, pc: 8] -> 8 when : java.lang.Exception\n" + 
3515
			"      Line numbers:\n" + 
3516
			"        [pc: 0, line: 22]\n" + 
3517
			"        [pc: 8, line: 24]\n" + 
3518
			"        [pc: 9, line: 26]\n" + 
3519
			"      Local variable table:\n" + 
3520
			"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
3521
			"  \n" + 
3522
			"  // Method descriptor #6 ()V\n" + 
3523
			"  // Stack: 2, Locals: 2\n" + 
3524
			"  void foo4();\n" + 
3525
			"     0  iconst_0\n" + 
3526
			"     1  istore_1 [i]\n" + 
3527
			"     2  goto 13\n" + 
3528
			"     5  new java.lang.NullPointerException [19]\n" + 
3529
			"     8  dup\n" + 
3530
			"     9  invokespecial java.lang.NullPointerException() [21]\n" + 
3531
			"    12  athrow\n" + 
3532
			"    13  aload_0 [this]\n" + 
3533
			"    14  invokevirtual X.bool() : boolean [17]\n" + 
3534
			"    17  ifne 5\n" + 
3535
			"    20  goto 24\n" + 
3536
			"    23  astore_1\n" + 
3537
			"    24  return\n" + 
3538
			"      Exception Table:\n" + 
3539
			"        [pc: 0, pc: 23] -> 23 when : java.lang.Exception\n" + 
3540
			"      Line numbers:\n" + 
3541
			"        [pc: 0, line: 29]\n" + 
3542
			"        [pc: 5, line: 30]\n" + 
3543
			"        [pc: 13, line: 29]\n" + 
3544
			"        [pc: 23, line: 32]\n" + 
3545
			"        [pc: 24, line: 34]\n" + 
3546
			"      Local variable table:\n" + 
3547
			"        [pc: 0, pc: 25] local: this index: 0 type: X\n" + 
3548
			"        [pc: 2, pc: 20] local: i index: 1 type: int\n" + 
3549
			"  \n" + 
3550
			"  // Method descriptor #6 ()V\n" + 
3551
			"  // Stack: 2, Locals: 1\n" + 
3552
			"  void bar();\n" + 
3553
			"     0  aload_0 [this]\n" + 
3554
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3555
			"     4  ifeq 22\n" + 
3556
			"     7  aload_0 [this]\n" + 
3557
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
3558
			"    11  ifeq 37\n" + 
3559
			"    14  new java.lang.NullPointerException [19]\n" + 
3560
			"    17  dup\n" + 
3561
			"    18  invokespecial java.lang.NullPointerException() [21]\n" + 
3562
			"    21  athrow\n" + 
3563
			"    22  aload_0 [this]\n" + 
3564
			"    23  invokevirtual X.bool() : boolean [17]\n" + 
3565
			"    26  ifeq 37\n" + 
3566
			"    29  new java.lang.NullPointerException [19]\n" + 
3567
			"    32  dup\n" + 
3568
			"    33  invokespecial java.lang.NullPointerException() [21]\n" + 
3569
			"    36  athrow\n" + 
3570
			"    37  return\n" + 
3571
			"      Line numbers:\n" + 
3572
			"        [pc: 0, line: 36]\n" + 
3573
			"        [pc: 7, line: 37]\n" + 
3574
			"        [pc: 14, line: 38]\n" + 
3575
			"        [pc: 22, line: 40]\n" + 
3576
			"        [pc: 29, line: 41]\n" + 
3577
			"        [pc: 37, line: 44]\n" + 
3578
			"      Local variable table:\n" + 
3579
			"        [pc: 0, pc: 38] local: this index: 0 type: X\n" + 
3580
			"  \n" + 
3581
			"  // Method descriptor #31 (I)V\n" + 
3582
			"  // Stack: 2, Locals: 2\n" + 
3583
			"  void baz(int i);\n" + 
3584
			"     0  aload_0 [this]\n" + 
3585
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3586
			"     4  ifeq 39\n" + 
3587
			"     7  iload_1 [i]\n" + 
3588
			"     8  tableswitch default: 36\n" + 
3589
			"          case 0: 28\n" + 
3590
			"    28  new java.lang.NullPointerException [19]\n" + 
3591
			"    31  dup\n" + 
3592
			"    32  invokespecial java.lang.NullPointerException() [21]\n" + 
3593
			"    35  athrow\n" + 
3594
			"    36  goto 44\n" + 
3595
			"    39  aload_0 [this]\n" + 
3596
			"    40  invokevirtual X.bool() : boolean [17]\n" + 
3597
			"    43  pop\n" + 
3598
			"    44  return\n" + 
3599
			"      Line numbers:\n" + 
3600
			"        [pc: 0, line: 46]\n" + 
3601
			"        [pc: 7, line: 47]\n" + 
3602
			"        [pc: 28, line: 48]\n" + 
3603
			"        [pc: 39, line: 52]\n" + 
3604
			"        [pc: 44, line: 54]\n" + 
3605
			"      Local variable table:\n" + 
3606
			"        [pc: 0, pc: 45] local: this index: 0 type: X\n" + 
3607
			"        [pc: 0, pc: 45] local: i index: 1 type: int\n"
3608
		:
3609
			"  // Method descriptor #6 ()V\n" + 
3610
			"  // Stack: 2, Locals: 2\n" + 
3611
			"  void foo();\n" + 
3612
			"     0  aload_0 [this]\n" + 
3613
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3614
			"     4  ifeq 16\n" + 
3615
			"     7  new java.lang.NullPointerException [19]\n" + 
3616
			"    10  dup\n" + 
3617
			"    11  invokespecial java.lang.NullPointerException() [21]\n" + 
3618
			"    14  athrow\n" + 
3619
			"    15  astore_1\n" + 
3620
			"    16  return\n" + 
3621
			"      Exception Table:\n" + 
3622
			"        [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + 
3623
			"      Line numbers:\n" + 
3624
			"        [pc: 0, line: 5]\n" + 
3625
			"        [pc: 7, line: 6]\n" + 
3626
			"        [pc: 15, line: 8]\n" + 
3627
			"        [pc: 16, line: 10]\n" + 
3628
			"      Local variable table:\n" + 
3629
			"        [pc: 0, pc: 17] local: this index: 0 type: X\n" + 
3630
			"      Stack map table: number of frames 2\n" + 
3631
			"        [pc: 15, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
3632
			"        [pc: 16, same]\n" + 
3633
			"  \n" + 
3634
			"  // Method descriptor #6 ()V\n" + 
3635
			"  // Stack: 2, Locals: 2\n" + 
3636
			"  void foo2();\n" + 
3637
			"     0  aload_0 [this]\n" + 
3638
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3639
			"     4  ifeq 16\n" + 
3640
			"     7  new java.lang.NullPointerException [19]\n" + 
3641
			"    10  dup\n" + 
3642
			"    11  invokespecial java.lang.NullPointerException() [21]\n" + 
3643
			"    14  athrow\n" + 
3644
			"    15  astore_1\n" + 
3645
			"    16  return\n" + 
3646
			"      Exception Table:\n" + 
3647
			"        [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + 
3648
			"      Line numbers:\n" + 
3649
			"        [pc: 0, line: 13]\n" + 
3650
			"        [pc: 7, line: 14]\n" + 
3651
			"        [pc: 15, line: 16]\n" + 
3652
			"        [pc: 16, line: 18]\n" + 
3653
			"      Local variable table:\n" + 
3654
			"        [pc: 0, pc: 17] local: this index: 0 type: X\n" + 
3655
			"      Stack map table: number of frames 3\n" + 
3656
			"        [pc: 7, same]\n" + 
3657
			"        [pc: 15, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
3658
			"        [pc: 16, same]\n" + 
3659
			"  \n" + 
3660
			"  // Method descriptor #6 ()V\n" + 
3661
			"  // Stack: 2, Locals: 2\n" + 
3662
			"  void foo3();\n" + 
3663
			"     0  new java.lang.NullPointerException [19]\n" + 
3664
			"     3  dup\n" + 
3665
			"     4  invokespecial java.lang.NullPointerException() [21]\n" + 
3666
			"     7  athrow\n" + 
3667
			"     8  astore_1\n" + 
3668
			"     9  return\n" + 
3669
			"      Exception Table:\n" + 
3670
			"        [pc: 0, pc: 8] -> 8 when : java.lang.Exception\n" + 
3671
			"      Line numbers:\n" + 
3672
			"        [pc: 0, line: 22]\n" + 
3673
			"        [pc: 8, line: 24]\n" + 
3674
			"        [pc: 9, line: 26]\n" + 
3675
			"      Local variable table:\n" + 
3676
			"        [pc: 0, pc: 10] local: this index: 0 type: X\n" + 
3677
			"      Stack map table: number of frames 2\n" + 
3678
			"        [pc: 0, same]\n" + 
3679
			"        [pc: 8, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
3680
			"  \n" + 
3681
			"  // Method descriptor #6 ()V\n" + 
3682
			"  // Stack: 2, Locals: 2\n" + 
3683
			"  void foo4();\n" + 
3684
			"     0  iconst_0\n" + 
3685
			"     1  istore_1 [i]\n" + 
3686
			"     2  goto 13\n" + 
3687
			"     5  new java.lang.NullPointerException [19]\n" + 
3688
			"     8  dup\n" + 
3689
			"     9  invokespecial java.lang.NullPointerException() [21]\n" + 
3690
			"    12  athrow\n" + 
3691
			"    13  aload_0 [this]\n" + 
3692
			"    14  invokevirtual X.bool() : boolean [17]\n" + 
3693
			"    17  ifne 5\n" + 
3694
			"    20  goto 24\n" + 
3695
			"    23  astore_1\n" + 
3696
			"    24  return\n" + 
3697
			"      Exception Table:\n" + 
3698
			"        [pc: 0, pc: 23] -> 23 when : java.lang.Exception\n" + 
3699
			"      Line numbers:\n" + 
3700
			"        [pc: 0, line: 29]\n" + 
3701
			"        [pc: 5, line: 30]\n" + 
3702
			"        [pc: 13, line: 29]\n" + 
3703
			"        [pc: 23, line: 32]\n" + 
3704
			"        [pc: 24, line: 34]\n" + 
3705
			"      Local variable table:\n" + 
3706
			"        [pc: 0, pc: 25] local: this index: 0 type: X\n" + 
3707
			"        [pc: 2, pc: 20] local: i index: 1 type: int\n" + 
3708
			"      Stack map table: number of frames 4\n" + 
3709
			"        [pc: 5, append: {int}]\n" + 
3710
			"        [pc: 13, same]\n" + 
3711
			"        [pc: 23, full, stack: {java.lang.Exception}, locals: {X}]\n" + 
3712
			"        [pc: 24, same]\n" + 
3713
			"  \n" + 
3714
			"  // Method descriptor #6 ()V\n" + 
3715
			"  // Stack: 2, Locals: 1\n" + 
3716
			"  void bar();\n" + 
3717
			"     0  aload_0 [this]\n" + 
3718
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3719
			"     4  ifeq 22\n" + 
3720
			"     7  aload_0 [this]\n" + 
3721
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
3722
			"    11  ifeq 37\n" + 
3723
			"    14  new java.lang.NullPointerException [19]\n" + 
3724
			"    17  dup\n" + 
3725
			"    18  invokespecial java.lang.NullPointerException() [21]\n" + 
3726
			"    21  athrow\n" + 
3727
			"    22  aload_0 [this]\n" + 
3728
			"    23  invokevirtual X.bool() : boolean [17]\n" + 
3729
			"    26  ifeq 37\n" + 
3730
			"    29  new java.lang.NullPointerException [19]\n" + 
3731
			"    32  dup\n" + 
3732
			"    33  invokespecial java.lang.NullPointerException() [21]\n" + 
3733
			"    36  athrow\n" + 
3734
			"    37  return\n" + 
3735
			"      Line numbers:\n" + 
3736
			"        [pc: 0, line: 36]\n" + 
3737
			"        [pc: 7, line: 37]\n" + 
3738
			"        [pc: 14, line: 38]\n" + 
3739
			"        [pc: 22, line: 40]\n" + 
3740
			"        [pc: 29, line: 41]\n" + 
3741
			"        [pc: 37, line: 44]\n" + 
3742
			"      Local variable table:\n" + 
3743
			"        [pc: 0, pc: 38] local: this index: 0 type: X\n" + 
3744
			"      Stack map table: number of frames 2\n" + 
3745
			"        [pc: 22, same]\n" + 
3746
			"        [pc: 37, same]\n" + 
3747
			"  \n" + 
3748
			"  // Method descriptor #32 (I)V\n" + 
3749
			"  // Stack: 2, Locals: 2\n" + 
3750
			"  void baz(int i);\n" + 
3751
			"     0  aload_0 [this]\n" + 
3752
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3753
			"     4  ifeq 39\n" + 
3754
			"     7  iload_1 [i]\n" + 
3755
			"     8  tableswitch default: 36\n" + 
3756
			"          case 0: 28\n" + 
3757
			"    28  new java.lang.NullPointerException [19]\n" + 
3758
			"    31  dup\n" + 
3759
			"    32  invokespecial java.lang.NullPointerException() [21]\n" + 
3760
			"    35  athrow\n" + 
3761
			"    36  goto 44\n" + 
3762
			"    39  aload_0 [this]\n" + 
3763
			"    40  invokevirtual X.bool() : boolean [17]\n" + 
3764
			"    43  pop\n" + 
3765
			"    44  return\n" + 
3766
			"      Line numbers:\n" + 
3767
			"        [pc: 0, line: 46]\n" + 
3768
			"        [pc: 7, line: 47]\n" + 
3769
			"        [pc: 28, line: 48]\n" + 
3770
			"        [pc: 39, line: 52]\n" + 
3771
			"        [pc: 44, line: 54]\n" + 
3772
			"      Local variable table:\n" + 
3773
			"        [pc: 0, pc: 45] local: this index: 0 type: X\n" + 
3774
			"        [pc: 0, pc: 45] local: i index: 1 type: int\n" + 
3775
			"      Stack map table: number of frames 4\n" + 
3776
			"        [pc: 28, same]\n" + 
3777
			"        [pc: 36, same]\n" + 
3778
			"        [pc: 39, same]\n" + 
3779
			"        [pc: 44, same]\n";
3780
	try {
3781
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
3782
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
3783
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
3784
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
3785
		int index = result.indexOf(expectedOutput);
3786
		if (index == -1 || expectedOutput.length() == 0) {
3787
			System.out.println(Util.displayString(result, 3));
3788
		}
3789
		if (index == -1) {
3790
			assertEquals("Wrong contents", expectedOutput, result);
3791
		}
3792
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
3793
		assertTrue(false);
3794
	} catch (IOException e) {
3795
		assertTrue(false);
3796
	}	
3797
}
3798
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation
3799
public void test050() {
3800
	this.runConformTest(
3801
			new String[] {
3802
				"X.java",
3803
				"public class X {\n" + 
3804
				"	boolean bool() { return true; }\n" + 
3805
				"	void foo() {\n" + 
3806
				"		check: try {\n" + 
3807
				"			if (bool()) {\n" + 
3808
				"				break check;\n" + 
3809
				"			}\n" + 
3810
				"		} catch (Exception e) {\n" + 
3811
				"		}\n" + 
3812
				"	}\n" + 
3813
				"	void foo2() {\n" + 
3814
				"		check: try {\n" + 
3815
				"			while (bool()) {\n" + 
3816
				"				break check;\n" + 
3817
				"			}\n" + 
3818
				"		} catch (Exception e) {\n" + 
3819
				"		}\n" + 
3820
				"	}\n" + 
3821
				"	void foo3() {\n" + 
3822
				"		check: try {\n" + 
3823
				"			do {\n" + 
3824
				"				if (true) break check;\n" + 
3825
				"			} while (bool());\n" + 
3826
				"		} catch (Exception e) {\n" + 
3827
				"		}\n" + 
3828
				"	}	\n" + 
3829
				"	void foo4() {\n" + 
3830
				"		check: try {\n" + 
3831
				"			for (int i  = 0; bool(); i++) {\n" + 
3832
				"				break check;\n" + 
3833
				"			}\n" + 
3834
				"		} catch (Exception e) {\n" + 
3835
				"		}\n" + 
3836
				"	}		\n" + 
3837
				"	void bar() {\n" + 
3838
				"		check: if (bool()) {\n" + 
3839
				"			if (bool())\n" + 
3840
				"				break check;\n" + 
3841
				"		} else {\n" + 
3842
				"			if (bool()) {\n" + 
3843
				"				break check;\n" + 
3844
				"			}\n" + 
3845
				"		}\n" + 
3846
				"	}\n" + 
3847
				"	void baz(int i) {\n" + 
3848
				"		check: if (bool()) {\n" + 
3849
				"			switch(i) {\n" + 
3850
				"				case 0 : break check;\n" + 
3851
				"				default : break;\n" + 
3852
				"			}\n" + 
3853
				"		} else {\n" + 
3854
				"			bool();\n" + 
3855
				"		}\n" + 
3856
				"	}\n" + 
3857
				"}\n",
3858
			},
3859
			"");
3860
	
3861
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
3862
		?	"  // Method descriptor #6 ()V\n" + 
3863
			"  // Stack: 1, Locals: 2\n" + 
3864
			"  void foo();\n" + 
3865
			"     0  aload_0 [this]\n" + 
3866
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3867
			"     4  ifeq 11\n" + 
3868
			"     7  goto 11\n" + 
3869
			"    10  astore_1\n" + 
3870
			"    11  return\n" + 
3871
			"      Exception Table:\n" + 
3872
			"        [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + 
3873
			"      Line numbers:\n" + 
3874
			"        [pc: 0, line: 5]\n" + 
3875
			"        [pc: 7, line: 6]\n" + 
3876
			"        [pc: 10, line: 8]\n" + 
3877
			"        [pc: 11, line: 10]\n" + 
3878
			"      Local variable table:\n" + 
3879
			"        [pc: 0, pc: 12] local: this index: 0 type: X\n" + 
3880
			"  \n" + 
3881
			"  // Method descriptor #6 ()V\n" + 
3882
			"  // Stack: 1, Locals: 2\n" + 
3883
			"  void foo2();\n" + 
3884
			"     0  aload_0 [this]\n" + 
3885
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3886
			"     4  ifeq 11\n" + 
3887
			"     7  goto 11\n" + 
3888
			"    10  astore_1\n" + 
3889
			"    11  return\n" + 
3890
			"      Exception Table:\n" + 
3891
			"        [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + 
3892
			"      Line numbers:\n" + 
3893
			"        [pc: 0, line: 13]\n" + 
3894
			"        [pc: 7, line: 14]\n" + 
3895
			"        [pc: 10, line: 16]\n" + 
3896
			"        [pc: 11, line: 18]\n" + 
3897
			"      Local variable table:\n" + 
3898
			"        [pc: 0, pc: 12] local: this index: 0 type: X\n" + 
3899
			"  \n" + 
3900
			"  // Method descriptor #6 ()V\n" + 
3901
			"  // Stack: 1, Locals: 2\n" + 
3902
			"  void foo3();\n" + 
3903
			"    0  goto 4\n" + 
3904
			"    3  astore_1\n" + 
3905
			"    4  return\n" + 
3906
			"      Line numbers:\n" + 
3907
			"        [pc: 0, line: 22]\n" + 
3908
			"        [pc: 3, line: 24]\n" + 
3909
			"        [pc: 4, line: 26]\n" + 
3910
			"      Local variable table:\n" + 
3911
			"        [pc: 0, pc: 5] local: this index: 0 type: X\n" + 
3912
			"  \n" + 
3913
			"  // Method descriptor #6 ()V\n" + 
3914
			"  // Stack: 1, Locals: 2\n" + 
3915
			"  void foo4();\n" + 
3916
			"     0  iconst_0\n" + 
3917
			"     1  istore_1 [i]\n" + 
3918
			"     2  aload_0 [this]\n" + 
3919
			"     3  invokevirtual X.bool() : boolean [17]\n" + 
3920
			"     6  ifne 13\n" + 
3921
			"     9  goto 13\n" + 
3922
			"    12  astore_1\n" + 
3923
			"    13  return\n" + 
3924
			"      Exception Table:\n" + 
3925
			"        [pc: 0, pc: 12] -> 12 when : java.lang.Exception\n" + 
3926
			"      Line numbers:\n" + 
3927
			"        [pc: 0, line: 29]\n" + 
3928
			"        [pc: 12, line: 32]\n" + 
3929
			"        [pc: 13, line: 34]\n" + 
3930
			"      Local variable table:\n" + 
3931
			"        [pc: 0, pc: 14] local: this index: 0 type: X\n" + 
3932
			"        [pc: 2, pc: 9] local: i index: 1 type: int\n" + 
3933
			"  \n" + 
3934
			"  // Method descriptor #6 ()V\n" + 
3935
			"  // Stack: 1, Locals: 1\n" + 
3936
			"  void bar();\n" + 
3937
			"     0  aload_0 [this]\n" + 
3938
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3939
			"     4  ifeq 17\n" + 
3940
			"     7  aload_0 [this]\n" + 
3941
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
3942
			"    11  ifeq 24\n" + 
3943
			"    14  goto 24\n" + 
3944
			"    17  aload_0 [this]\n" + 
3945
			"    18  invokevirtual X.bool() : boolean [17]\n" + 
3946
			"    21  ifeq 24\n" + 
3947
			"    24  return\n" + 
3948
			"      Line numbers:\n" + 
3949
			"        [pc: 0, line: 36]\n" + 
3950
			"        [pc: 7, line: 37]\n" + 
3951
			"        [pc: 14, line: 38]\n" + 
3952
			"        [pc: 17, line: 40]\n" + 
3953
			"        [pc: 24, line: 44]\n" + 
3954
			"      Local variable table:\n" + 
3955
			"        [pc: 0, pc: 25] local: this index: 0 type: X\n" + 
3956
			"  \n" + 
3957
			"  // Method descriptor #28 (I)V\n" + 
3958
			"  // Stack: 1, Locals: 2\n" + 
3959
			"  void baz(int i);\n" + 
3960
			"     0  aload_0 [this]\n" + 
3961
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3962
			"     4  ifeq 34\n" + 
3963
			"     7  iload_1 [i]\n" + 
3964
			"     8  tableswitch default: 31\n" + 
3965
			"          case 0: 28\n" + 
3966
			"    28  goto 39\n" + 
3967
			"    31  goto 39\n" + 
3968
			"    34  aload_0 [this]\n" + 
3969
			"    35  invokevirtual X.bool() : boolean [17]\n" + 
3970
			"    38  pop\n" + 
3971
			"    39  return\n" + 
3972
			"      Line numbers:\n" + 
3973
			"        [pc: 0, line: 46]\n" + 
3974
			"        [pc: 7, line: 47]\n" + 
3975
			"        [pc: 28, line: 48]\n" + 
3976
			"        [pc: 34, line: 52]\n" + 
3977
			"        [pc: 39, line: 54]\n" + 
3978
			"      Local variable table:\n" + 
3979
			"        [pc: 0, pc: 40] local: this index: 0 type: X\n" + 
3980
			"        [pc: 0, pc: 40] local: i index: 1 type: int\n"
3981
		:	
3982
			"  // Method descriptor #6 ()V\n" + 
3983
			"  // Stack: 1, Locals: 2\n" + 
3984
			"  void foo();\n" + 
3985
			"     0  aload_0 [this]\n" + 
3986
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
3987
			"     4  ifeq 11\n" + 
3988
			"     7  goto 11\n" + 
3989
			"    10  astore_1\n" + 
3990
			"    11  return\n" + 
3991
			"      Exception Table:\n" + 
3992
			"        [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + 
3993
			"      Line numbers:\n" + 
3994
			"        [pc: 0, line: 5]\n" + 
3995
			"        [pc: 7, line: 6]\n" + 
3996
			"        [pc: 10, line: 8]\n" + 
3997
			"        [pc: 11, line: 10]\n" + 
3998
			"      Local variable table:\n" + 
3999
			"        [pc: 0, pc: 12] local: this index: 0 type: X\n" + 
4000
			"      Stack map table: number of frames 2\n" + 
4001
			"        [pc: 10, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
4002
			"        [pc: 11, same]\n" + 
4003
			"  \n" + 
4004
			"  // Method descriptor #6 ()V\n" + 
4005
			"  // Stack: 1, Locals: 2\n" + 
4006
			"  void foo2();\n" + 
4007
			"     0  aload_0 [this]\n" + 
4008
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
4009
			"     4  ifeq 11\n" + 
4010
			"     7  goto 11\n" + 
4011
			"    10  astore_1\n" + 
4012
			"    11  return\n" + 
4013
			"      Exception Table:\n" + 
4014
			"        [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + 
4015
			"      Line numbers:\n" + 
4016
			"        [pc: 0, line: 13]\n" + 
4017
			"        [pc: 7, line: 14]\n" + 
4018
			"        [pc: 10, line: 16]\n" + 
4019
			"        [pc: 11, line: 18]\n" + 
4020
			"      Local variable table:\n" + 
4021
			"        [pc: 0, pc: 12] local: this index: 0 type: X\n" + 
4022
			"      Stack map table: number of frames 3\n" + 
4023
			"        [pc: 7, same]\n" + 
4024
			"        [pc: 10, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
4025
			"        [pc: 11, same]\n" + 
4026
			"  \n" + 
4027
			"  // Method descriptor #6 ()V\n" + 
4028
			"  // Stack: 1, Locals: 2\n" + 
4029
			"  void foo3();\n" + 
4030
			"    0  goto 4\n" + 
4031
			"    3  astore_1\n" + 
4032
			"    4  return\n" + 
4033
			"      Line numbers:\n" + 
4034
			"        [pc: 0, line: 22]\n" + 
4035
			"        [pc: 3, line: 24]\n" + 
4036
			"        [pc: 4, line: 26]\n" + 
4037
			"      Local variable table:\n" + 
4038
			"        [pc: 0, pc: 5] local: this index: 0 type: X\n" + 
4039
			"      Stack map table: number of frames 3\n" + 
4040
			"        [pc: 0, same]\n" + 
4041
			"        [pc: 3, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + 
4042
			"        [pc: 4, same]\n" + 
4043
			"  \n" + 
4044
			"  // Method descriptor #6 ()V\n" + 
4045
			"  // Stack: 1, Locals: 2\n" + 
4046
			"  void foo4();\n" + 
4047
			"     0  iconst_0\n" + 
4048
			"     1  istore_1 [i]\n" + 
4049
			"     2  aload_0 [this]\n" + 
4050
			"     3  invokevirtual X.bool() : boolean [17]\n" + 
4051
			"     6  ifne 13\n" + 
4052
			"     9  goto 13\n" + 
4053
			"    12  astore_1\n" + 
4054
			"    13  return\n" + 
4055
			"      Exception Table:\n" + 
4056
			"        [pc: 0, pc: 12] -> 12 when : java.lang.Exception\n" + 
4057
			"      Line numbers:\n" + 
4058
			"        [pc: 0, line: 29]\n" + 
4059
			"        [pc: 12, line: 32]\n" + 
4060
			"        [pc: 13, line: 34]\n" + 
4061
			"      Local variable table:\n" + 
4062
			"        [pc: 0, pc: 14] local: this index: 0 type: X\n" + 
4063
			"        [pc: 2, pc: 9] local: i index: 1 type: int\n" + 
4064
			"      Stack map table: number of frames 3\n" + 
4065
			"        [pc: 2, append: {int}]\n" + 
4066
			"        [pc: 12, full, stack: {java.lang.Exception}, locals: {X}]\n" + 
4067
			"        [pc: 13, same]\n" + 
4068
			"  \n" + 
4069
			"  // Method descriptor #6 ()V\n" + 
4070
			"  // Stack: 1, Locals: 1\n" + 
4071
			"  void bar();\n" + 
4072
			"     0  aload_0 [this]\n" + 
4073
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
4074
			"     4  ifeq 17\n" + 
4075
			"     7  aload_0 [this]\n" + 
4076
			"     8  invokevirtual X.bool() : boolean [17]\n" + 
4077
			"    11  ifeq 24\n" + 
4078
			"    14  goto 24\n" + 
4079
			"    17  aload_0 [this]\n" + 
4080
			"    18  invokevirtual X.bool() : boolean [17]\n" + 
4081
			"    21  ifeq 24\n" + 
4082
			"    24  return\n" + 
4083
			"      Line numbers:\n" + 
4084
			"        [pc: 0, line: 36]\n" + 
4085
			"        [pc: 7, line: 37]\n" + 
4086
			"        [pc: 14, line: 38]\n" + 
4087
			"        [pc: 17, line: 40]\n" + 
4088
			"        [pc: 24, line: 44]\n" + 
4089
			"      Local variable table:\n" + 
4090
			"        [pc: 0, pc: 25] local: this index: 0 type: X\n" + 
4091
			"      Stack map table: number of frames 2\n" + 
4092
			"        [pc: 17, same]\n" + 
4093
			"        [pc: 24, same]\n" + 
4094
			"  \n" + 
4095
			"  // Method descriptor #29 (I)V\n" + 
4096
			"  // Stack: 1, Locals: 2\n" + 
4097
			"  void baz(int i);\n" + 
4098
			"     0  aload_0 [this]\n" + 
4099
			"     1  invokevirtual X.bool() : boolean [17]\n" + 
4100
			"     4  ifeq 34\n" + 
4101
			"     7  iload_1 [i]\n" + 
4102
			"     8  tableswitch default: 31\n" + 
4103
			"          case 0: 28\n" + 
4104
			"    28  goto 39\n" + 
4105
			"    31  goto 39\n" + 
4106
			"    34  aload_0 [this]\n" + 
4107
			"    35  invokevirtual X.bool() : boolean [17]\n" + 
4108
			"    38  pop\n" + 
4109
			"    39  return\n" + 
4110
			"      Line numbers:\n" + 
4111
			"        [pc: 0, line: 46]\n" + 
4112
			"        [pc: 7, line: 47]\n" + 
4113
			"        [pc: 28, line: 48]\n" + 
4114
			"        [pc: 34, line: 52]\n" + 
4115
			"        [pc: 39, line: 54]\n" + 
4116
			"      Local variable table:\n" + 
4117
			"        [pc: 0, pc: 40] local: this index: 0 type: X\n" + 
4118
			"        [pc: 0, pc: 40] local: i index: 1 type: int\n" + 
4119
			"      Stack map table: number of frames 4\n" + 
4120
			"        [pc: 28, same]\n" + 
4121
			"        [pc: 31, same]\n" + 
4122
			"        [pc: 34, same]\n" + 
4123
			"        [pc: 39, same]\n";
4124
	
4125
	try {
4126
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
4127
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
4128
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
4129
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
4130
		int index = result.indexOf(expectedOutput);
4131
		if (index == -1 || expectedOutput.length() == 0) {
4132
			System.out.println(Util.displayString(result, 3));
4133
		}
4134
		if (index == -1) {
4135
			assertEquals("Wrong contents", expectedOutput, result);
4136
		}
4137
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
4138
		assertTrue(false);
4139
	} catch (IOException e) {
4140
		assertTrue(false);
4141
	}	
4142
}
4143
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation
4144
public void test051() {
4145
	this.runConformTest(
4146
			new String[] {
4147
				"X.java",
4148
				"public class X {\n" + 
4149
				"	public static void main(String argv[]) {\n" + 
4150
				"		System.out.println(\"[count=\" + count() + \"]\");\n" + 
4151
				"	}\n" + 
4152
				"	static int count() {\n" + 
4153
				"		int count = 0;\n" + 
4154
				"		try {\n" + 
4155
				"			for (int i = 0;;) {\n" + 
4156
				"				count++;\n" + 
4157
				"				if (i++ > 10) \n" + 
4158
				"					break; \n" + 
4159
				"			}\n" + 
4160
				"		} catch(Exception e) {\n" + 
4161
				"		}\n" + 
4162
				"		return count;\n" + 
4163
				"	}\n" + 
4164
				"}\n",
4165
			},
4166
			"[count=12]");
4167
	
4168
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
4169
		?	"  // Method descriptor #32 ()I\n" + 
4170
			"  // Stack: 2, Locals: 2\n" + 
4171
			"  static int count();\n" + 
4172
			"     0  iconst_0\n" + 
4173
			"     1  istore_0 [count]\n" + 
4174
			"     2  iconst_0\n" + 
4175
			"     3  istore_1 [i]\n" + 
4176
			"     4  iinc 0 1 [count]\n" + 
4177
			"     7  iload_1 [i]\n" + 
4178
			"     8  iinc 1 1 [i]\n" + 
4179
			"    11  bipush 10\n" + 
4180
			"    13  if_icmple 4\n" + 
4181
			"    16  goto 20\n" + 
4182
			"    19  astore_1\n" + 
4183
			"    20  iload_0 [count]\n" + 
4184
			"    21  ireturn\n" + 
4185
			"      Exception Table:\n" + 
4186
			"        [pc: 2, pc: 19] -> 19 when : java.lang.Exception\n" + 
4187
			"      Line numbers:\n" + 
4188
			"        [pc: 0, line: 6]\n" + 
4189
			"        [pc: 2, line: 8]\n" + 
4190
			"        [pc: 4, line: 9]\n" + 
4191
			"        [pc: 7, line: 10]\n" + 
4192
			"        [pc: 19, line: 13]\n" + 
4193
			"        [pc: 20, line: 15]\n" + 
4194
			"      Local variable table:\n" + 
4195
			"        [pc: 2, pc: 22] local: count index: 0 type: int\n" + 
4196
			"        [pc: 4, pc: 16] local: i index: 1 type: int\n"
4197
		:	
4198
			"  // Method descriptor #32 ()I\n" + 
4199
			"  // Stack: 2, Locals: 2\n" + 
4200
			"  static int count();\n" + 
4201
			"     0  iconst_0\n" + 
4202
			"     1  istore_0 [count]\n" + 
4203
			"     2  iconst_0\n" + 
4204
			"     3  istore_1 [i]\n" + 
4205
			"     4  iinc 0 1 [count]\n" + 
4206
			"     7  iload_1 [i]\n" + 
4207
			"     8  iinc 1 1 [i]\n" + 
4208
			"    11  bipush 10\n" + 
4209
			"    13  if_icmple 4\n" + 
4210
			"    16  goto 20\n" + 
4211
			"    19  astore_1\n" + 
4212
			"    20  iload_0 [count]\n" + 
4213
			"    21  ireturn\n" + 
4214
			"      Exception Table:\n" + 
4215
			"        [pc: 2, pc: 19] -> 19 when : java.lang.Exception\n" + 
4216
			"      Line numbers:\n" + 
4217
			"        [pc: 0, line: 6]\n" + 
4218
			"        [pc: 2, line: 8]\n" + 
4219
			"        [pc: 4, line: 9]\n" + 
4220
			"        [pc: 7, line: 10]\n" + 
4221
			"        [pc: 19, line: 13]\n" + 
4222
			"        [pc: 20, line: 15]\n" + 
4223
			"      Local variable table:\n" + 
4224
			"        [pc: 2, pc: 22] local: count index: 0 type: int\n" + 
4225
			"        [pc: 4, pc: 16] local: i index: 1 type: int\n" + 
4226
			"      Stack map table: number of frames 3\n" + 
4227
			"        [pc: 4, append: {int, int}]\n" + 
4228
			"        [pc: 19, full, stack: {java.lang.Exception}, locals: {int}]\n" + 
4229
			"        [pc: 20, same]\n";
4230
	
4231
	try {
4232
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
4233
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
4234
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
4235
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
4236
		int index = result.indexOf(expectedOutput);
4237
		if (index == -1 || expectedOutput.length() == 0) {
4238
			System.out.println(Util.displayString(result, 3));
4239
		}
4240
		if (index == -1) {
4241
			assertEquals("Wrong contents", expectedOutput, result);
4242
		}
4243
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
4244
		assertTrue(false);
4245
	} catch (IOException e) {
4246
		assertTrue(false);
4247
	}	
4248
}
4249
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation
4250
public void test052() {
4251
	this.runConformTest(
4252
			new String[] {
4253
				"X.java",
4254
				"public class X {\n" + 
4255
				"	public static void main(String argv[]) {\n" + 
4256
				"		try {\n" + 
4257
				"			for (int i = 0; i < 0; i++)\n" + 
4258
				"				do ;  while (true);\n" + 
4259
				"		} catch(Exception e) {\n" + 
4260
				"		}\n" + 
4261
				"	} \n" + 
4262
				"}\n",
4263
			},
4264
			"");
4265
	
4266
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
4267
		?	"  // Method descriptor #15 ([Ljava/lang/String;)V\n" + 
4268
			"  // Stack: 1, Locals: 2\n" + 
4269
			"  public static void main(java.lang.String[] argv);\n" + 
4270
			"     0  iconst_0\n" + 
4271
			"     1  istore_1 [i]\n" + 
4272
			"     2  goto 8\n" + 
4273
			"     5  goto 5\n" + 
4274
			"     8  iload_1 [i]\n" + 
4275
			"     9  iflt 5\n" + 
4276
			"    12  goto 16\n" + 
4277
			"    15  astore_1\n" + 
4278
			"    16  return\n" + 
4279
			"      Exception Table:\n" + 
4280
			"        [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + 
4281
			"      Line numbers:\n" + 
4282
			"        [pc: 0, line: 4]\n" + 
4283
			"        [pc: 5, line: 5]\n" + 
4284
			"        [pc: 8, line: 4]\n" + 
4285
			"        [pc: 15, line: 6]\n" + 
4286
			"        [pc: 16, line: 8]\n" + 
4287
			"      Local variable table:\n" + 
4288
			"        [pc: 0, pc: 17] local: argv index: 0 type: java.lang.String[]\n" + 
4289
			"        [pc: 2, pc: 12] local: i index: 1 type: int\n"
4290
		:	
4291
			"  // Method descriptor #15 ([Ljava/lang/String;)V\n" + 
4292
			"  // Stack: 1, Locals: 2\n" + 
4293
			"  public static void main(java.lang.String[] argv);\n" + 
4294
			"     0  iconst_0\n" + 
4295
			"     1  istore_1 [i]\n" + 
4296
			"     2  goto 8\n" + 
4297
			"     5  goto 5\n" + 
4298
			"     8  iload_1 [i]\n" + 
4299
			"     9  iflt 5\n" + 
4300
			"    12  goto 16\n" + 
4301
			"    15  astore_1\n" + 
4302
			"    16  return\n" + 
4303
			"      Exception Table:\n" + 
4304
			"        [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + 
4305
			"      Line numbers:\n" + 
4306
			"        [pc: 0, line: 4]\n" + 
4307
			"        [pc: 5, line: 5]\n" + 
4308
			"        [pc: 8, line: 4]\n" + 
4309
			"        [pc: 15, line: 6]\n" + 
4310
			"        [pc: 16, line: 8]\n" + 
4311
			"      Local variable table:\n" + 
4312
			"        [pc: 0, pc: 17] local: argv index: 0 type: java.lang.String[]\n" + 
4313
			"        [pc: 2, pc: 12] local: i index: 1 type: int\n" + 
4314
			"      Stack map table: number of frames 4\n" + 
4315
			"        [pc: 5, append: {int}]\n" + 
4316
			"        [pc: 8, same]\n" + 
4317
			"        [pc: 15, full, stack: {java.lang.Exception}, locals: {java.lang.String[]}]\n" + 
4318
			"        [pc: 16, same]\n";
4319
	
4320
	try {
4321
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
4322
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
4323
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
4324
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
4325
		int index = result.indexOf(expectedOutput);
4326
		if (index == -1 || expectedOutput.length() == 0) {
4327
			System.out.println(Util.displayString(result, 3));
4328
		}
4329
		if (index == -1) {
4330
			assertEquals("Wrong contents", expectedOutput, result);
4331
		}
4332
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
4333
		assertTrue(false);
4334
	} catch (IOException e) {
4335
		assertTrue(false);
4336
	}	
4337
}
4338
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation
4339
public void test053() {
4340
	this.runConformTest(
4341
			new String[] {
4342
				"X.java",
4343
				"public class X {\n" + 
4344
				"	public static void main(String[] args) {\n" + 
4345
				"		try {\n" + 
4346
				"			final int val;\n" + 
4347
				"			for (val = 7; val > 0;) break;\n" + 
4348
				"			System.out.println(val);\n" + 
4349
				"		} catch(Exception e) {\n" + 
4350
				"		}\n" + 
4351
				"	}	\n" + 
4352
				"}\n",
4353
			},
4354
			"7");
4355
	
4356
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
4357
		?	"  // Method descriptor #15 ([Ljava/lang/String;)V\n" + 
4358
			"  // Stack: 2, Locals: 2\n" + 
4359
			"  public static void main(java.lang.String[] args);\n" + 
4360
			"     0  bipush 7\n" + 
4361
			"     2  istore_1 [val]\n" + 
4362
			"     3  iload_1 [val]\n" + 
4363
			"     4  ifgt 7\n" + 
4364
			"     7  getstatic java.lang.System.out : java.io.PrintStream [16]\n" + 
4365
			"    10  iload_1 [val]\n" + 
4366
			"    11  invokevirtual java.io.PrintStream.println(int) : void [22]\n" + 
4367
			"    14  goto 18\n" + 
4368
			"    17  astore_1\n" + 
4369
			"    18  return\n" + 
4370
			"      Exception Table:\n" + 
4371
			"        [pc: 0, pc: 17] -> 17 when : java.lang.Exception\n" + 
4372
			"      Line numbers:\n" + 
4373
			"        [pc: 0, line: 5]\n" + 
4374
			"        [pc: 7, line: 6]\n" + 
4375
			"        [pc: 17, line: 7]\n" + 
4376
			"        [pc: 18, line: 9]\n" + 
4377
			"      Local variable table:\n" + 
4378
			"        [pc: 0, pc: 19] local: args index: 0 type: java.lang.String[]\n" + 
4379
			"        [pc: 3, pc: 17] local: val index: 1 type: int\n"
4380
		:	
4381
			"  // Method descriptor #15 ([Ljava/lang/String;)V\n" + 
4382
			"  // Stack: 2, Locals: 2\n" + 
4383
			"  public static void main(java.lang.String[] args);\n" + 
4384
			"     0  bipush 7\n" + 
4385
			"     2  istore_1 [val]\n" + 
4386
			"     3  iload_1 [val]\n" + 
4387
			"     4  ifgt 7\n" + 
4388
			"     7  getstatic java.lang.System.out : java.io.PrintStream [16]\n" + 
4389
			"    10  iload_1 [val]\n" + 
4390
			"    11  invokevirtual java.io.PrintStream.println(int) : void [22]\n" + 
4391
			"    14  goto 18\n" + 
4392
			"    17  astore_1\n" + 
4393
			"    18  return\n" + 
4394
			"      Exception Table:\n" + 
4395
			"        [pc: 0, pc: 17] -> 17 when : java.lang.Exception\n" + 
4396
			"      Line numbers:\n" + 
4397
			"        [pc: 0, line: 5]\n" + 
4398
			"        [pc: 7, line: 6]\n" + 
4399
			"        [pc: 17, line: 7]\n" + 
4400
			"        [pc: 18, line: 9]\n" + 
4401
			"      Local variable table:\n" + 
4402
			"        [pc: 0, pc: 19] local: args index: 0 type: java.lang.String[]\n" + 
4403
			"        [pc: 3, pc: 17] local: val index: 1 type: int\n" + 
4404
			"      Stack map table: number of frames 4\n" + 
4405
			"        [pc: 3, append: {int}]\n" + 
4406
			"        [pc: 7, same]\n" + 
4407
			"        [pc: 17, full, stack: {java.lang.Exception}, locals: {java.lang.String[]}]\n" + 
4408
			"        [pc: 18, same]\n";
4409
	
4410
	try {
4411
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
4412
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
4413
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
4414
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
4415
		int index = result.indexOf(expectedOutput);
4416
		if (index == -1 || expectedOutput.length() == 0) {
4417
			System.out.println(Util.displayString(result, 3));
4418
		}
4419
		if (index == -1) {
4420
			assertEquals("Wrong contents", expectedOutput, result);
4421
		}
4422
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
4423
		assertTrue(false);
4424
	} catch (IOException e) {
4425
		assertTrue(false);
4426
	}	
4427
}
4428
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation
4429
public void test054() {
4430
	this.runConformTest(
4431
			new String[] {
4432
				"X.java",
4433
				"public class X {\n" + 
4434
				" X parent;\n" + 
4435
				" int kind;\n" + 
4436
				" static boolean F = false;\n" + 
4437
				" public static void main(String[] args) {\n" + 
4438
				"  X x = new X();\n" + 
4439
				"  x.kind = 2; \n" + 
4440
				"  try {\n" + 
4441
				"   x.foo();\n" + 
4442
				"  } catch(NullPointerException e) { \n" + 
4443
				"   System.out.println(\"SUCCESS\");\n" + 
4444
				"   return;\n" + 
4445
				"  }\n" + 
4446
				"  System.out.println(\"FAILED\");  \n" + 
4447
				" }\n" + 
4448
				" void foo() {\n" + 
4449
				"  X x = this;\n" + 
4450
				"  done : while (true) {\n" + 
4451
				"   switch (x.kind) {\n" + 
4452
				"    case 2 :\n" + 
4453
				"     if (F) {\n" + 
4454
				"      return;\n" + 
4455
				"     }\n" + 
4456
				"     break;\n" + 
4457
				"    case 3 :\n" + 
4458
				"     break done;\n" + 
4459
				"   }\n" + 
4460
				"   x = x.parent; // should throw npe\n" + 
4461
				"  }\n" + 
4462
				" } \n" + 
4463
				"}\n",
4464
			},
4465
			"SUCCESS");
4466
	
4467
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
4468
		?	"  // Method descriptor #12 ()V\n" + 
4469
			"  // Stack: 1, Locals: 2\n" + 
4470
			"  void foo();\n" + 
4471
			"     0  aload_0 [this]\n" + 
4472
			"     1  astore_1 [x]\n" + 
4473
			"     2  aload_1 [x]\n" + 
4474
			"     3  getfield X.kind : int [25]\n" + 
4475
			"     6  tableswitch default: 38\n" + 
4476
			"          case 2: 28\n" + 
4477
			"          case 3: 35\n" + 
4478
			"    28  getstatic X.F : boolean [14]\n" + 
4479
			"    31  ifeq 38\n" + 
4480
			"    34  return\n" + 
4481
			"    35  goto 46\n" + 
4482
			"    38  aload_1 [x]\n" + 
4483
			"    39  getfield X.parent : X [53]\n" + 
4484
			"    42  astore_1 [x]\n" + 
4485
			"    43  goto 2\n" + 
4486
			"    46  return\n" + 
4487
			"      Line numbers:\n" + 
4488
			"        [pc: 0, line: 17]\n" + 
4489
			"        [pc: 2, line: 19]\n" + 
4490
			"        [pc: 28, line: 21]\n" + 
4491
			"        [pc: 34, line: 22]\n" + 
4492
			"        [pc: 35, line: 26]\n" + 
4493
			"        [pc: 38, line: 28]\n" + 
4494
			"        [pc: 43, line: 18]\n" + 
4495
			"        [pc: 46, line: 30]\n" + 
4496
			"      Local variable table:\n" + 
4497
			"        [pc: 0, pc: 47] local: this index: 0 type: X\n" + 
4498
			"        [pc: 2, pc: 47] local: x index: 1 type: X\n"
4499
		:	
4500
			"  // Method descriptor #12 ()V\n" + 
4501
			"  // Stack: 1, Locals: 2\n" + 
4502
			"  void foo();\n" + 
4503
			"     0  aload_0 [this]\n" + 
4504
			"     1  astore_1 [x]\n" + 
4505
			"     2  aload_1 [x]\n" + 
4506
			"     3  getfield X.kind : int [25]\n" + 
4507
			"     6  tableswitch default: 38\n" + 
4508
			"          case 2: 28\n" + 
4509
			"          case 3: 35\n" + 
4510
			"    28  getstatic X.F : boolean [14]\n" + 
4511
			"    31  ifeq 38\n" + 
4512
			"    34  return\n" + 
4513
			"    35  goto 46\n" + 
4514
			"    38  aload_1 [x]\n" + 
4515
			"    39  getfield X.parent : X [55]\n" + 
4516
			"    42  astore_1 [x]\n" + 
4517
			"    43  goto 2\n" + 
4518
			"    46  return\n" + 
4519
			"      Line numbers:\n" + 
4520
			"        [pc: 0, line: 17]\n" + 
4521
			"        [pc: 2, line: 19]\n" + 
4522
			"        [pc: 28, line: 21]\n" + 
4523
			"        [pc: 34, line: 22]\n" + 
4524
			"        [pc: 35, line: 26]\n" + 
4525
			"        [pc: 38, line: 28]\n" + 
4526
			"        [pc: 43, line: 18]\n" + 
4527
			"        [pc: 46, line: 30]\n" + 
4528
			"      Local variable table:\n" + 
4529
			"        [pc: 0, pc: 47] local: this index: 0 type: X\n" + 
4530
			"        [pc: 2, pc: 47] local: x index: 1 type: X\n" + 
4531
			"      Stack map table: number of frames 5\n" + 
4532
			"        [pc: 2, append: {X}]\n" + 
4533
			"        [pc: 28, same]\n" + 
4534
			"        [pc: 35, same]\n" + 
4535
			"        [pc: 38, same]\n" + 
4536
			"        [pc: 46, same]\n";
4537
	
4538
	try {
4539
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
4540
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
4541
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
4542
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
4543
		int index = result.indexOf(expectedOutput);
4544
		if (index == -1 || expectedOutput.length() == 0) {
4545
			System.out.println(Util.displayString(result, 3));
4546
		}
4547
		if (index == -1) {
4548
			assertEquals("Wrong contents", expectedOutput, result);
4549
		}
4550
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
4551
		assertTrue(false);
4552
	} catch (IOException e) {
4553
		assertTrue(false);
4554
	}	
4555
}
2973
public static Class testClass() {
4556
public static Class testClass() {
2974
	return TryStatementTest.class;
4557
	return TryStatementTest.class;
2975
}
4558
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java (+222 lines)
Lines 16-21 Link Here
16
import org.eclipse.jdt.core.ToolFactory;
16
import org.eclipse.jdt.core.ToolFactory;
17
import org.eclipse.jdt.core.tests.util.Util;
17
import org.eclipse.jdt.core.tests.util.Util;
18
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
18
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
19
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
20
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
19
21
20
import junit.framework.Test;
22
import junit.framework.Test;
21
23
Lines 355-360 Link Here
355
		assertTrue("IOException", false);
357
		assertTrue("IOException", false);
356
	}		
358
	}		
357
}
359
}
360
public void test013() {
361
	this.runConformTest(new String[] {
362
		"X.java",
363
		"public class X {\n" + 
364
		"\n" + 
365
		"	public static void main(String[] args) {\n" + 
366
		"		X x;\n" + 
367
		"		Object o = null;\n" + 
368
		"		for (int i = 0; i < 10; i++) {\n" + 
369
		"			if (i < 90) {\n" + 
370
		"				x = new X();\n" + 
371
		"				if (i > 4) {\n" + 
372
		"					o = new Object();\n" + 
373
		"				} else {\n" + 
374
		"					o = null;\n" + 
375
		"				}\n" + 
376
		"				switch (2) {\n" + 
377
		"					case 0:\n" + 
378
		"						if (o instanceof String) {\n" + 
379
		"							System.out.print(\"1\");\n" + 
380
		"							return;\n" + 
381
		"						} else {\n" + 
382
		"							break;\n" + 
383
		"						}\n" + 
384
		"					default: {\n" + 
385
		"						Object diff = o;\n" + 
386
		"						if (diff != null) {\n" + 
387
		"							System.out.print(\"2\");\n" + 
388
		"						}\n" + 
389
		"						break;\n" + 
390
		"					}\n" + 
391
		"				}\n" + 
392
		"				System.out.print(\"3\");				\n" + 
393
		"			}\n" + 
394
		"		}\n" + 
395
		"	}\n" + 
396
		"}\n",
397
	},
398
	"333332323232323");
399
400
	String expectedOutput = new CompilerOptions(this.getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6
401
		?	"  // Method descriptor #15 ([Ljava/lang/String;)V\n" + 
402
			"  // Stack: 2, Locals: 5\n" + 
403
			"  public static void main(java.lang.String[] args);\n" + 
404
			"      0  aconst_null\n" + 
405
			"      1  astore_2 [o]\n" + 
406
			"      2  iconst_0\n" + 
407
			"      3  istore_3 [i]\n" + 
408
			"      4  goto 103\n" + 
409
			"      7  iload_3 [i]\n" + 
410
			"      8  bipush 90\n" + 
411
			"     10  if_icmpge 100\n" + 
412
			"     13  new X [1]\n" + 
413
			"     16  dup\n" + 
414
			"     17  invokespecial X() [16]\n" + 
415
			"     20  astore_1 [x]\n" + 
416
			"     21  iload_3 [i]\n" + 
417
			"     22  iconst_4\n" + 
418
			"     23  if_icmple 37\n" + 
419
			"     26  new java.lang.Object [3]\n" + 
420
			"     29  dup\n" + 
421
			"     30  invokespecial java.lang.Object() [8]\n" + 
422
			"     33  astore_2 [o]\n" + 
423
			"     34  goto 39\n" + 
424
			"     37  aconst_null\n" + 
425
			"     38  astore_2 [o]\n" + 
426
			"     39  iconst_2\n" + 
427
			"     40  tableswitch default: 76\n" + 
428
			"          case 0: 60\n" + 
429
			"     60  aload_2 [o]\n" + 
430
			"     61  instanceof java.lang.String [17]\n" + 
431
			"     64  ifeq 92\n" + 
432
			"     67  getstatic java.lang.System.out : java.io.PrintStream [19]\n" + 
433
			"     70  ldc <String \"1\"> [25]\n" + 
434
			"     72  invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + 
435
			"     75  return\n" + 
436
			"     76  aload_2 [o]\n" + 
437
			"     77  astore 4 [diff]\n" + 
438
			"     79  aload 4 [diff]\n" + 
439
			"     81  ifnull 92\n" + 
440
			"     84  getstatic java.lang.System.out : java.io.PrintStream [19]\n" + 
441
			"     87  ldc <String \"2\"> [33]\n" + 
442
			"     89  invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + 
443
			"     92  getstatic java.lang.System.out : java.io.PrintStream [19]\n" + 
444
			"     95  ldc <String \"3\"> [35]\n" + 
445
			"     97  invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + 
446
			"    100  iinc 3 1 [i]\n" + 
447
			"    103  iload_3 [i]\n" + 
448
			"    104  bipush 10\n" + 
449
			"    106  if_icmplt 7\n" + 
450
			"    109  return\n" + 
451
			"      Line numbers:\n" + 
452
			"        [pc: 0, line: 5]\n" + 
453
			"        [pc: 2, line: 6]\n" + 
454
			"        [pc: 7, line: 7]\n" + 
455
			"        [pc: 13, line: 8]\n" + 
456
			"        [pc: 21, line: 9]\n" + 
457
			"        [pc: 26, line: 10]\n" + 
458
			"        [pc: 37, line: 12]\n" + 
459
			"        [pc: 39, line: 14]\n" + 
460
			"        [pc: 60, line: 16]\n" + 
461
			"        [pc: 67, line: 17]\n" + 
462
			"        [pc: 75, line: 18]\n" + 
463
			"        [pc: 76, line: 23]\n" + 
464
			"        [pc: 79, line: 24]\n" + 
465
			"        [pc: 84, line: 25]\n" + 
466
			"        [pc: 92, line: 30]\n" + 
467
			"        [pc: 100, line: 6]\n" + 
468
			"        [pc: 109, line: 33]\n" + 
469
			"      Local variable table:\n" + 
470
			"        [pc: 0, pc: 110] local: args index: 0 type: java.lang.String[]\n" + 
471
			"        [pc: 21, pc: 100] local: x index: 1 type: X\n" + 
472
			"        [pc: 2, pc: 110] local: o index: 2 type: java.lang.Object\n" + 
473
			"        [pc: 4, pc: 109] local: i index: 3 type: int\n" + 
474
			"        [pc: 79, pc: 92] local: diff index: 4 type: java.lang.Object\n"
475
		:
476
			"  // Method descriptor #15 ([Ljava/lang/String;)V\n" + 
477
			"  // Stack: 2, Locals: 5\n" + 
478
			"  public static void main(java.lang.String[] args);\n" + 
479
			"      0  aconst_null\n" + 
480
			"      1  astore_2 [o]\n" + 
481
			"      2  iconst_0\n" + 
482
			"      3  istore_3 [i]\n" + 
483
			"      4  goto 103\n" + 
484
			"      7  iload_3 [i]\n" + 
485
			"      8  bipush 90\n" + 
486
			"     10  if_icmpge 100\n" + 
487
			"     13  new X [1]\n" + 
488
			"     16  dup\n" + 
489
			"     17  invokespecial X() [16]\n" + 
490
			"     20  astore_1 [x]\n" + 
491
			"     21  iload_3 [i]\n" + 
492
			"     22  iconst_4\n" + 
493
			"     23  if_icmple 37\n" + 
494
			"     26  new java.lang.Object [3]\n" + 
495
			"     29  dup\n" + 
496
			"     30  invokespecial java.lang.Object() [8]\n" + 
497
			"     33  astore_2 [o]\n" + 
498
			"     34  goto 39\n" + 
499
			"     37  aconst_null\n" + 
500
			"     38  astore_2 [o]\n" + 
501
			"     39  iconst_2\n" + 
502
			"     40  tableswitch default: 76\n" + 
503
			"          case 0: 60\n" + 
504
			"     60  aload_2 [o]\n" + 
505
			"     61  instanceof java.lang.String [17]\n" + 
506
			"     64  ifeq 92\n" + 
507
			"     67  getstatic java.lang.System.out : java.io.PrintStream [19]\n" + 
508
			"     70  ldc <String \"1\"> [25]\n" + 
509
			"     72  invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + 
510
			"     75  return\n" + 
511
			"     76  aload_2 [o]\n" + 
512
			"     77  astore 4 [diff]\n" + 
513
			"     79  aload 4 [diff]\n" + 
514
			"     81  ifnull 92\n" + 
515
			"     84  getstatic java.lang.System.out : java.io.PrintStream [19]\n" + 
516
			"     87  ldc <String \"2\"> [33]\n" + 
517
			"     89  invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + 
518
			"     92  getstatic java.lang.System.out : java.io.PrintStream [19]\n" + 
519
			"     95  ldc <String \"3\"> [35]\n" + 
520
			"     97  invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + 
521
			"    100  iinc 3 1 [i]\n" + 
522
			"    103  iload_3 [i]\n" + 
523
			"    104  bipush 10\n" + 
524
			"    106  if_icmplt 7\n" + 
525
			"    109  return\n" + 
526
			"      Line numbers:\n" + 
527
			"        [pc: 0, line: 5]\n" + 
528
			"        [pc: 2, line: 6]\n" + 
529
			"        [pc: 7, line: 7]\n" + 
530
			"        [pc: 13, line: 8]\n" + 
531
			"        [pc: 21, line: 9]\n" + 
532
			"        [pc: 26, line: 10]\n" + 
533
			"        [pc: 37, line: 12]\n" + 
534
			"        [pc: 39, line: 14]\n" + 
535
			"        [pc: 60, line: 16]\n" + 
536
			"        [pc: 67, line: 17]\n" + 
537
			"        [pc: 75, line: 18]\n" + 
538
			"        [pc: 76, line: 23]\n" + 
539
			"        [pc: 79, line: 24]\n" + 
540
			"        [pc: 84, line: 25]\n" + 
541
			"        [pc: 92, line: 30]\n" + 
542
			"        [pc: 100, line: 6]\n" + 
543
			"        [pc: 109, line: 33]\n" + 
544
			"      Local variable table:\n" + 
545
			"        [pc: 0, pc: 110] local: args index: 0 type: java.lang.String[]\n" + 
546
			"        [pc: 21, pc: 100] local: x index: 1 type: X\n" + 
547
			"        [pc: 2, pc: 110] local: o index: 2 type: java.lang.Object\n" + 
548
			"        [pc: 4, pc: 109] local: i index: 3 type: int\n" + 
549
			"        [pc: 79, pc: 92] local: diff index: 4 type: java.lang.Object\n" + 
550
			"      Stack map table: number of frames 8\n" + 
551
			"        [pc: 7, full, stack: {}, locals: {java.lang.String[], _, java.lang.Object, int}]\n" + 
552
			"        [pc: 37, full, stack: {}, locals: {java.lang.String[], X, java.lang.Object, int}]\n" + 
553
			"        [pc: 39, same]\n" + 
554
			"        [pc: 60, same]\n" + 
555
			"        [pc: 76, same]\n" + 
556
			"        [pc: 92, same]\n" + 
557
			"        [pc: 100, full, stack: {}, locals: {java.lang.String[], _, java.lang.Object, int}]\n" + 
558
			"        [pc: 103, same]\n";
559
	
560
	try {
561
		File f = new File(OUTPUT_DIR + File.separator + "X.class");
562
		byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
563
		ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
564
		String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
565
		int index = result.indexOf(expectedOutput);
566
		if (index == -1 || expectedOutput.length() == 0) {
567
			System.out.println(Util.displayString(result, 3));
568
		}
569
		if (index == -1) {
570
			assertEquals("Wrong contents", expectedOutput, result);
571
		}
572
	} catch (org.eclipse.jdt.core.util.ClassFormatException e) {
573
		e.printStackTrace();
574
		assertTrue("ClassFormatException", false);
575
	} catch (IOException e) {
576
		e.printStackTrace();
577
		assertTrue("IOException", false);
578
	}		
579
}
358
public static Class testClass() {
580
public static Class testClass() {
359
	return SwitchTest.class;
581
	return SwitchTest.class;
360
}
582
}
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java (-56 / +72 lines)
Lines 134-141 Link Here
134
	public int generateAttributes;
134
	public int generateAttributes;
135
	// store all the labels placed at the current position to be able to optimize
135
	// store all the labels placed at the current position to be able to optimize
136
	// a jump to the next bytecode.
136
	// a jump to the next bytecode.
137
	static final int L_UNKNOWN = 0, L_OPTIMIZABLE = 2, L_CANNOT_OPTIMIZE = 4;	
137
	public BranchLabel[] labels = new BranchLabel[LABELS_INCREMENT];
138
	public BranchLabel[] labels = new BranchLabel[LABELS_INCREMENT];
138
	public int lastEntryPC; // last entry recorded
139
	public int lastEntryPC; // last entry recorded
140
	public int lastAbruptCompletion; // position of last instruction which abrupts completion: goto/return/athrow
139
	public int[] lineSeparatorPositions;
141
	public int[] lineSeparatorPositions;
140
	
142
	
141
	public LocalVariableBinding[] locals = new LocalVariableBinding[LOCALS_INCREMENT];
143
	public LocalVariableBinding[] locals = new LocalVariableBinding[LOCALS_INCREMENT];
Lines 239-245 Link Here
239
}
241
}
240
public void addVisibleLocalVariable(LocalVariableBinding localBinding) {
242
public void addVisibleLocalVariable(LocalVariableBinding localBinding) {
241
	if (((this.generateAttributes & ClassFileConstants.ATTR_VARS) == 0)
243
	if (((this.generateAttributes & ClassFileConstants.ATTR_VARS) == 0)
242
		&& ((this.generateAttributes & ClassFileConstants.ATTR_STACK_MAP) == 0))
244
			&& ((this.generateAttributes & ClassFileConstants.ATTR_STACK_MAP) == 0))
243
		return;
245
		return;
244
246
245
	if (visibleLocalsCount >= visibleLocals.length)
247
	if (visibleLocalsCount >= visibleLocals.length)
Lines 354-359 Link Here
354
	}
356
	}
355
	position++;
357
	position++;
356
	bCodeStream[classFileOffset++] = Opcodes.OPC_areturn;
358
	bCodeStream[classFileOffset++] = Opcodes.OPC_areturn;
359
	this.lastAbruptCompletion = this.position;		
357
}
360
}
358
public void arrayAt(int typeBindingID) {
361
public void arrayAt(int typeBindingID) {
359
	switch (typeBindingID) {
362
	switch (typeBindingID) {
Lines 521-526 Link Here
521
	}
524
	}
522
	position++;
525
	position++;
523
	bCodeStream[classFileOffset++] = Opcodes.OPC_athrow;
526
	bCodeStream[classFileOffset++] = Opcodes.OPC_athrow;
527
	this.lastAbruptCompletion = this.position;		
524
}
528
}
525
public void baload() {
529
public void baload() {
526
	if (DEBUG) System.out.println(position + "\t\tbaload"); //$NON-NLS-1$
530
	if (DEBUG) System.out.println(position + "\t\tbaload"); //$NON-NLS-1$
Lines 859-864 Link Here
859
	}
863
	}
860
	position++;
864
	position++;
861
	bCodeStream[classFileOffset++] = Opcodes.OPC_dreturn;
865
	bCodeStream[classFileOffset++] = Opcodes.OPC_dreturn;
866
	this.lastAbruptCompletion = this.position;		
862
}
867
}
863
public void dstore(int iArg) {
868
public void dstore(int iArg) {
864
	if (DEBUG) System.out.println(position + "\t\tdstore:"+iArg); //$NON-NLS-1$
869
	if (DEBUG) System.out.println(position + "\t\tdstore:"+iArg); //$NON-NLS-1$
Lines 1293-1298 Link Here
1293
	}
1298
	}
1294
	position++;
1299
	position++;
1295
	bCodeStream[classFileOffset++] = Opcodes.OPC_freturn;
1300
	bCodeStream[classFileOffset++] = Opcodes.OPC_freturn;
1301
	this.lastAbruptCompletion = this.position;		
1296
}
1302
}
1297
public void fstore(int iArg) {
1303
public void fstore(int iArg) {
1298
	if (DEBUG) System.out.println(position + "\t\tfstore:"+iArg); //$NON-NLS-1$
1304
	if (DEBUG) System.out.println(position + "\t\tfstore:"+iArg); //$NON-NLS-1$
Lines 2944-2950 Link Here
2944
	if (classFileOffset >= bCodeStream.length) {
2950
	if (classFileOffset >= bCodeStream.length) {
2945
		resizeByteArray();
2951
		resizeByteArray();
2946
	}
2952
	}
2947
	this.inlineForwardReferencesFromLabelsTargeting(label, position);
2953
	boolean chained = this.inlineForwardReferencesFromLabelsTargeting(label, position);
2954
	if (DEBUG && chained) {
2955
		if (DEBUG) {
2956
			if (this.lastAbruptCompletion == this.position) {
2957
				System.out.println("\t\t\t\t<branch chaining - goto eliminated : "+this.position+","+label+">");//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$				
2958
			} else {
2959
				System.out.println("\t\t\t\t<branch chaining - goto issued : "+this.position+","+label+">");//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
2960
			}
2961
		}		
2962
	}
2948
	/*
2963
	/*
2949
	 Possible optimization for code such as:
2964
	 Possible optimization for code such as:
2950
	 public Object foo() {
2965
	 public Object foo() {
Lines 2961-2989 Link Here
2961
	}
2976
	}
2962
	The goto around the else block for the first if will
2977
	The goto around the else block for the first if will
2963
	be unreachable, because the thenClause of the second if
2978
	be unreachable, because the thenClause of the second if
2964
	returns.
2979
	returns. Also see 114894
2965
	See inlineForwardReferencesFromLabelsTargeting defined
2966
	on the Label class for the remaining part of this
2967
	optimization.
2968
	 if (!lbl.isBranchTarget(position)) {
2969
		switch(bCodeStream[classFileOffset-1]) {
2970
			case Opcodes.OPC_return :
2971
			case Opcodes.OPC_areturn:
2972
				return;
2973
		}
2974
	}*/
2980
	}*/
2981
	if (chained && this.lastAbruptCompletion == this.position) {
2982
		if (label.position != Label.POS_NOT_SET) { // ensure existing forward references are updated
2983
			int[] forwardRefs = label.forwardReferences();
2984
			for (int i = 0, max = label.forwardReferenceCount(); i < max; i++) {
2985
				this.writePosition(label, forwardRefs[i]);
2986
			}				
2987
			this.countLabels = 0; // backward jump, no further chaining allowed
2988
		}
2989
//		this.lastAbruptCompletion = -1;
2990
		return;
2991
	}
2975
	position++;
2992
	position++;
2976
	bCodeStream[classFileOffset++] = Opcodes.OPC_goto;
2993
	bCodeStream[classFileOffset++] = Opcodes.OPC_goto;
2977
	label.branch();
2994
	label.branch();
2995
	this.lastAbruptCompletion = this.position;
2978
}
2996
}
2979
final public void goto_w(BranchLabel lbl) {
2997
final public void goto_w(BranchLabel label) {
2980
	if (DEBUG) System.out.println(position + "\t\tgotow:"+lbl); //$NON-NLS-1$
2998
	if (DEBUG) System.out.println(position + "\t\tgotow:"+label); //$NON-NLS-1$
2981
	if (classFileOffset >= bCodeStream.length) {
2999
	if (classFileOffset >= bCodeStream.length) {
2982
		resizeByteArray();
3000
		resizeByteArray();
2983
	}
3001
	}
2984
	position++;
3002
	position++;
2985
	bCodeStream[classFileOffset++] = Opcodes.OPC_goto_w;
3003
	bCodeStream[classFileOffset++] = Opcodes.OPC_goto_w;
2986
	lbl.branchWide();
3004
	label.branchWide();
3005
	this.lastAbruptCompletion = this.position;	
2987
}
3006
}
2988
public void i2b() {
3007
public void i2b() {
2989
	if (DEBUG) System.out.println(position + "\t\ti2b"); //$NON-NLS-1$
3008
	if (DEBUG) System.out.println(position + "\t\ti2b"); //$NON-NLS-1$
Lines 3225-3231 Link Here
3225
	}
3244
	}
3226
}
3245
}
3227
public void if_icmpge(BranchLabel lbl) {
3246
public void if_icmpge(BranchLabel lbl) {
3228
	if (DEBUG) System.out.println(position + "\t\tif_iacmpge:"+lbl); //$NON-NLS-1$
3247
	if (DEBUG) System.out.println(position + "\t\tif_icmpge:"+lbl); //$NON-NLS-1$
3229
	countLabels = 0;
3248
	countLabels = 0;
3230
	stackDepth -= 2;
3249
	stackDepth -= 2;
3231
	if (this.wideMode) {
3250
	if (this.wideMode) {
Lines 3240-3246 Link Here
3240
	}
3259
	}
3241
}
3260
}
3242
public void if_icmpgt(BranchLabel lbl) {
3261
public void if_icmpgt(BranchLabel lbl) {
3243
	if (DEBUG) System.out.println(position + "\t\tif_iacmpgt:"+lbl); //$NON-NLS-1$
3262
	if (DEBUG) System.out.println(position + "\t\tif_icmpgt:"+lbl); //$NON-NLS-1$
3244
	countLabels = 0;
3263
	countLabels = 0;
3245
	stackDepth -= 2;
3264
	stackDepth -= 2;
3246
	if (this.wideMode) {
3265
	if (this.wideMode) {
Lines 3255-3261 Link Here
3255
	}
3274
	}
3256
}
3275
}
3257
public void if_icmple(BranchLabel lbl) {
3276
public void if_icmple(BranchLabel lbl) {
3258
	if (DEBUG) System.out.println(position + "\t\tif_iacmple:"+lbl); //$NON-NLS-1$
3277
	if (DEBUG) System.out.println(position + "\t\tif_icmple:"+lbl); //$NON-NLS-1$
3259
	countLabels = 0;
3278
	countLabels = 0;
3260
	stackDepth -= 2;
3279
	stackDepth -= 2;
3261
	if (this.wideMode) {
3280
	if (this.wideMode) {
Lines 3270-3276 Link Here
3270
	}
3289
	}
3271
}
3290
}
3272
public void if_icmplt(BranchLabel lbl) {
3291
public void if_icmplt(BranchLabel lbl) {
3273
	if (DEBUG) System.out.println(position + "\t\tif_iacmplt:"+lbl); //$NON-NLS-1$
3292
	if (DEBUG) System.out.println(position + "\t\tif_icmplt:"+lbl); //$NON-NLS-1$
3274
	countLabels = 0;
3293
	countLabels = 0;
3275
	stackDepth -= 2;
3294
	stackDepth -= 2;
3276
	if (this.wideMode) {
3295
	if (this.wideMode) {
Lines 3285-3291 Link Here
3285
	}
3304
	}
3286
}
3305
}
3287
public void if_icmpne(BranchLabel lbl) {
3306
public void if_icmpne(BranchLabel lbl) {
3288
	if (DEBUG) System.out.println(position + "\t\tif_iacmpne:"+lbl); //$NON-NLS-1$
3307
	if (DEBUG) System.out.println(position + "\t\tif_icmpne:"+lbl); //$NON-NLS-1$
3289
	countLabels = 0;
3308
	countLabels = 0;
3290
	stackDepth -= 2;
3309
	stackDepth -= 2;
3291
	if (this.wideMode) {
3310
	if (this.wideMode) {
Lines 3556-3591 Link Here
3556
/*
3575
/*
3557
 * Some placed labels might be branching to a goto bytecode which we can optimize better.
3576
 * Some placed labels might be branching to a goto bytecode which we can optimize better.
3558
 */
3577
 */
3559
public void inlineForwardReferencesFromLabelsTargeting(BranchLabel label, int gotoLocation) {
3578
public boolean inlineForwardReferencesFromLabelsTargeting(BranchLabel targetLabel, int gotoLocation) {
3560
	
3579
	int chaining = L_UNKNOWN;
3561
/*
3562
 Code required to optimized unreachable gotos.
3563
	public boolean isBranchTarget(int location) {
3564
		Label[] labels = codeStream.labels;
3565
		for (int i = codeStream.countLabels - 1; i >= 0; i--){
3566
			Label label = labels[i];
3567
			if ((label.position == location) && label.isStandardLabel()){
3568
				return true;
3569
			}
3570
		}
3571
		return false;
3572
	}
3573
 */
3574
	
3575
	for (int i = this.countLabels - 1; i >= 0; i--) {
3580
	for (int i = this.countLabels - 1; i >= 0; i--) {
3576
		BranchLabel currentLabel = labels[i];
3581
		BranchLabel currentLabel = labels[i];
3577
		if (currentLabel.position == gotoLocation) {
3582
		if (currentLabel.position != gotoLocation) break;
3578
			if (currentLabel.isStandardLabel()) {
3583
		if (currentLabel == targetLabel) {
3579
				label.appendForwardReferencesFrom(currentLabel);
3584
			chaining |= L_CANNOT_OPTIMIZE; // recursive
3580
			}
3585
			continue;
3581
			/*
3586
		} 
3582
			 Code required to optimized unreachable gotos.
3587
		if (currentLabel.isStandardLabel()) {
3583
				label.position = POS_NOT_SET;
3588
			if (currentLabel.delegate != null) continue; // ignore since already inlined
3584
			*/
3589
			targetLabel.becomeDelegateFor(currentLabel);
3585
		} else {
3590
			chaining |= L_OPTIMIZABLE; // optimizable, providing no vetoing
3586
			break; // same target labels should be contiguous
3591
			continue;
3587
		}
3592
		}
3593
		// case label
3594
		chaining |= L_CANNOT_OPTIMIZE;
3588
	}
3595
	}
3596
	return (chaining & (L_OPTIMIZABLE|L_CANNOT_OPTIMIZE)) == L_OPTIMIZABLE; // check was some standards, and no case/recursive
3589
}
3597
}
3590
public void init(ClassFile targetClassFile) {
3598
public void init(ClassFile targetClassFile) {
3591
	this.classFile = targetClassFile;
3599
	this.classFile = targetClassFile;
Lines 3622-3627 Link Here
3622
	}
3630
	}
3623
	System.arraycopy(noLabels, 0, labels, 0, length);
3631
	System.arraycopy(noLabels, 0, labels, 0, length);
3624
	countLabels = 0;
3632
	countLabels = 0;
3633
	this.lastAbruptCompletion = -1;
3625
3634
3626
	stackMax = 0;
3635
	stackMax = 0;
3627
	stackDepth = 0;
3636
	stackDepth = 0;
Lines 4493-4498 Link Here
4493
	}
4502
	}
4494
	position++;
4503
	position++;
4495
	bCodeStream[classFileOffset++] = Opcodes.OPC_ireturn;
4504
	bCodeStream[classFileOffset++] = Opcodes.OPC_ireturn;
4505
	this.lastAbruptCompletion = this.position;		
4496
}
4506
}
4497
public boolean isDefinitelyAssigned(Scope scope, int initStateIndex, LocalVariableBinding local) {
4507
public boolean isDefinitelyAssigned(Scope scope, int initStateIndex, LocalVariableBinding local) {
4498
	// Mirror of UnconditionalFlowInfo.isDefinitelyAssigned(..)
4508
	// Mirror of UnconditionalFlowInfo.isDefinitelyAssigned(..)
Lines 5278-5283 Link Here
5278
	}
5288
	}
5279
	position++;
5289
	position++;
5280
	bCodeStream[classFileOffset++] = Opcodes.OPC_lreturn;
5290
	bCodeStream[classFileOffset++] = Opcodes.OPC_lreturn;
5291
	this.lastAbruptCompletion = this.position;		
5281
}
5292
}
5282
public void lshl() {
5293
public void lshl() {
5283
	if (DEBUG) System.out.println(position + "\t\tlshl"); //$NON-NLS-1$
5294
	if (DEBUG) System.out.println(position + "\t\tlshl"); //$NON-NLS-1$
Lines 5624-5637 Link Here
5624
			label.position = position;
5635
			label.position = position;
5625
			if (label instanceof CaseLabel) {
5636
			if (label instanceof CaseLabel) {
5626
				int offset = position - ((CaseLabel) label).instructionPosition;
5637
				int offset = position - ((CaseLabel) label).instructionPosition;
5627
				for (int j = 0; j < label.forwardReferenceCount; j++) {
5638
				int[] forwardRefs = label.forwardReferences();
5628
					int forwardPosition = label.forwardReferences[j];
5639
				for (int j = 0, length = label.forwardReferenceCount(); j < length; j++) {
5629
					this.writeSignedWord(forwardPosition, offset);
5640
					int forwardRef = forwardRefs[j];
5641
					this.writeSignedWord(forwardRef, offset);
5630
				}
5642
				}
5631
			} else {
5643
			} else {
5632
				for (int j = 0; j < label.forwardReferenceCount; j++) {
5644
				int[] forwardRefs = label.forwardReferences();
5633
					final int forwardReference = label.forwardReferences[j];
5645
				for (int j = 0, length = label.forwardReferenceCount(); j < length; j++) {
5634
					this.writePosition(lbl, forwardReference);
5646
					final int forwardRef = forwardRefs[j];
5647
					this.writePosition(lbl, forwardRef);
5635
				}
5648
				}
5636
			}
5649
			}
5637
		}
5650
		}
Lines 5898-5903 Link Here
5898
	}
5911
	}
5899
	position++;
5912
	position++;
5900
	bCodeStream[classFileOffset++] = Opcodes.OPC_return;
5913
	bCodeStream[classFileOffset++] = Opcodes.OPC_return;
5914
	this.lastAbruptCompletion = this.position;	
5901
}
5915
}
5902
public void saload() {
5916
public void saload() {
5903
	if (DEBUG) System.out.println(position + "\t\tsaload"); //$NON-NLS-1$
5917
	if (DEBUG) System.out.println(position + "\t\tsaload"); //$NON-NLS-1$
Lines 6275-6282 Link Here
6275
		throw new AbortMethod(CodeStream.RESTART_IN_WIDE_MODE, null);
6289
		throw new AbortMethod(CodeStream.RESTART_IN_WIDE_MODE, null);
6276
	}
6290
	}
6277
	this.writeSignedShort(offset);
6291
	this.writeSignedShort(offset);
6278
	for (int i = 0, max = label.forwardReferenceCount; i < max; i++) {
6292
	int[] forwardRefs = label.forwardReferences();
6279
		this.writePosition(label, label.forwardReferences[i]);
6293
	for (int i = 0, max = label.forwardReferenceCount(); i < max; i++) {
6294
		this.writePosition(label, forwardRefs[i]);
6280
	}	
6295
	}	
6281
}
6296
}
6282
protected void writePosition(BranchLabel label, int forwardReference) {
6297
protected void writePosition(BranchLabel label, int forwardReference) {
Lines 6350-6357 Link Here
6350
	int labelPos = label.position;
6365
	int labelPos = label.position;
6351
	int offset = labelPos - this.position + 1;
6366
	int offset = labelPos - this.position + 1;
6352
	this.writeSignedWord(offset);
6367
	this.writeSignedWord(offset);
6353
	for (int i = 0, max = label.forwardReferenceCount; i < max; i++) {
6368
	int[] forwardRefs = label.forwardReferences();
6354
		int forward = label.forwardReferences[i];
6369
	for (int i = 0, max = label.forwardReferenceCount(); i < max; i++) {
6370
		int forward = forwardRefs[i];
6355
		offset = labelPos - forward + 1;
6371
		offset = labelPos - forward + 1;
6356
		this.writeSignedWord(forward, offset);
6372
		this.writeSignedWord(forward, offset);
6357
	}	
6373
	}	
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/CaseLabel.java (-2 / +3 lines)
Lines 64-71 Link Here
64
	}
64
	}
65
	if (instructionPosition != POS_NOT_SET) {
65
	if (instructionPosition != POS_NOT_SET) {
66
		int offset = position - instructionPosition;
66
		int offset = position - instructionPosition;
67
		for (int i = 0; i < forwardReferenceCount; i++) {
67
		int[] forwardRefs = forwardReferences();
68
			codeStream.writeSignedWord(forwardReferences[i], offset);
68
		for (int i = 0, length = forwardReferenceCount(); i < length; i++) {
69
			codeStream.writeSignedWord(forwardRefs[i], offset);
69
		}
70
		}
70
		// add the label int the codeStream labels collection
71
		// add the label int the codeStream labels collection
71
		codeStream.addLabel(this);
72
		codeStream.addLabel(this);
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/ExceptionLabel.java (-1 / +2 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.codegen;
11
package org.eclipse.jdt.internal.compiler.codegen;
12
12
13
import org.eclipse.jdt.core.compiler.CharOperation;
13
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
14
import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
14
15
15
public class ExceptionLabel extends Label {
16
public class ExceptionLabel extends Label {
Lines 59-65 Link Here
59
	basic = basic.substring(basic.lastIndexOf('.')+1);
60
	basic = basic.substring(basic.lastIndexOf('.')+1);
60
	StringBuffer buffer = new StringBuffer(basic); 
61
	StringBuffer buffer = new StringBuffer(basic); 
61
	buffer.append('@').append(Integer.toHexString(hashCode()));
62
	buffer.append('@').append(Integer.toHexString(hashCode()));
62
	buffer.append("(type=").append(this.exceptionType == null ? null : this.exceptionType.readableName()); //$NON-NLS-1$
63
	buffer.append("(type=").append(this.exceptionType == null ? CharOperation.NO_CHAR : this.exceptionType.readableName()); //$NON-NLS-1$
63
	buffer.append(", position=").append(position); //$NON-NLS-1$
64
	buffer.append(", position=").append(position); //$NON-NLS-1$
64
	buffer.append(", ranges = "); //$NON-NLS-1$
65
	buffer.append(", ranges = "); //$NON-NLS-1$
65
	if (this.count == 0) {
66
	if (this.count == 0) {
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/BranchLabel.java (-5 / +34 lines)
Lines 17-24 Link Here
17
17
18
public class BranchLabel extends Label {
18
public class BranchLabel extends Label {
19
	
19
	
20
	public int[] forwardReferences = new int[10]; // Add an overflow check here.
20
	private int[] forwardReferences = new int[10]; // Add an overflow check here.
21
	public int forwardReferenceCount = 0;
21
	private int forwardReferenceCount = 0;
22
	BranchLabel delegate; //
22
	
23
	
23
	// Label tagbits
24
	// Label tagbits
24
	public int tagBits;
25
	public int tagBits;
Lines 40-45 Link Here
40
 * Add a forward refrence for the array.
41
 * Add a forward refrence for the array.
41
 */
42
 */
42
void addForwardReference(int pos) {
43
void addForwardReference(int pos) {
44
	if (this.delegate != null) {
45
		this.delegate.addForwardReference(pos);
46
		return;
47
	}
43
	final int count = this.forwardReferenceCount;
48
	final int count = this.forwardReferenceCount;
44
	if (count >= 1) {
49
	if (count >= 1) {
45
		int previousValue = this.forwardReferences[count - 1];
50
		int previousValue = this.forwardReferences[count - 1];
Lines 69-77 Link Here
69
}
74
}
70
75
71
/**
76
/**
72
 * Add a forward reference for the array.
77
 * Makes the current label inline all references to the other label
73
 */
78
 */
74
public void appendForwardReferencesFrom(BranchLabel otherLabel) {
79
public void becomeDelegateFor(BranchLabel otherLabel) {
80
	// other label is delegating to receiver from now on
81
	otherLabel.delegate = this;
82
	
83
	// all existing forward refs to other label are inlined into current label
75
	final int otherCount = otherLabel.forwardReferenceCount;
84
	final int otherCount = otherLabel.forwardReferenceCount;
76
	if (otherCount == 0) return;
85
	if (otherCount == 0) return;
77
	// need to merge the two sorted arrays of forward references
86
	// need to merge the two sorted arrays of forward references
Lines 110-115 Link Here
110
*/
119
*/
111
void branch() {
120
void branch() {
112
	this.tagBits |= BranchLabel.USED;
121
	this.tagBits |= BranchLabel.USED;
122
	if (this.delegate != null) {
123
		this.delegate.branch();
124
		return;
125
	}
113
	if (this.position == Label.POS_NOT_SET) {
126
	if (this.position == Label.POS_NOT_SET) {
114
		addForwardReference(this.codeStream.position);
127
		addForwardReference(this.codeStream.position);
115
		// Leave two bytes free to generate the jump afterwards
128
		// Leave two bytes free to generate the jump afterwards
Lines 128-133 Link Here
128
*/
141
*/
129
void branchWide() {
142
void branchWide() {
130
	this.tagBits |= BranchLabel.USED;
143
	this.tagBits |= BranchLabel.USED;
144
	if (this.delegate != null) {
145
		this.delegate.branchWide();
146
		return;
147
	}
131
	if (this.position == Label.POS_NOT_SET) {
148
	if (this.position == Label.POS_NOT_SET) {
132
		addForwardReference(this.codeStream.position);
149
		addForwardReference(this.codeStream.position);
133
		// Leave 4 bytes free to generate the jump offset afterwards
150
		// Leave 4 bytes free to generate the jump offset afterwards
Lines 139-148 Link Here
139
	}
156
	}
140
}
157
}
141
158
159
public int forwardReferenceCount() {
160
	if (this.delegate != null) this.delegate.forwardReferenceCount();
161
	return forwardReferenceCount;
162
}
163
public int[] forwardReferences() {
164
	if (this.delegate != null) this.delegate.forwardReferences();
165
	return forwardReferences;
166
}
142
public void initialize(CodeStream stream) {
167
public void initialize(CodeStream stream) {
143
    this.codeStream = stream;
168
    this.codeStream = stream;
144
   	this.position = Label.POS_NOT_SET;
169
   	this.position = Label.POS_NOT_SET;
145
	this.forwardReferenceCount = 0; 
170
	this.forwardReferenceCount = 0;
171
	this.delegate = null;
146
}
172
}
147
public boolean isCaseLabel() {
173
public boolean isCaseLabel() {
148
	return false;
174
	return false;
Lines 150-155 Link Here
150
public boolean isStandardLabel(){
176
public boolean isStandardLabel(){
151
	return true;
177
	return true;
152
}
178
}
179
153
/*
180
/*
154
* Place the label. If we have forward references resolve them.
181
* Place the label. If we have forward references resolve them.
155
*/
182
*/
Lines 220-225 Link Here
220
		}
247
		}
221
	}
248
	}
222
}
249
}
250
223
/**
251
/**
224
 * Print out the receiver
252
 * Print out the receiver
225
 */
253
 */
Lines 229-234 Link Here
229
	StringBuffer buffer = new StringBuffer(basic); 
257
	StringBuffer buffer = new StringBuffer(basic); 
230
	buffer.append('@').append(Integer.toHexString(hashCode()));
258
	buffer.append('@').append(Integer.toHexString(hashCode()));
231
	buffer.append("(position=").append(this.position); //$NON-NLS-1$
259
	buffer.append("(position=").append(this.position); //$NON-NLS-1$
260
	if (this.delegate != null) buffer.append("delegate=").append(this.delegate); //$NON-NLS-1$
232
	buffer.append(", forwards = ["); //$NON-NLS-1$
261
	buffer.append(", forwards = ["); //$NON-NLS-1$
233
	for (int i = 0; i < this.forwardReferenceCount - 1; i++)
262
	for (int i = 0; i < this.forwardReferenceCount - 1; i++)
234
		buffer.append(this.forwardReferences[i] + ", "); //$NON-NLS-1$
263
		buffer.append(this.forwardReferences[i] + ", "); //$NON-NLS-1$
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/StackMapFrameCodeStream.java (-44 / +29 lines)
Lines 907-969 Link Here
907
	super.imul();
907
	super.imul();
908
	this.currentFrame.numberOfStackItems--;
908
	this.currentFrame.numberOfStackItems--;
909
}
909
}
910
/*
910
public boolean inlineForwardReferencesFromLabelsTargeting(BranchLabel targetLabel, int gotoLocation) {
911
 * Some placed labels might be branching to a goto bytecode which we can optimize better.
911
	int chaining = L_UNKNOWN;
912
 */
912
913
public void inlineForwardReferencesFromLabelsTargeting(BranchLabel label, int gotoLocation) {
914
	
915
/*
916
 Code required to optimized unreachable gotos.
917
	public boolean isBranchTarget(int location) {
918
		Label[] labels = codeStream.labels;
919
		for (int i = codeStream.countLabels - 1; i >= 0; i--){
920
			Label label = labels[i];
921
			if ((label.position == location) && label.isStandardLabel()){
922
				return true;
923
			}
924
		}
925
		return false;
926
	}
927
 */
928
	boolean hasStandardLabel = false;
929
	boolean removeFrame = true;
913
	boolean removeFrame = true;
930
	for (int i = this.countLabels - 1; i >= 0; i--) {
914
	for (int i = this.countLabels - 1; i >= 0; i--) {
931
		BranchLabel currentLabel = labels[i];
915
		BranchLabel currentLabel = labels[i];
932
		if (currentLabel.position == gotoLocation) {
916
		if (currentLabel.position != gotoLocation) break;
933
			if (currentLabel.isStandardLabel()) {
917
		if (currentLabel == targetLabel) {
934
				hasStandardLabel = true;
918
			chaining |= L_CANNOT_OPTIMIZE;
935
				if (currentLabel.forwardReferenceCount == 0 && ((currentLabel.tagBits & BranchLabel.USED) != 0)) {
919
			continue;
936
					removeFrame = false;
920
		}
937
				}
921
		if (currentLabel.isStandardLabel()) {
938
			} else if (currentLabel.isCaseLabel()) {
922
			if (currentLabel.delegate != null) continue; // already inlined		
923
			chaining |= L_OPTIMIZABLE;
924
			if (currentLabel.forwardReferenceCount() == 0 && ((currentLabel.tagBits & BranchLabel.USED) != 0)) {
939
				removeFrame = false;
925
				removeFrame = false;
940
			}
926
			}
941
		} else {
927
			continue;
942
			break; // same target labels should be contiguous
943
		}
928
		}
929
		// case label
930
		removeFrame = false;
931
		chaining |= L_CANNOT_OPTIMIZE;
944
	}
932
	}
945
	if (hasStandardLabel) {
933
	if ((chaining & L_OPTIMIZABLE) != 0) {
946
		for (int i = this.countLabels - 1; i >= 0; i--) {
934
		for (int i = this.countLabels - 1; i >= 0; i--) {
947
			BranchLabel currentLabel = labels[i];
935
			BranchLabel currentLabel = labels[i];
948
			if (currentLabel.position == gotoLocation) {
936
			if (currentLabel.position != gotoLocation) break;
949
				if (currentLabel.isStandardLabel()){
937
			if (currentLabel == targetLabel) continue;
950
					label.appendForwardReferencesFrom(currentLabel);
938
			if (currentLabel.isStandardLabel()) {
951
					// we should remove the frame corresponding to otherLabel position in order to prevent unused stack frame
939
				if (currentLabel.delegate != null) continue; // already inlined
952
					if (removeFrame) {
940
				targetLabel.becomeDelegateFor(currentLabel);
953
						currentLabel.tagBits &= ~BranchLabel.USED;
941
				// we should remove the frame corresponding to otherLabel position in order to prevent unused stack frame
954
						this.removeStackFrameFor(gotoLocation);
942
				if (removeFrame) {
955
					}
943
					currentLabel.tagBits &= ~BranchLabel.USED;
944
					this.removeStackFrameFor(gotoLocation);
956
				}
945
				}
957
				/*
958
				 Code required to optimized unreachable gotos.
959
					label.position = POS_NOT_SET;
960
				*/
961
			} else {
962
				break; // same target labels should be contiguous
963
			}
946
			}
964
		}
947
		}
965
	}
948
	}
949
	return (chaining & (L_OPTIMIZABLE|L_CANNOT_OPTIMIZE)) == L_OPTIMIZABLE; // check was some standards, and no case/recursive	
966
}
950
}
951
967
public void init(ClassFile targetClassFile) {
952
public void init(ClassFile targetClassFile) {
968
	super.init(targetClassFile);
953
	super.init(targetClassFile);
969
	this.framesCounter = 0;
954
	this.framesCounter = 0;
Lines 1613-1619 Link Here
1613
}
1598
}
1614
public void optimizeBranch(int oldPosition, BranchLabel lbl) {
1599
public void optimizeBranch(int oldPosition, BranchLabel lbl) {
1615
	super.optimizeBranch(oldPosition, lbl);
1600
	super.optimizeBranch(oldPosition, lbl);
1616
	if (lbl.forwardReferenceCount > 0) {
1601
	if (lbl.forwardReferenceCount() > 0) {
1617
		StackMapFrame frame = this.frames;
1602
		StackMapFrame frame = this.frames;
1618
		loop: while (frame != null) {
1603
		loop: while (frame != null) {
1619
			if (frame.pc == oldPosition) {
1604
			if (frame.pc == oldPosition) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java (-1 / +1 lines)
Lines 145-151 Link Here
145
				} else {
145
				} else {
146
					codeStream.iconst_1();
146
					codeStream.iconst_1();
147
				}
147
				}
148
				if (falseLabel.forwardReferenceCount > 0) {
148
				if (falseLabel.forwardReferenceCount() > 0) {
149
					if ((bits & IsReturnedValue) != 0) {
149
					if ((bits & IsReturnedValue) != 0) {
150
						codeStream.generateImplicitConversion(this.implicitConversion);
150
						codeStream.generateImplicitConversion(this.implicitConversion);
151
						codeStream.generateReturnBytecode(this);
151
						codeStream.generateReturnBytecode(this);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java (-2 / +2 lines)
Lines 388-395 Link Here
388
		// generated (if any), and have them directly branch to a better
388
		// generated (if any), and have them directly branch to a better
389
		// location (the argument label).
389
		// location (the argument label).
390
		// we know at this point that the breakLabel already got placed
390
		// we know at this point that the breakLabel already got placed
391
		if (this.breakLabel.forwardReferenceCount > 0) {
391
		if (this.breakLabel.forwardReferenceCount() > 0) {
392
			label.appendForwardReferencesFrom(this.breakLabel);
392
			label.becomeDelegateFor(this.breakLabel);
393
		}
393
		}
394
	}
394
	}
395
}
395
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/UnaryExpression.java (-1 / +1 lines)
Lines 85-91 Link Here
85
							valueRequired);
85
							valueRequired);
86
						if (valueRequired) {
86
						if (valueRequired) {
87
							codeStream.iconst_0();
87
							codeStream.iconst_0();
88
							if (falseLabel.forwardReferenceCount > 0) {
88
							if (falseLabel.forwardReferenceCount() > 0) {
89
								codeStream.goto_(endifLabel = new BranchLabel(codeStream));
89
								codeStream.goto_(endifLabel = new BranchLabel(codeStream));
90
								codeStream.decrStackSize(1);
90
								codeStream.decrStackSize(1);
91
								falseLabel.place();
91
								falseLabel.place();
(-)compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java (-1 / +1 lines)
Lines 164-170 Link Here
164
		codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
164
		codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
165
		codeStream.addDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
165
		codeStream.addDefinitelyAssignedVariables(currentScope, this.mergedInitStateIndex);
166
	}
166
	}
167
	if (this.breakLabel.forwardReferenceCount > 0) {
167
	if (this.breakLabel.forwardReferenceCount() > 0) {
168
		this.breakLabel.place();
168
		this.breakLabel.place();
169
	}
169
	}
170
170
(-)compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java (-1 / +1 lines)
Lines 148-154 Link Here
148
				} else {
148
				} else {
149
					codeStream.iconst_0();
149
					codeStream.iconst_0();
150
				}
150
				}
151
				if (trueLabel.forwardReferenceCount > 0) {
151
				if (trueLabel.forwardReferenceCount() > 0) {
152
					if ((bits & IsReturnedValue) != 0) {
152
					if ((bits & IsReturnedValue) != 0) {
153
						codeStream.generateImplicitConversion(this.implicitConversion);
153
						codeStream.generateImplicitConversion(this.implicitConversion);
154
						codeStream.generateReturnBytecode(this);
154
						codeStream.generateReturnBytecode(this);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ConditionalExpression.java (-1 / +1 lines)
Lines 169-175 Link Here
169
					falseInitStateIndex);
169
					falseInitStateIndex);
170
				codeStream.addDefinitelyAssignedVariables(currentScope, falseInitStateIndex);
170
				codeStream.addDefinitelyAssignedVariables(currentScope, falseInitStateIndex);
171
			}
171
			}
172
			if (falseLabel.forwardReferenceCount > 0) {
172
			if (falseLabel.forwardReferenceCount() > 0) {
173
				falseLabel.place();
173
				falseLabel.place();
174
			}
174
			}
175
			valueIfFalse.generateCode(currentScope, codeStream, valueRequired);
175
			valueIfFalse.generateCode(currentScope, codeStream, valueRequired);

Return to bug 114894