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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ClassFile.java (-46 / +50 lines)
Lines 1268-1274 Link Here
1268
		this.contents[codeAttributeOffset + 13] = (byte) code_length;
1268
		this.contents[codeAttributeOffset + 13] = (byte) code_length;
1269
1269
1270
		// write the exception table
1270
		// write the exception table
1271
		int exceptionHandlersNumber = codeStream.exceptionHandlersNumber;
1271
		int exceptionHandlersNumber = codeStream.exceptionHandlersCounter;
1272
		ExceptionLabel[] exceptionHandlers = codeStream.exceptionHandlers;
1272
		ExceptionLabel[] exceptionHandlers = codeStream.exceptionHandlers;
1273
		int exSize = exceptionHandlersNumber * 8 + 2;
1273
		int exSize = exceptionHandlersNumber * 8 + 2;
1274
		if (exSize + localContentsOffset >= this.contents.length) {
1274
		if (exSize + localContentsOffset >= this.contents.length) {
Lines 1278-1308 Link Here
1278
		// on the attribute generation
1278
		// on the attribute generation
1279
		this.contents[localContentsOffset++] = (byte) (exceptionHandlersNumber >> 8);
1279
		this.contents[localContentsOffset++] = (byte) (exceptionHandlersNumber >> 8);
1280
		this.contents[localContentsOffset++] = (byte) exceptionHandlersNumber;
1280
		this.contents[localContentsOffset++] = (byte) exceptionHandlersNumber;
1281
		for (int i = 0; i < exceptionHandlersNumber; i++) {
1281
		for (int i = 0, max = codeStream.exceptionHandlersIndex; i < max; i++) {
1282
			ExceptionLabel exceptionHandler = exceptionHandlers[i];
1282
			ExceptionLabel exceptionHandler = exceptionHandlers[i];
1283
			int start = exceptionHandler.start;
1283
			if (exceptionHandler != null) {
1284
			this.contents[localContentsOffset++] = (byte) (start >> 8);
1284
				int start = exceptionHandler.start;
1285
			this.contents[localContentsOffset++] = (byte) start;
1285
				this.contents[localContentsOffset++] = (byte) (start >> 8);
1286
			int end = exceptionHandler.end;
1286
				this.contents[localContentsOffset++] = (byte) start;
1287
			this.contents[localContentsOffset++] = (byte) (end >> 8);
1287
				int end = exceptionHandler.end;
1288
			this.contents[localContentsOffset++] = (byte) end;
1288
				this.contents[localContentsOffset++] = (byte) (end >> 8);
1289
			int handlerPC = exceptionHandler.position;
1289
				this.contents[localContentsOffset++] = (byte) end;
1290
			this.contents[localContentsOffset++] = (byte) (handlerPC >> 8);
1290
				int handlerPC = exceptionHandler.position;
1291
			this.contents[localContentsOffset++] = (byte) handlerPC;
1291
				this.contents[localContentsOffset++] = (byte) (handlerPC >> 8);
1292
			if (exceptionHandler.exceptionType == null) {
1292
				this.contents[localContentsOffset++] = (byte) handlerPC;
1293
				// any exception handler
1293
				if (exceptionHandler.exceptionType == null) {
1294
				this.contents[localContentsOffset++] = 0;
1294
					// any exception handler
1295
				this.contents[localContentsOffset++] = 0;
1295
					this.contents[localContentsOffset++] = 0;
1296
			} else {
1296
					this.contents[localContentsOffset++] = 0;
1297
				int nameIndex;
1298
				if (exceptionHandler.exceptionType == BaseTypes.NullBinding) {
1299
					/* represents ClassNotFoundException, see class literal access*/
1300
					nameIndex = constantPool.literalIndexForJavaLangClassNotFoundException();
1301
				} else {
1297
				} else {
1302
					nameIndex = constantPool.literalIndex(exceptionHandler.exceptionType);
1298
					int nameIndex;
1299
					if (exceptionHandler.exceptionType == BaseTypes.NullBinding) {
1300
						/* represents ClassNotFoundException, see class literal access*/
1301
						nameIndex = constantPool.literalIndexForJavaLangClassNotFoundException();
1302
					} else {
1303
						nameIndex = constantPool.literalIndex(exceptionHandler.exceptionType);
1304
					}
1305
					this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
1306
					this.contents[localContentsOffset++] = (byte) nameIndex;
1303
				}
1307
				}
1304
				this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
1305
				this.contents[localContentsOffset++] = (byte) nameIndex;
1306
			}
1308
			}
1307
		}
1309
		}
1308
		// debug attributes
1310
		// debug attributes
Lines 1578-1584 Link Here
1578
		this.contents[codeAttributeOffset + 13] = (byte) code_length;
1580
		this.contents[codeAttributeOffset + 13] = (byte) code_length;
1579
1581
1580
		// write the exception table
1582
		// write the exception table
1581
		int exceptionHandlersNumber = codeStream.exceptionHandlersNumber;
1583
		int exceptionHandlersNumber = codeStream.exceptionHandlersCounter;
1582
		ExceptionLabel[] exceptionHandlers = codeStream.exceptionHandlers;
1584
		ExceptionLabel[] exceptionHandlers = codeStream.exceptionHandlers;
1583
		int exSize = exceptionHandlersNumber * 8 + 2;
1585
		int exSize = exceptionHandlersNumber * 8 + 2;
1584
		if (exSize + localContentsOffset >= this.contents.length) {
1586
		if (exSize + localContentsOffset >= this.contents.length) {
Lines 1588-1618 Link Here
1588
		// on the attribute generation
1590
		// on the attribute generation
1589
		this.contents[localContentsOffset++] = (byte) (exceptionHandlersNumber >> 8);
1591
		this.contents[localContentsOffset++] = (byte) (exceptionHandlersNumber >> 8);
1590
		this.contents[localContentsOffset++] = (byte) exceptionHandlersNumber;
1592
		this.contents[localContentsOffset++] = (byte) exceptionHandlersNumber;
1591
		for (int i = 0; i < exceptionHandlersNumber; i++) {
1593
		for (int i = 0, max = codeStream.exceptionHandlersIndex; i < max; i++) {
1592
			ExceptionLabel exceptionHandler = exceptionHandlers[i];
1594
			ExceptionLabel exceptionHandler = exceptionHandlers[i];
1593
			int start = exceptionHandler.start;
1595
			if (exceptionHandler != null) {
1594
			this.contents[localContentsOffset++] = (byte) (start >> 8);
1596
				int start = exceptionHandler.start;
1595
			this.contents[localContentsOffset++] = (byte) start;
1597
				this.contents[localContentsOffset++] = (byte) (start >> 8);
1596
			int end = exceptionHandler.end;
1598
				this.contents[localContentsOffset++] = (byte) start;
1597
			this.contents[localContentsOffset++] = (byte) (end >> 8);
1599
				int end = exceptionHandler.end;
1598
			this.contents[localContentsOffset++] = (byte) end;
1600
				this.contents[localContentsOffset++] = (byte) (end >> 8);
1599
			int handlerPC = exceptionHandler.position;
1601
				this.contents[localContentsOffset++] = (byte) end;
1600
			this.contents[localContentsOffset++] = (byte) (handlerPC >> 8);
1602
				int handlerPC = exceptionHandler.position;
1601
			this.contents[localContentsOffset++] = (byte) handlerPC;
1603
				this.contents[localContentsOffset++] = (byte) (handlerPC >> 8);
1602
			if (exceptionHandler.exceptionType == null) {
1604
				this.contents[localContentsOffset++] = (byte) handlerPC;
1603
				// any exception handler
1605
				if (exceptionHandler.exceptionType == null) {
1604
				this.contents[localContentsOffset++] = 0;
1606
					// any exception handler
1605
				this.contents[localContentsOffset++] = 0;
1607
					this.contents[localContentsOffset++] = 0;
1606
			} else {
1608
					this.contents[localContentsOffset++] = 0;
1607
				int nameIndex;
1608
				if (exceptionHandler.exceptionType == BaseTypes.NullBinding) {
1609
					/* represents denote ClassNotFoundException, see class literal access*/
1610
					nameIndex = constantPool.literalIndexForJavaLangClassNotFoundException();
1611
				} else {
1609
				} else {
1612
					nameIndex = constantPool.literalIndex(exceptionHandler.exceptionType);
1610
					int nameIndex;
1611
					if (exceptionHandler.exceptionType == BaseTypes.NullBinding) {
1612
						/* represents denote ClassNotFoundException, see class literal access*/
1613
						nameIndex = constantPool.literalIndexForJavaLangClassNotFoundException();
1614
					} else {
1615
						nameIndex = constantPool.literalIndex(exceptionHandler.exceptionType);
1616
					}
1617
					this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
1618
					this.contents[localContentsOffset++] = (byte) nameIndex;
1613
				}
1619
				}
1614
				this.contents[localContentsOffset++] = (byte) (nameIndex >> 8);
1615
				this.contents[localContentsOffset++] = (byte) nameIndex;
1616
			}
1620
			}
1617
		}
1621
		}
1618
		// debug attributes
1622
		// debug attributes
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SubRoutineStatement.java (-1 / +3 lines)
Lines 44-51 Link Here
44
		if (currentLabel.start == currentLabel.codeStream.position) {
44
		if (currentLabel.start == currentLabel.codeStream.position) {
45
			// discard empty exception handler
45
			// discard empty exception handler
46
			this.anyExceptionLabels[--this.anyExceptionLabelsCount] = null;
46
			this.anyExceptionLabels[--this.anyExceptionLabelsCount] = null;
47
			currentLabel.codeStream.removeExceptionHandler(currentLabel);
48
		} else {
49
			currentLabel.placeEnd();
47
		}
50
		}
48
		currentLabel.placeEnd();
49
	}
51
	}
50
	
52
	
51
	public void placeAllAnyExceptionHandlers() {
53
	public void placeAllAnyExceptionHandlers() {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SynchronizedStatement.java (-6 / +4 lines)
Lines 71-77 Link Here
71
	 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
71
	 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
72
	 */
72
	 */
73
	public void generateCode(BlockScope currentScope, CodeStream codeStream) {
73
	public void generateCode(BlockScope currentScope, CodeStream codeStream) {
74
74
	
75
		if ((bits & IsReachableMASK) == 0) {
75
		if ((bits & IsReachableMASK) == 0) {
76
			return;
76
			return;
77
		}
77
		}
Lines 82-88 Link Here
82
			this.anyExceptionLabelsCount = 0;
82
			this.anyExceptionLabelsCount = 0;
83
		}
83
		}
84
		int pc = codeStream.position;
84
		int pc = codeStream.position;
85
85
	
86
		// generate the synchronization expression
86
		// generate the synchronization expression
87
		expression.generateCode(scope, codeStream, true);
87
		expression.generateCode(scope, codeStream, true);
88
		if (block.isEmptyBlock()) {
88
		if (block.isEmptyBlock()) {
Lines 99-105 Link Here
99
			// enter the monitor
99
			// enter the monitor
100
			codeStream.store(synchroVariable, true);
100
			codeStream.store(synchroVariable, true);
101
			codeStream.monitorenter();
101
			codeStream.monitorenter();
102
102
	
103
			// generate  the body of the synchronized block
103
			// generate  the body of the synchronized block
104
			this.enterAnyExceptionHandler(codeStream);
104
			this.enterAnyExceptionHandler(codeStream);
105
			block.generateCode(scope, codeStream);
105
			block.generateCode(scope, codeStream);
Lines 107-122 Link Here
107
			if (!blockExit) {
107
			if (!blockExit) {
108
				codeStream.load(synchroVariable);
108
				codeStream.load(synchroVariable);
109
				codeStream.monitorexit();
109
				codeStream.monitorexit();
110
				this.exitAnyExceptionHandler();				
111
				codeStream.goto_(endLabel);
110
				codeStream.goto_(endLabel);
112
				this.enterAnyExceptionHandler(codeStream);
113
			}
111
			}
114
			// generate the body of the exception handler
112
			// generate the body of the exception handler
113
			this.exitAnyExceptionHandler();
115
			this.placeAllAnyExceptionHandlers();
114
			this.placeAllAnyExceptionHandlers();
116
			codeStream.incrStackSize(1);
115
			codeStream.incrStackSize(1);
117
			codeStream.load(synchroVariable);
116
			codeStream.load(synchroVariable);
118
			codeStream.monitorexit();
117
			codeStream.monitorexit();
119
			this.exitAnyExceptionHandler();
120
			codeStream.athrow();
118
			codeStream.athrow();
121
			if (!blockExit) {
119
			if (!blockExit) {
122
				endLabel.place();
120
				endLabel.place();
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java (-5 / +1 lines)
Lines 298-306 Link Here
298
					}
298
					}
299
				}
299
				}
300
			}
300
			}
301
			if (finallyMode != FINALLY_SUBROUTINE || this.subRoutineStartLabel == null) {
301
			this.exitAnyExceptionHandler();
302
				this.exitAnyExceptionHandler();
303
			}
304
			// extra handler for trailing natural exit (will be fixed up later on when natural exit is generated below)
302
			// extra handler for trailing natural exit (will be fixed up later on when natural exit is generated below)
305
			ExceptionLabel naturalExitExceptionHandler = 
303
			ExceptionLabel naturalExitExceptionHandler = 
306
				finallyMode == FINALLY_SUBROUTINE && requiresNaturalExit ? new ExceptionLabel(codeStream, null) : null;
304
				finallyMode == FINALLY_SUBROUTINE && requiresNaturalExit ? new ExceptionLabel(codeStream, null) : null;
Lines 319-329 Link Here
319
317
320
				codeStream.incrStackSize(1);
318
				codeStream.incrStackSize(1);
321
				switch(finallyMode) {
319
				switch(finallyMode) {
322
					
323
					case FINALLY_SUBROUTINE :
320
					case FINALLY_SUBROUTINE :
324
						codeStream.store(anyExceptionVariable, false);
321
						codeStream.store(anyExceptionVariable, false);
325
						codeStream.jsr(subRoutineStartLabel);
322
						codeStream.jsr(subRoutineStartLabel);
326
						this.exitAnyExceptionHandler();
327
						codeStream.load(anyExceptionVariable);
323
						codeStream.load(anyExceptionVariable);
328
						codeStream.athrow();
324
						codeStream.athrow();
329
						subRoutineStartLabel.place();
325
						subRoutineStartLabel.place();
(-)compiler/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java (-4 / +17 lines)
Lines 49-55 Link Here
49
	public AbstractMethodDeclaration methodDeclaration;
49
	public AbstractMethodDeclaration methodDeclaration;
50
	public ExceptionLabel[] exceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
50
	public ExceptionLabel[] exceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
51
	static ExceptionLabel[] noExceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
51
	static ExceptionLabel[] noExceptionHandlers = new ExceptionLabel[LABELS_INCREMENT];
52
	public int exceptionHandlersNumber;
52
	public int exceptionHandlersIndex;
53
	public int exceptionHandlersCounter;
54
	
53
	public static FieldBinding[] ImplicitThis = new FieldBinding[] {};
55
	public static FieldBinding[] ImplicitThis = new FieldBinding[] {};
54
	public boolean generateLineNumberAttributes;
56
	public boolean generateLineNumberAttributes;
55
	public boolean generateLocalVariableTableAttributes;
57
	public boolean generateLocalVariableTableAttributes;
Lines 2713-2719 Link Here
2713
		noExceptionHandlers = new ExceptionLabel[length];
2715
		noExceptionHandlers = new ExceptionLabel[length];
2714
	}
2716
	}
2715
	System.arraycopy(noExceptionHandlers, 0, exceptionHandlers, 0, length);
2717
	System.arraycopy(noExceptionHandlers, 0, exceptionHandlers, 0, length);
2716
	exceptionHandlersNumber = 0;
2718
	exceptionHandlersIndex = 0;
2719
	exceptionHandlersCounter = 0;
2717
	
2720
	
2718
	length = labels.length;
2721
	length = labels.length;
2719
	if (noLabels.length < length) {
2722
	if (noLabels.length < length) {
Lines 4760-4771 Link Here
4760
 */
4763
 */
4761
public void registerExceptionHandler(ExceptionLabel anExceptionLabel) {
4764
public void registerExceptionHandler(ExceptionLabel anExceptionLabel) {
4762
	int length;
4765
	int length;
4763
	if (exceptionHandlersNumber >= (length = exceptionHandlers.length)) {
4766
	if (exceptionHandlersIndex >= (length = exceptionHandlers.length)) {
4764
		// resize the exception handlers table
4767
		// resize the exception handlers table
4765
		System.arraycopy(exceptionHandlers, 0, exceptionHandlers = new ExceptionLabel[length + LABELS_INCREMENT], 0, length);
4768
		System.arraycopy(exceptionHandlers, 0, exceptionHandlers = new ExceptionLabel[length + LABELS_INCREMENT], 0, length);
4766
	}
4769
	}
4767
	// no need to resize. So just add the new exception label
4770
	// no need to resize. So just add the new exception label
4768
	exceptionHandlers[exceptionHandlersNumber++] = anExceptionLabel;
4771
	exceptionHandlers[exceptionHandlersIndex++] = anExceptionLabel;
4772
	exceptionHandlersCounter++;
4773
}
4774
public void removeExceptionHandler(ExceptionLabel exceptionLabel) {
4775
	for (int i = 0; i < exceptionHandlersIndex; i++) {
4776
		if (exceptionHandlers[i] == exceptionLabel) {
4777
			exceptionHandlers[i] = null;
4778
			exceptionHandlersCounter--;
4779
			return;
4780
		}
4781
	}
4769
}
4782
}
4770
public final void removeNotDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
4783
public final void removeNotDefinitelyAssignedVariables(Scope scope, int initStateIndex) {
4771
	// given some flow info, make sure we did not loose some variables initialization
4784
	// given some flow info, make sure we did not loose some variables initialization

Return to bug 71910