From a22be1267ace5faa9c16787910ed32227367177d Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Tue, 17 May 2011 09:51:59 +0000 Subject: Error reporting when the generated code size ex... Error reporting when the generated code size exceeds JVM limits (65,535 bytes per method). Closed #4573. review by extempore. --- src/fjbg/ch/epfl/lamp/fjbg/JCode.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/fjbg/ch/epfl') diff --git a/src/fjbg/ch/epfl/lamp/fjbg/JCode.java b/src/fjbg/ch/epfl/lamp/fjbg/JCode.java index 332cc7c518..d80f9f5f94 100644 --- a/src/fjbg/ch/epfl/lamp/fjbg/JCode.java +++ b/src/fjbg/ch/epfl/lamp/fjbg/JCode.java @@ -22,6 +22,8 @@ import ch.epfl.lamp.util.ByteArray; public class JCode { protected boolean frozen = false; + public static int MAX_CODE_SIZE = 65535; + protected final FJBGContext context; protected final JMethod owner; @@ -57,8 +59,8 @@ public class JCode { this.owner = owner; owner.setCode(this); int size = stream.readInt(); - if (size >= 65536) // section 4.10 - throw new Error("code size must be less than 65536: " + size); + if (size > MAX_CODE_SIZE) // section 4.10 + throw new Error("code size must be less than " + MAX_CODE_SIZE + ": " + size); this.codeArray = new ByteArray(stream, size); } @@ -97,8 +99,19 @@ public class JCode { // Freezing ////////////////////////////////////////////////////////////////////// + public static class CodeSizeTooBigException extends OffsetTooBigException { + public int codeSize; + + public CodeSizeTooBigException(int size) { + codeSize = size; + } + } + public void freeze() throws OffsetTooBigException { assert !frozen; + + if (getSize() > MAX_CODE_SIZE) throw new CodeSizeTooBigException(getSize()); + patchAllOffset(); codeArray.freeze(); frozen = true; -- cgit v1.2.3