Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 79665 invoked from network); 25 Oct 2007 14:48:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Oct 2007 14:48:49 -0000 Received: (qmail 15375 invoked by uid 500); 25 Oct 2007 14:48:35 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 15352 invoked by uid 500); 25 Oct 2007 14:48:35 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 15152 invoked by uid 99); 25 Oct 2007 14:48:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2007 07:48:34 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2007 14:48:44 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5CD371A9851; Thu, 25 Oct 2007 07:48:01 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r588245 [7/10] - in /harmony/enhanced/classlib/branches/java6: depends/build/ depends/files/ make/ modules/annotation/src/test/java/org/apache/harmony/annotation/tests/java/lang/annotation/ modules/archive/ modules/archive/src/main/java/jav... Date: Thu, 25 Oct 2007 14:45:48 -0000 To: commits@harmony.apache.org From: tellison@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071025144801.5CD371A9851@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Thu Oct 25 07:44:56 2007 @@ -20,8 +20,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; import org.apache.harmony.pack200.bytecode.CPClass; import org.apache.harmony.pack200.bytecode.ConstantValueAttribute; @@ -32,8 +30,6 @@ */ public class ClassBands extends BandSet { - private int classAttrCount; - private int[] classFieldCount; private long[] classFlags; @@ -45,6 +41,8 @@ private String[] classSuper; private String[] classThis; + + private ArrayList[] classAttributes; private int[] codeHandlerCount; @@ -67,23 +65,30 @@ private String[][] methodDescr; private ExceptionsAttribute[][] methodExceptions; - + private long[][] methodFlags; private AttributeLayoutMap attrMap; private CpBands cpBands; - private int codeAttrCount; + private SegmentOptions options; + private int classCount; + + private int[] methodAttrCalls; + /** - * @param header + * @param segment */ public ClassBands(Segment segment) { super(segment); this.attrMap = segment.getAttrDefinitionBands() .getAttributeDefinitionMap(); this.cpBands = segment.getCpBands(); + this.classCount = header.getClassCount(); + this.options = header.getOptions(); + } /* @@ -107,13 +112,10 @@ cpBands.getCpClass()); classSuper = parseReferences("class_super", in, Codec.DELTA5, classCount, cpBands.getCpClass()); - classInterfaces = new String[classCount][]; int[] classInterfaceLengths = decodeBandInt("class_interface_count", in, Codec.DELTA5, classCount); - // for (int i = 0; i < classCount; i++) { classInterfaces = parseReferences("class_interface", in, Codec.DELTA5, classInterfaceLengths, cpBands.getCpClass()); - // } classFieldCount = decodeBandInt("class_field_count", in, Codec.DELTA5, classCount); classMethodCount = decodeBandInt("class_method_count", in, @@ -127,106 +129,122 @@ private void parseFieldBands(InputStream in) throws IOException, Pack200Exception { - int classCount = header.getClassCount(); - SegmentOptions options = header.getOptions(); fieldDescr = parseReferences("field_descr", in, Codec.DELTA5, classFieldCount, cpBands.getCpDescriptor()); - fieldFlags = parseFlags("field_flags", in, classCount, classFieldCount, + fieldFlags = parseFlags("field_flags", in, classFieldCount, Codec.UNSIGNED5, options.hasFieldFlagsHi()); - for (int i = 0; i < classCount; i++) { + for (int i = 0; i < fieldFlags.length; i++) { for (int j = 0; j < fieldFlags[i].length; j++) { long flag = fieldFlags[i][j]; if ((flag & (1 << 16)) != 0) fieldAttrCount++; } } - if (fieldAttrCount > 0) - throw new Error( - "There are attribute flags, and I don't know what to do with them"); - debug("unimplemented field_attr_indexes"); - debug("unimplemented field_attr_calls"); + int[] fieldAttrCounts = decodeBandInt("field_attr_count", in, Codec.UNSIGNED5, fieldAttrCount); + int[][] fieldAttrIndexes = decodeBandInt("field_attr_indexes", in, Codec.UNSIGNED5, fieldAttrCounts); + int callCount = 0; + for (int i = 0; i < fieldAttrIndexes.length; i++) { + for (int j = 0; j < fieldAttrIndexes[i].length; j++) { + int index = fieldAttrIndexes[i][j]; + AttributeLayout layout = attrMap.getAttributeLayout(index, AttributeLayout.CONTEXT_FIELD); + callCount += layout.numBackwardsCallables(); + } + } + int[] fieldAttrCalls = decodeBandInt("field_attr_calls", in, Codec.UNSIGNED5, callCount); AttributeLayout layout = attrMap.getAttributeLayout("ConstantValue", AttributeLayout.CONTEXT_FIELD); - Codec codec = layout.getCodec(); - fieldAttributes = new ArrayList[classCount][]; - for (int i = 0; i < classCount; i++) { - fieldAttributes[i] = new ArrayList[fieldFlags[i].length]; - for (int j = 0; j < fieldFlags[i].length; j++) { - fieldAttributes[i][j] = new ArrayList(); - long flag = fieldFlags[i][j]; - if (layout.matches(flag)) { - // we've got a value to read - long result = codec.decode(in); - String desc = fieldDescr[i][j]; - int colon = desc.indexOf(':'); - // String name = desc.substring(0, colon); - String type = desc.substring(colon + 1); - // TODO Got to get better at this ... in any case, it should - // be e.g. KIB or KIH - if (type.equals("B") || type.equals("H")) - type = "I"; - Object value = layout.getValue(result, type, cpBands - .getConstantPool()); - fieldAttributes[i][j] - .add(new ConstantValueAttribute(value)); - debug("Processed value " + value + " for ConstantValue"); + int constantCount = SegmentUtils.countMatches(fieldFlags, layout); + if(constantCount > 0) { + int[] field_constantValue_KQ = decodeBandInt("field_ConstantValue_KQ", in, Codec.UNSIGNED5, constantCount); + int index = 0; + fieldAttributes = new ArrayList[classCount][]; + for (int i = 0; i < classCount; i++) { + fieldAttributes[i] = new ArrayList[fieldFlags[i].length]; + for (int j = 0; j < fieldFlags[i].length; j++) { + fieldAttributes[i][j] = new ArrayList(); + long flag = fieldFlags[i][j]; + if (layout.matches(flag)) { + // we've got a value to read + long result = field_constantValue_KQ[index]; + String desc = fieldDescr[i][j]; + int colon = desc.indexOf(':'); + // String name = desc.substring(0, colon); + String type = desc.substring(colon + 1); + // TODO Got to get better at this ... in any case, it should + // be e.g. KIB or KIH + if (type.equals("B") || type.equals("H")) + type = "I"; + Object value = layout.getValue(result, type, cpBands + .getConstantPool()); + fieldAttributes[i][j] + .add(new ConstantValueAttribute(value)); + debug("Processed value " + value + " for ConstantValue"); + index++; + } } } } layout = attrMap.getAttributeLayout(AttributeLayout.ATTRIBUTE_SIGNATURE, AttributeLayout.CONTEXT_FIELD); - codec = layout.getCodec(); -// fieldAttributes = new ArrayList[classCount][]; - for (int i = 0; i < classCount; i++) { -// fieldAttributes[i] = new ArrayList[fieldFlags[i].length]; - for (int j = 0; j < fieldFlags[i].length; j++) { -// fieldAttributes[i][j] = new ArrayList(); - long flag = fieldFlags[i][j]; - if (layout.matches(flag)) { - // we've got a value to read - long result = codec.decode(in); -// String desc = fieldDescr[i][j]; -// int colon = desc.indexOf(':'); -// // String name = desc.substring(0, colon); -// String type = desc.substring(colon + 1); -// // TODO Got to get better at this ... in any case, it should -// // be e.g. KIB or KIH -// if (type.equals("B") || type.equals("H")) -// type = "I"; -// Object value = layout.getValue(result, type, cpBands -// .getConstantPool()); -// fieldAttributes[i][j] -// .add(new ConstantValueAttribute(value)); - debug("Found a signature attribute: " + result); + int signatureCount = SegmentUtils.countMatches(fieldFlags, layout); + if (signatureCount > 0) { + int[] fieldSignatureRS = decodeBandInt("field_Signature_RS", in, Codec.UNSIGNED5, signatureCount); + int index = 0; + fieldAttributes = new ArrayList[classCount][]; + for (int i = 0; i < classCount; i++) { + fieldAttributes[i] = new ArrayList[fieldFlags[i].length]; + for (int j = 0; j < fieldFlags[i].length; j++) { + fieldAttributes[i][j] = new ArrayList(); + long flag = fieldFlags[i][j]; + if (layout.matches(flag)) { + // we've got a signature attribute + long result = fieldSignatureRS[index]; + String desc = fieldDescr[i][j]; + int colon = desc.indexOf(':'); + // String name = desc.substring(0, colon); + String type = desc.substring(colon + 1); + // TODO Got to get better at this ... in any case, it should + // be e.g. KIB or KIH + if (type.equals("B") || type.equals("H")) + type = "I"; + Object value = layout.getValue(result, type, cpBands + .getConstantPool()); + fieldAttributes[i][j] + .add(new ConstantValueAttribute(value)); + index++; + debug("Found a signature attribute: " + result); + } } } } -// debug("unimplemented field_Signature_RS"); parseFieldMetadataBands(); } private void parseMethodBands(InputStream in) throws IOException, Pack200Exception { - int classCount = header.getClassCount(); - SegmentOptions options = header.getOptions(); methodDescr = parseReferences("method_descr", in, Codec.MDELTA5, classMethodCount, cpBands.getCpDescriptor()); - methodFlags = parseFlags("method_flags", in, classCount, - classMethodCount, Codec.UNSIGNED5, options.hasMethodFlagsHi()); + methodFlags = parseFlags("method_flags", in, classMethodCount, + Codec.UNSIGNED5, options.hasMethodFlagsHi()); for (int i = 0; i < classCount; i++) { for (int j = 0; j < methodFlags[i].length; j++) { long flag = methodFlags[i][j]; if ((flag & (1 << 16)) != 0) methodAttrCount++; } + } + int[] methodAttrCounts = decodeBandInt("method_attr_count", in, Codec.UNSIGNED5, methodAttrCount); + int[][] methodAttrIndexes = decodeBandInt("method_attr_indexes", in, Codec.UNSIGNED5, methodAttrCounts); + int callCount = 0; + for (int i = 0; i < methodAttrIndexes.length; i++) { + for (int j = 0; j < methodAttrIndexes[i].length; j++) { + int index = methodAttrIndexes[i][j]; + AttributeLayout layout = attrMap.getAttributeLayout(index, AttributeLayout.CONTEXT_METHOD); + callCount += layout.numBackwardsCallables(); + } } - if (methodAttrCount > 0) - throw new Error( - "There are method attribute flags, and I don't know what to do with them"); - debug("unimplemented method_attr_count"); - debug("unimplemented method_attr_indexes"); - debug("unimplemented method_attr_calls"); + methodAttrCalls = decodeBandInt("code_attr_calls", in, Codec.UNSIGNED5, callCount); // assign empty method attributes methodAttributes = new ArrayList[classCount][]; for (int i = 0; i < classCount; i++) { @@ -236,10 +254,41 @@ } } parseAttributeMethodExceptions(in); - parseAttributeMethodSignature(in); + parseAttributeMethodSigntaure(in); parseMethodMetadataBands(); } + private void parseAttributeMethodSigntaure(InputStream in) throws IOException, Pack200Exception { + AttributeLayout layout = attrMap.getAttributeLayout(AttributeLayout.ATTRIBUTE_SIGNATURE, + AttributeLayout.CONTEXT_METHOD); + int count = SegmentUtils.countMatches(methodFlags, layout); + long[] methodSignatureRS = decodeBandLong("method_signature_RS", in, Codec.UNSIGNED5, count); + int index = 0; + for (int i = 0; i < methodAttributes.length; i++) { + for (int j = 0; j < methodAttributes[i].length; j++) { + long flag = methodFlags[i][j]; + if (layout.matches(flag)) { + // we've got a signature attribute + long result = methodSignatureRS[index]; + String desc = methodDescr[i][j]; + int colon = desc.indexOf(':'); + // String name = desc.substring(0, colon); + String type = desc.substring(colon + 1); + // TODO Got to get better at this ... in any case, it should + // be e.g. KIB or KIH + if (type.equals("B") || type.equals("H")) + type = "I"; + Object value = layout.getValue(result, type, cpBands + .getConstantPool()); + methodAttributes[i][j] + .add(new ConstantValueAttribute(value)); + index++; + debug("Found a signature attribute: " + result); + } + } + } + } + /** * @param in * @throws Pack200Exception @@ -247,123 +296,159 @@ */ private void parseAttributeMethodExceptions(InputStream in) throws Pack200Exception, IOException { - // TODO Should refactor this stuff into the layout somehow - int classCount = header.getClassCount(); AttributeLayout layout = attrMap.getAttributeLayout("Exceptions", AttributeLayout.CONTEXT_METHOD); - Codec codec = layout.getCodec(); methodExceptions = new ExceptionsAttribute[classCount][]; - int[][] numExceptions = new int[classCount][]; - for (int i = 0; i < classCount; i++) { - numExceptions[i] = new int[methodFlags[i].length]; - for (int j = 0; j < methodFlags[i].length; j++) { - long flag = methodFlags[i][j]; - if (layout.matches(flag)) { - numExceptions[i][j] = (int) codec.decode(in); - } - } - } + int count = SegmentUtils.countMatches(methodFlags, layout); + int[] numExceptions = decodeBandInt("method_Exceptions_n", in, Codec.UNSIGNED5, count); + String[][] methodExceptionsRS = parseReferences("method_Exceptions_RC", in, Codec.UNSIGNED5, numExceptions, cpBands.getCpClass()); + int index = 0; for (int i = 0; i < classCount; i++) { methodExceptions[i] = new ExceptionsAttribute[methodFlags[i].length]; for (int j = 0; j < methodFlags[i].length; j++) { long flag = methodFlags[i][j]; - int n = numExceptions[i][j]; - if (n > 0) { - CPClass[] exceptions = new CPClass[n]; - if (layout.matches(flag)) { - for (int k = 0; k < n; k++) { - long result = codec.decode(in); - exceptions[k] = new CPClass( - cpBands.getCpClass()[(int) result]); - } + if(layout.matches(flag)) { + int n = numExceptions[index]; + String[] exceptions = methodExceptionsRS[index]; + CPClass[] exceptionClasses = new CPClass[n]; + for (int k = 0; k < n; k++) { + exceptionClasses[k] = new CPClass(exceptions[k]); } - methodExceptions[i][j] = new ExceptionsAttribute(exceptions); + methodExceptions[i][j] = new ExceptionsAttribute(exceptionClasses); methodAttributes[i][j].add(methodExceptions[i][j]); + index ++; } } } } - /** - * @param name - * @param flags - * @throws Pack200Exception - */ - private void parseAttributeUnknown(String name, int context, long[][] flags) - throws Pack200Exception { - debug("Parsing unknown attributes for " + name); - AttributeLayout layout = attrMap.getAttributeLayout(name, context); - int count = SegmentUtils.countMatches(flags, layout); - if (count > 0) - throw new Error("We've got data for " + name - + " and we don't know what to do with it (yet)"); - } - - /** - * @param in - * - */ - private void parseAttributeMethodSignature(InputStream in) - throws Pack200Exception, IOException { - parseAttributeUnknown(AttributeLayout.ATTRIBUTE_SIGNATURE, - AttributeLayout.CONTEXT_METHOD, methodFlags); - } - private void parseClassAttrBands(InputStream in) throws IOException, Pack200Exception { - int classCount = header.getClassCount(); - SegmentOptions options = header.getOptions(); classFlags = parseFlags("class_flags", in, classCount, Codec.UNSIGNED5, options.hasClassFlagsHi()); - for (int i = 0; i < classCount; i++) { + int classAttrCount = 0; + for (int i = 0; i < classFlags.length; i++) { long flag = classFlags[i]; if ((flag & (1 << 16)) != 0) classAttrCount++; } - if (classAttrCount > 0) - throw new Error( - "There are attribute flags, and I don't know what to do with them"); - debug("unimplemented class_attr_count"); - debug("unimplemented class_attr_indexes"); - debug("unimplemented class_attr_calls"); - AttributeLayout layout = attrMap.getAttributeLayout( + int[] classAttrCounts = decodeBandInt("class_attr_count", in, Codec.UNSIGNED5, classAttrCount); + int[][] classAttrIndexes = decodeBandInt("class_attr_indexes", in, Codec.UNSIGNED5, classAttrCounts); + int callCount = 0; + for (int i = 0; i < classAttrIndexes.length; i++) { + for (int j = 0; j < classAttrIndexes[i].length; j++) { + int index = classAttrIndexes[i][j]; + AttributeLayout layout = attrMap.getAttributeLayout(index, AttributeLayout.CONTEXT_CLASS); + callCount += layout.numBackwardsCallables(); + } + } + int[] classAttrCalls = decodeBandInt("class_attr_calls", in, Codec.UNSIGNED5, callCount); + + AttributeLayout sourceFileLayout = attrMap.getAttributeLayout( AttributeLayout.ATTRIBUTE_SOURCE_FILE, AttributeLayout.CONTEXT_CLASS); + int sourceFileCount = SegmentUtils.countMatches(classFlags, + sourceFileLayout); + int[] classSourceFile = decodeBandInt("class_SourceFile_RUN", in, + Codec.UNSIGNED5, sourceFileCount); + + AttributeLayout enclosingMethodLayout = attrMap.getAttributeLayout( + AttributeLayout.ATTRIBUTE_ENCLOSING_METHOD, + AttributeLayout.CONTEXT_CLASS); + int enclosingMethodCount = SegmentUtils.countMatches(classFlags, + enclosingMethodLayout); + int[] enclosingMethodRC = decodeBandInt("class_EnclosingMethod_RC", in, + Codec.UNSIGNED5, enclosingMethodCount); + int[] enclosingMethodRDN = decodeBandInt("class_EnclosingMethod_RDN", in, + Codec.UNSIGNED5, enclosingMethodCount); + + AttributeLayout signatureLayout = attrMap.getAttributeLayout( + AttributeLayout.ATTRIBUTE_SIGNATURE, + AttributeLayout.CONTEXT_CLASS); + int signatureCount = SegmentUtils.countMatches(classFlags, + signatureLayout); + int[] classSignature = decodeBandInt("class_Signature_RS", in, + Codec.UNSIGNED5, signatureCount); + + parseClassMetadataBands(); + + AttributeLayout innerClassLayout = attrMap.getAttributeLayout( + AttributeLayout.ATTRIBUTE_INNER_CLASSES, + AttributeLayout.CONTEXT_CLASS); + int innerClassCount = SegmentUtils.countMatches(classFlags, + innerClassLayout); + int[] classInnerClassesN = decodeBandInt("class_InnerClasses_N", in, + Codec.UNSIGNED5, innerClassCount); + int[][] classInnerClassesRC = decodeBandInt("class_InnerClasses_RC", in, Codec.UNSIGNED5, classInnerClassesN); + int[][] classInnerClassesF = decodeBandInt("class_InnerClasses_F", in, Codec.UNSIGNED5, classInnerClassesN); + int flagsCount = 0; + for (int i = 0; i < classInnerClassesF.length; i++) { + for (int j = 0; j < classInnerClassesF[i].length; j++) { + if(classInnerClassesF[i][j] != 0) { + flagsCount++; + } + } + } + int[] classInnerClassesOuterRCN = decodeBandInt("class_InnerClasses_outer_RCN", in, Codec.UNSIGNED5, flagsCount); + int[] classInnerClassesNameRUN = decodeBandInt("class_InnerClasses_name_RUN", in, Codec.UNSIGNED5, flagsCount); + + + AttributeLayout versionLayout = attrMap.getAttributeLayout( + AttributeLayout.ATTRIBUTE_CLASS_FILE_VERSION, + AttributeLayout.CONTEXT_CLASS); + int versionCount = SegmentUtils.countMatches(classFlags, versionLayout); + int[] classFileVersionMinorH = decodeBandInt( + "class_file_version_minor_H", in, Codec.UNSIGNED5, versionCount); + int[] classFileVersionMajorH = decodeBandInt( + "class_file_version_major_H", in, Codec.UNSIGNED5, versionCount); + + + // Now process the attribute bands we have parsed + int sourceFileIndex = 0; + int enclosingMethodIndex = 0; + int signatureIndex = 0; + int innerClassIndex = 0; + int versionIndex = 0; + classAttributes = new ArrayList[classCount]; for (int i = 0; i < classCount; i++) { + classAttributes[i] = new ArrayList(); long flag = classFlags[i]; - if (layout.matches(flag)) { + if (sourceFileLayout.matches(flag)) { + long result = classSourceFile[sourceFileIndex]; // we've got a value to read // TODO File this as a sourcefile attribute and don't generate // everything below - long result = layout.getCodec().decode(in); - Object value = layout.getValue(result, cpBands + Object value = sourceFileLayout.getValue(result, cpBands .getConstantPool()); debug("Processed value " + value + " for SourceFile"); + sourceFileIndex++; + } + if(enclosingMethodLayout.matches(flag)) { + // TODO + } + if(signatureLayout.matches(flag)) { +// TODO + } + if(innerClassLayout.matches(flag)) { + // TODO + } + if(versionLayout.matches(flag)) { + // TODO } } - debug("unimplemented class_EnclosingMethod_RC"); - debug("unimplemented class_EnclosingMethod_RDN"); - debug("unimplemented class_Signature_RS"); - parseClassMetadataBands(); - debug("unimplemented class_InnerClasses_N"); - debug("unimplemented class_InnerClasses_RC"); - debug("unimplemented class_InnerClasses_F"); - debug("unimplemented class_InnerClasses_outer_RCN"); - debug("unimplemented class_InnerClasses_inner_RCN"); - debug("unimplemented class_file_version_minor_H"); - debug("unimplemented class_file_version_major_H"); } + private void parseCodeBands(InputStream in) throws Pack200Exception, IOException { AttributeLayout layout = attrMap.getAttributeLayout( AttributeLayout.ATTRIBUTE_CODE, AttributeLayout.CONTEXT_METHOD); - int codeBands = SegmentUtils.countMatches(methodFlags, layout); + int codeCount = SegmentUtils.countMatches(methodFlags, layout); int[] codeHeaders = decodeBandInt("code_headers", in, Codec.BYTE1, - codeBands); + codeCount); int codeSpecialHeader = 0; - for (int i = 0; i < codeBands; i++) { + for (int i = 0; i < codeCount; i++) { if (codeHeaders[i] == 0) codeSpecialHeader++; } @@ -374,11 +459,11 @@ int[] codeHandlerCountSpecials = decodeBandInt("code_handler_count", in, Codec.UNSIGNED5, codeSpecialHeader); - codeMaxStack = new int[codeBands]; - codeMaxNALocals = new int[codeBands]; - codeHandlerCount = new int[codeBands]; + codeMaxStack = new int[codeCount]; + codeMaxNALocals = new int[codeCount]; + codeHandlerCount = new int[codeCount]; int special = 0; - for (int i = 0; i < codeBands; i++) { + for (int i = 0; i < codeCount; i++) { int header = 0xff & codeHeaders[i]; if (header < 0) { throw new IllegalStateException("Shouldn't get here"); @@ -403,26 +488,44 @@ throw new IllegalStateException("Shouldn't get here either"); } } + int sumCodeHandlerCount = 0; + for (int i = 0; i < codeHandlerCount.length; i++) { + sumCodeHandlerCount+= codeHandlerCount[i]; + } + int[] codeHandlerStartP = decodeBandInt("code_handler_start_P", in, Codec.BCI5, sumCodeHandlerCount); + int[] codeHandlerEndPO = decodeBandInt("code_handler_end_PO", in, Codec.BRANCH5, sumCodeHandlerCount); + int[] codeHandlerCatchPO = decodeBandInt("code_handler_catch_PO", in, Codec.BRANCH5, sumCodeHandlerCount); + int[] codeHandlerClassRCN = decodeBandInt("code_handler_class_RCN", in, Codec.UNSIGNED5, sumCodeHandlerCount); + int codeFlagsCount = segment.getSegmentHeader().getOptions().hasAllCodeFlags() ? - codeBands : codeSpecialHeader; + codeCount : codeSpecialHeader; parseCodeAttrBands(in, codeFlagsCount); } private void parseCodeAttrBands(InputStream in, int codeFlagsCount) throws IOException, Pack200Exception { long[] codeFlags = parseFlags("code_flags", in, codeFlagsCount, Codec.UNSIGNED5, segment.getSegmentHeader().getOptions().hasCodeFlagsHi()); + int codeAttrCount = 0; for (int i = 0; i < codeFlagsCount; i++) { long flag = codeFlags[i]; if ((flag & (1 << 16)) != 0) codeAttrCount++; } - if (codeAttrCount > 0) - throw new Error( - "There are attribute flags, and I don't know what to do with them"); - debug("unimplemented code_attr_count"); - debug("unimplemented code_attr_indexes"); - debug("unimplemented code_attr_calls"); - + System.out.println("codeAttrCount = " + codeAttrCount); + int[] codeAttrCounts = decodeBandInt("code_attr_count", in, Codec.UNSIGNED5, codeAttrCount); + int[][] codeAttrIndexes = decodeBandInt("code_attr_indexes", in, Codec.UNSIGNED5, codeAttrCounts); + int callCount = 0; + for (int i = 0; i < codeAttrIndexes.length; i++) { + for (int j = 0; j < codeAttrIndexes[i].length; j++) { + int index = codeAttrIndexes[i][j]; + AttributeLayout layout = attrMap.getAttributeLayout(index, AttributeLayout.CONTEXT_CODE); + callCount += layout.numBackwardsCallables(); + } + } + System.out.println("callCount = " + callCount); + int[] codeAttrCalls = decodeBandInt("code_attr_calls", in, Codec.UNSIGNED5, callCount); + int lineNumberTableCount = SegmentUtils.countMatches(codeFlags, attrMap.getAttributeLayout(AttributeLayout.ATTRIBUTE_LINE_NUMBER_TABLE, AttributeLayout.CONTEXT_CODE)); + System.out.println("lineNumberTables = " + lineNumberTableCount); int[] lineNumberTableN = decodeBandInt("code_LineNumberTable_N", in, Codec.UNSIGNED5, lineNumberTableCount); int[][] lineNumberTableBciP = decodeBandInt("code_LineNumberTable_bci_P", in, Codec.BCI5, lineNumberTableN); int[][] lineNumberTableLine = decodeBandInt("code_LineNumberTable_line", in, Codec.UNSIGNED5, lineNumberTableN); @@ -430,6 +533,8 @@ for (int i = 0; i < types.length; i++) { String type = types[i]; int lengthNBand = SegmentUtils.countMatches(codeFlags, attrMap.getAttributeLayout(type, AttributeLayout.CONTEXT_CODE)); + System.out.println(type + " count = " + lengthNBand); + int[] nBand = decodeBandInt("code_" + type + "_N", in, Codec.UNSIGNED5, lengthNBand); int[][] bciP = decodeBandInt("code_" + type + "_bci_P", in, Codec.BCI5, nBand); int[][] spanO = decodeBandInt("code_" + type + "_span_O", in, Codec.BRANCH5, nBand); @@ -597,10 +702,6 @@ } } - public int getClassAttrCount() { - return classAttrCount; - } - public int[] getClassFieldCount() { return classFieldCount; } @@ -647,10 +748,6 @@ public long[][] getFieldFlags() { return fieldFlags; - } - - public int getMethodAttrCount() { - return methodAttrCount; } public ArrayList[][] getMethodAttributes() { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.IOException; import java.io.InputStream; @@ -95,9 +93,6 @@ * by the Pack200 specification, which allow a codec to be referred to by * canonical number. TODO Add links to canonical numbers when this has been * done. - * - * @author Alex Blewitt - * @version $Revision: $ */ public abstract class Codec { /** @@ -129,7 +124,7 @@ public static final BHSDCodec DELTA5 = new BHSDCodec(5, 64, 1, 1); /** - * DELTA5 = (5,64,2,1): Used for the majority of numerical codings where + * MDELTA5 = (5,64,2,1): Used for the majority of numerical codings where * there is a correlated sequence of signed values, but where most of them * are expected to be non-negative. */ @@ -147,7 +142,7 @@ public static final BHSDCodec UDELTA5 = new BHSDCodec(5, 64, 0, 1); /** - * USIGNED5 = (5,64): Used for small unsigned values. + * UNSIGNED5 = (5,64): Used for small unsigned values. */ public static final BHSDCodec UNSIGNED5 = new BHSDCodec(5, 64); Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CodecEncoding.java Thu Oct 25 07:44:56 2007 @@ -15,20 +15,19 @@ * limitations under the License. */ package org.apache.harmony.pack200; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.EOFException; import java.io.IOException; import java.io.InputStream; public class CodecEncoding { + /** * The canonical encodings are defined to allow a single byte to represent * one of the standard encodings. The following values are defined in the * Pack200 specification, and this array cannot be changed. */ - private static Codec[] canonicalCodec = { null, new BHSDCodec(1, 256), + private static final Codec[] canonicalCodec = { null, new BHSDCodec(1, 256), new BHSDCodec(1, 256, 1), new BHSDCodec(1, 256, 0, 1), new BHSDCodec(1, 256, 1, 1), new BHSDCodec(2, 256), new BHSDCodec(2, 256, 1), new BHSDCodec(2, 256, 0, 1), @@ -100,7 +99,7 @@ * @throws Pack200Exception */ public static Codec getCodec(int value, InputStream in, Codec defaultCodec) throws IOException, Pack200Exception { - // Sanity check to make sure that no-one's been buggering with + // Sanity check to make sure that no-one has changed // the canonical codecs, which would really cause havoc if (canonicalCodec.length != 116) throw new Error("Canonical encodings have been incorrectly modified"); Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java Thu Oct 25 07:44:56 2007 @@ -209,8 +209,8 @@ private void parseCpLong(InputStream in) throws IOException, Pack200Exception { int cpLongCount = header.getCpLongCount(); - cpLong = parseFlags("cp_Long", in, cpLongCount, new int[] { 1 }, - Codec.UDELTA5, Codec.DELTA5)[0]; + cpLong = parseFlags("cp_Long", in, cpLongCount, + Codec.UDELTA5, Codec.DELTA5); } /** @@ -262,7 +262,18 @@ String[] cpSignatureForm = parseReferences("cp_Signature_form", in, Codec.DELTA5, cpSignatureCount, cpUTF8); cpSignature = new String[cpSignatureCount]; - long last = 0; + int lCount = 0; + for (int i = 0; i < cpSignatureCount; i++) { + String form = cpSignatureForm[i]; + char[] chars = form.toCharArray(); + for (int j = 0; j < chars.length; j++) { + if(chars[j] == 'L') { + lCount++; + } + } + } + String[] cpSignatureClasses = parseReferences("cp_Signature_classes", in, Codec.UDELTA5, lCount, cpClass); + int index = 0; for (int i = 0; i < cpSignatureCount; i++) { String form = cpSignatureForm[i]; int len = form.length(); @@ -272,10 +283,10 @@ char c = form.charAt(j); signature.append(c); if (c == 'L') { - int index = (int) (last = Codec.UDELTA5.decode(in, last)); - String className = cpClass[index]; + String className = cpSignatureClasses[index]; list.add(className); signature.append(className); + index++; } } cpSignature[i] = signature.toString(); Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java Thu Oct 25 07:44:56 2007 @@ -67,42 +67,22 @@ Pack200Exception { int numberOfFiles = header.getNumberOfFiles(); SegmentOptions options = header.getOptions(); - if (false && System.getProperty("debug.pack200") != null) { - // TODO HACK - fileSize = new long[numberOfFiles]; - fileModtime = new long[numberOfFiles]; - fileOptions = new long[numberOfFiles]; - fileName = new String[numberOfFiles]; - Arrays.fill(fileName, ""); - return; - } - long last; + fileName = parseReferences("file_name", in, Codec.UNSIGNED5, numberOfFiles, cpUTF8); - fileSize = new long[numberOfFiles]; - if (options.hasFileSizeHi()) { - last = 0; - for (int i = 0; i < numberOfFiles; i++) { - fileSize[i] = (last = Codec.UNSIGNED5.decode(in, last)) << 32; - } - } - last = 0; - for (int i = 0; i < numberOfFiles; i++) { - fileSize[i] |= (last = Codec.UNSIGNED5.decode(in, last)); - } - fileModtime = new long[numberOfFiles]; + fileSize = parseFlags("file_size", in, numberOfFiles, Codec.UNSIGNED5, + options.hasFileSizeHi()); if (options.hasFileModtime()) { - last = 0; - for (int i = 0; i < numberOfFiles; i++) { - fileModtime[i] |= (last = Codec.DELTA5.decode(in, last)); - } + fileModtime = decodeBandLong("file_modtime", in, Codec.DELTA5, + numberOfFiles); + } else { + fileModtime = new long[numberOfFiles]; } - fileOptions = new long[numberOfFiles]; if (options.hasFileOptions()) { - last = 0; - for (int i = 0; i < numberOfFiles; i++) { - fileOptions[i] |= (last = Codec.UNSIGNED5.decode(in, last)); - } + fileOptions = decodeBandLong("file_options", in, Codec.UNSIGNED5, + numberOfFiles); + } else { + fileOptions = new long[numberOfFiles]; } } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java Thu Oct 25 07:44:56 2007 @@ -62,12 +62,9 @@ int innerClassCount = header.getInnerClassCount(); icThisClass = parseReferences("ic_this_class", in, Codec.UDELTA5, innerClassCount, cpClass); - icFlags = new int[innerClassCount]; - long last = 0; + icFlags = decodeBandInt("ic_flags", in, Codec.UNSIGNED5, innerClassCount); int outerClasses = 0; - // ic_flags for (int i = 0; i < innerClassCount; i++) { - icFlags[i] = (int) (last = Codec.UNSIGNED5.decode(in, last)); if ((icFlags[i] & 1 << 16) != 0) outerClasses++; } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java Thu Oct 25 07:44:56 2007 @@ -15,14 +15,9 @@ * limitations under the License. */ package org.apache.harmony.pack200; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + /** * Represents a problem with a Pack200 coding/decoding issue. - * - * @author Alex Blewitt - * @version $Revision: $ */ public class Pack200Exception extends Exception { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.IOException; import java.io.InputStream; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/RunCodec.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.IOException; import java.io.InputStream; @@ -26,9 +24,6 @@ * the first codec, and the remaining codes are decoded from the remaining * codec. Note that since this codec maintains state, the instances are * not reusable. - * - * @author Alex Blewitt - * @version $Revision: $ */ public class RunCodec extends Codec { private int k; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Thu Oct 25 07:44:56 2007 @@ -16,10 +16,6 @@ */ package org.apache.harmony.pack200; -// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -// NOTE: Do not extract strings as messages; this code is still a -// work-in-progress -// NOTE: Also, don't get rid of 'else' statements for the hell of it ... import java.io.BufferedInputStream; import java.io.DataOutputStream; import java.io.IOException; @@ -64,9 +60,6 @@ * In any case, if GZip decompression is being performed the input stream will * be buffered at a higher level, and thus this can read on a byte-oriented * basis. - * - * @author Alex Blewitt - * @version $Revision: $ */ public class Segment { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentOptions.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentOptions.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentOptions.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentOptions.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + /** * Stores the combinations of bit flags that can be used in the segment header * options. Whilst this could be defined in {@link Segment}, it's cleaner to @@ -25,9 +23,6 @@ * to determine the semantic meaning of the flags. In languages with a * pre-processor, these may be defined by macros that do bitflag manipulation * instead. - * - * @author Alex Blewitt - * @version $Revision: $ */ public class SegmentOptions { private static final int DEFLATE_HINT = 1 << 5; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java Thu Oct 25 07:44:56 2007 @@ -16,10 +16,6 @@ */ package org.apache.harmony.pack200.bytecode; -// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -// NOTE: Do not extract strings as messages; this code is still a -// work-in-progress -// NOTE: Also, don't get rid of 'else' statements for the hell of it ... import java.util.ArrayList; import java.util.Iterator; import java.util.List; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFile.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200.bytecode; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.DataOutputStream; import java.io.IOException; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java Thu Oct 25 07:44:56 2007 @@ -16,10 +16,6 @@ */ package org.apache.harmony.pack200.bytecode; -// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -// NOTE: Do not extract strings as messages; this code is still a -// work-in-progress -// NOTE: Also, don't get rid of 'else' statements for the hell of it ... import java.io.DataOutputStream; import java.io.IOException; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java Thu Oct 25 07:44:56 2007 @@ -16,16 +16,10 @@ */ package org.apache.harmony.pack200.bytecode; -// NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -// NOTE: Do not extract strings as messages; this code is still a -// work-in-progress -// NOTE: Also, don't get rid of 'else' statements for the hell of it ... import java.io.DataOutputStream; import java.io.IOException; - /** - * @author alex * */ public abstract class ConstantPoolEntry extends ClassFileEntry { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutMapTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutMapTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutMapTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutMapTest.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200.tests; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import junit.framework.TestCase; import org.apache.harmony.pack200.AttributeLayout; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/AttributeLayoutTest.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200.tests; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import junit.framework.TestCase; import org.apache.harmony.pack200.AttributeLayout; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java Thu Oct 25 07:44:56 2007 @@ -26,18 +26,27 @@ import org.apache.harmony.pack200.BHSDCodec; import org.apache.harmony.pack200.BandSet; import org.apache.harmony.pack200.Codec; +import org.apache.harmony.pack200.CodecEncoding; import org.apache.harmony.pack200.Pack200Exception; import org.apache.harmony.pack200.Segment; +import org.apache.harmony.pack200.SegmentHeader; public class BandSetTest extends TestCase { - private BandSet bandSet = new BandSet(new Segment()) { + public class MockSegment extends Segment { + public SegmentHeader getSegmentHeader() { + return new SegmentHeader(); + } + } + + private BandSet bandSet = new BandSet(new MockSegment()) { public void pack(OutputStream outputStream) { } public void unpack(InputStream inputStream) throws IOException, Pack200Exception { } + }; public void testDecodeBandInt() throws IOException, Pack200Exception { @@ -52,13 +61,24 @@ public void testDecodeBandLong() throws IOException, Pack200Exception { BHSDCodec codec = Codec.BYTE1; - byte[] bytes = new byte[]{(byte)3,(byte)56,(byte)122,(byte)78, Byte.MAX_VALUE, Byte.MIN_VALUE}; + byte[] bytes = new byte[]{(byte)3,(byte)56,(byte)122,(byte)78, (byte)0, (byte)255}; InputStream in = new ByteArrayInputStream(bytes); - long[] longs = bandSet.decodeBandLong("Test Band", in, codec, 4); + long[] longs = bandSet.decodeBandLong("Test Band", in, codec, 6); for (int i = 0; i < longs.length; i++) { - assertEquals("Wrong value in position " + i, longs[i], bytes[i]); + assertEquals("Wrong value in position " + i, (byte)longs[i], bytes[i]); } //TODO: Should test this with other Codecs. + } + + public void testDecodeBandLong2() throws IOException, Pack200Exception { + + BHSDCodec codec = Codec.DELTA5; + byte[] bytes = new byte[]{3, 1, 2, 3, 4, 5}; // 3 is decoded to -2 by DELTA5, which signifies a switch to BYTE1 + InputStream in = new ByteArrayInputStream(bytes); + long[] longs = bandSet.decodeBandLong("Test Band", in, codec, 5); + for (int i = 0; i < longs.length; i++) { + assertEquals("Wrong value in position " + i, longs[i], bytes[i + 1]); + } } public void testParseFlags1() { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java Thu Oct 25 07:44:56 2007 @@ -43,17 +43,7 @@ * should be replaced with properly encoded byte arrays when encoding is * implemented. */ -public class BcBandsTest extends TestCase { - - - private int numClasses = 1; - private int[] numMethods = {1}; - - public class MockSegmentHeader extends SegmentHeader { - public int getClassCount() { - return numClasses; - } - } +public class BcBandsTest extends AbstractBandsTestCase { public class MockClassBands extends ClassBands { public MockClassBands(Segment segment) { @@ -107,26 +97,7 @@ } } - public class MockAttributeDefinitionBands extends AttrDefinitionBands { - - public MockAttributeDefinitionBands(Segment segment) { - super(segment); - } - - public AttributeLayoutMap getAttributeDefinitionMap() { - try { - return new AttributeLayoutMap(); - } catch (Pack200Exception e) { - fail(e.getLocalizedMessage()); - } - return null; - } - - - - } - - public class MockSegment extends Segment { + public class MockSegment extends AbstractBandsTestCase.MockSegment { protected AttrDefinitionBands getAttrDefinitionBands() { return new MockAttributeDefinitionBands(this); } @@ -137,10 +108,6 @@ protected ClassBands getClassBands() { return new MockClassBands(this); - } - - public SegmentHeader getSegmentHeader() { - return new MockSegmentHeader(); } } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecEncodingTest.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200.tests; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.HashMap; @@ -31,11 +29,11 @@ import org.apache.harmony.pack200.Pack200Exception; /** - * @author Alex Blewitt - * @version $Revision: $ + * */ public class CodecEncodingTest extends TestCase { - public void testCanonicalEncodings() throws IOException, Pack200Exception { + + public void testCanonicalEncodings() throws IOException, Pack200Exception { Codec defaultCodec = new BHSDCodec(2,16,0,0); assertEquals(defaultCodec,CodecEncoding.getCodec(0,null, defaultCodec)); Map map = new HashMap(); @@ -164,4 +162,5 @@ assertEquals("(5,128,2,1)",CodecEncoding.getCodec(116,new ByteArrayInputStream(new byte[] { 0x25, (byte)0x7F}), null).toString()); assertEquals("(2,128,1,1)",CodecEncoding.getCodec(116,new ByteArrayInputStream(new byte[] { 0x0B, (byte)0x7F}), null).toString()); } + } Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodecTest.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200.tests; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.ByteArrayInputStream; import java.io.EOFException; import java.io.IOException; @@ -31,8 +29,7 @@ /** - * @author Alex Blewitt - * @version $Revision: $ + * */ public class CodecTest extends TestCase { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/HelloWorld.java Thu Oct 25 07:44:56 2007 @@ -15,13 +15,9 @@ * limitations under the License. */ package org.apache.harmony.pack200.tests; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + /** * This is intended to be used as a test class for unpacking a packed Jar file. - * @author Alex Blewitt - * @version $Revision: $ */ public class HelloWorld { int i=97,j=42,k=12345; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/PopulationCodecTest.java Thu Oct 25 07:44:56 2007 @@ -15,9 +15,7 @@ * limitations under the License. */ package org.apache.harmony.pack200.tests; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentOptionsTest.java Thu Oct 25 07:44:56 2007 @@ -15,20 +15,18 @@ * limitations under the License. */ package org.apache.harmony.pack200.tests; -//NOTE: Do not use generics in this code; it needs to run on JVMs < 1.5 -//NOTE: Do not extract strings as messages; this code is still a work-in-progress -//NOTE: Also, don't get rid of 'else' statements for the hell of it ... + import junit.framework.TestCase; import org.apache.harmony.pack200.Pack200Exception; import org.apache.harmony.pack200.SegmentOptions; /** - * @author Alex Blewitt - * @version $Revision: $ + * */ public class SegmentOptionsTest extends TestCase { - public void testUnused() { + + public void testUnused() { int[] unused = new int[] { 3, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; for (int i = 0; i < unused.length; i++) { Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java (original) +++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentTest.java Thu Oct 25 07:44:56 2007 @@ -16,10 +16,15 @@ */ package org.apache.harmony.pack200.tests; -import org.apache.harmony.pack200.Segment; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.jar.JarOutputStream; import junit.framework.TestCase; +import org.apache.harmony.pack200.Segment; + /** * Tests for org.apache.harmony.pack200.Segment, which is the main class for pack200. */ @@ -31,9 +36,11 @@ } public void testJustResources() throws Exception { - assertNotNull(Segment - .parse(Segment.class - .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack"))); + InputStream in = Segment.class + .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack"); + Segment segment = Segment.parse(in); + assertNotNull(segment); + segment.writeJar(new JarOutputStream(new FileOutputStream(File.createTempFile("just", "Resources.jar"))), in); } public void testJustResourcesGZip() throws Exception { @@ -41,11 +48,28 @@ .parse(Segment.class .getResourceAsStream("/org/apache/harmony/pack200/tests/JustResources.pack.gz"))); } - + + // Test with an archive containing Harmony's SQL module, packed with -E1 + public void testWithSqlE1() throws Exception { + assertNotNull(Segment + .parse(Segment.class + .getResourceAsStream("/org/apache/harmony/pack200/tests/sql-e1.pack.gz"))); + + } + + // Test with an archive containing Harmony's Pack200 module, packed with -E1 + public void testWithPack200E1() throws Exception { + assertNotNull(Segment + .parse(Segment.class + .getResourceAsStream("/org/apache/harmony/pack200/tests/pack200-e1.pack.gz"))); + + } + public void testInterfaceOnly() throws Exception { assertNotNull(Segment .parse(Segment.class .getResourceAsStream("/org/apache/harmony/pack200/tests/InterfaceOnly.pack"))); } + } Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/build.xml URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/build.xml?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/build.xml (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/build.xml Thu Oct 25 07:44:56 2007 @@ -60,6 +60,12 @@ + + + + + + @@ -174,6 +180,12 @@ + + + + + + Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/iohelp.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/iohelp.c?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/iohelp.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/iohelp.c Thu Oct 25 07:44:56 2007 @@ -19,8 +19,6 @@ #include "exceptions.h" #include "jclglob.h" -jfieldID getJavaIoFileDescriptorDescriptorFID (JNIEnv * env); - /** * This will convert all separators to the proper platform separator * and remove duplicates on non POSIX platforms. @@ -71,390 +69,4 @@ } /* This will have to handle extra \'s but currently doesn't */ -} - -/** - * This will write count bytes from buffer starting at offset - */ -void -ioh_writebytesImpl (JNIEnv * env, jobject recv, jbyteArray buffer, - jint offset, jint count, IDATA descriptor) -{ - I_32 result = 0; - jbyte *buf; - PORT_ACCESS_FROM_ENV (env); - jsize len; - char *errorMessage = NULL; - -/* TODO: ARRAY PINNING */ -#define INTERNAL_MAX 512 - jbyte internalBuffer[INTERNAL_MAX]; - - if (buffer == NULL) - { - throwNPException (env, "buffer is null"); - return; - } - - len = (*env)->GetArrayLength (env, buffer); - - /** - * If offset is negative, or count is negative, or offset+count is greater - * than the length of the array b, then an IndexOutOfBoundsException is thrown. - * Must test offset > len, or len - offset < count to avoid int overflow caused - * by offset + count - */ - if (offset < 0 || count < 0 || offset > len || (len - offset) < count) - { - throwIndexOutOfBoundsException (env); - return; - } - - /* If len or count is zero, just return 0 */ - if (len == 0 || count == 0) - return; - - if (descriptor == -1) - { - throwJavaIoIOExceptionClosed (env); - return; - } - if (count > INTERNAL_MAX) - { - buf = jclmem_allocate_memory (env, count); - } - else - { - buf = internalBuffer; - } - - if (buf == NULL) - { - throwNewOutOfMemoryError (env, ""); - return; - } - ((*env)->GetByteArrayRegion (env, buffer, offset, count, buf)); - - result = hyfile_write (descriptor, buf, count); - - /** - * if there is an error, find the error message before calling free in case - * hymem_free_memory changes the error code - */ - if (result < 0) - errorMessage = ioLookupErrorString (env, result); - - if (buf != internalBuffer) - { - jclmem_free_memory (env, buf); - } -#undef INTERNAL_MAX - - if (result < 0) - throwJavaIoIOException (env, errorMessage); -} - -/** - * This will write one byte - */ -void -ioh_writecharImpl (JNIEnv * env, jobject recv, jint c, IDATA descriptor) -{ - I_32 result = 0; - char buf[1]; - PORT_ACCESS_FROM_ENV (env); - - if (descriptor == -1) - { - throwJavaIoIOExceptionClosed (env); - return; - } - - buf[0] = (char) c; - - result = hyfile_write (descriptor, buf, 1); - - if (result < 0) - throwJavaIoIOException (env, ioLookupErrorString (env, result)); -} - -/** - * This will read a single character from the descriptor - */ -jint -ioh_readcharImpl (JNIEnv * env, jobject recv, IDATA descriptor) -{ - I_32 result; - char buf[1]; - PORT_ACCESS_FROM_ENV (env); - - if (descriptor == -1) - { - throwJavaIoIOExceptionClosed (env); - return 0; - } - - if (descriptor == 0) - { - result = hytty_get_chars (buf, 1); - } - else - { - result = hyfile_read (descriptor, buf, 1); - } - - if (result <= 0) - return -1; - - return (jint) buf[0] & 0xFF; -} - -/** - * This will read a up to count bytes into buffer starting at offset - */ -jint -ioh_readbytesImpl (JNIEnv * env, jobject recv, jbyteArray buffer, jint offset, - jint count, IDATA descriptor) -{ - I_32 result; - jsize len; - jbyte *buf; - -/* TODO: ARRAY PINNING */ -#define INTERNAL_MAX 2048 - jbyte internalBuffer[INTERNAL_MAX]; - - PORT_ACCESS_FROM_ENV (env); - - if (buffer == NULL) - { - throwNPException (env, "buffer is null"); - return 0; - } - - len = (*env)->GetArrayLength (env, buffer); - /** - * Throw IndexOutOfBoundsException according to spec. - * Must test offset > len, or len - offset < count to avoid - * int overflow caused by offset + count - */ - if (offset < 0 || count < 0 || offset > len || (len - offset) < count) - { - throwIndexOutOfBoundsException (env); - return 0; - } - /* If len is 0, simply return 0 (even if it is closed) */ - if (len == 0 || count == 0) - return 0; - - if (descriptor == -1) - { - throwJavaIoIOExceptionClosed (env); - return 0; - } - if (len >= INTERNAL_MAX) - { - buf = jclmem_allocate_memory (env, len); - } - else - { - buf = internalBuffer; - } - - if (buf == NULL) - { - throwNewOutOfMemoryError (env, ""); - return 0; - } - /* Must FREE buffer before returning */ - - if (descriptor == 0) - { - /* hytty_get_chars() returns zero on EOF */ - if ((result = hytty_get_chars (buf, count)) == 0) - result = -1; - } - else - { - result = hyfile_read (descriptor, buf, count); - } - if (result > 0) - (*env)->SetByteArrayRegion (env, buffer, offset, result, buf); - - if (buf != internalBuffer) - { - jclmem_free_memory (env, buf); - } -#undef INTERNAL_MAX - - return result; -} - -/** - * This will return the number of chars left in the file - */ -jint -new_ioh_available (JNIEnv * env, jobject recv, jfieldID fdFID) -{ - jobject fd; - I_64 currentPosition, endOfFile; - IDATA descriptor; - PORT_ACCESS_FROM_ENV (env); - - /* fetch the fd field from the object */ - fd = (*env)->GetObjectField (env, recv, fdFID); - - /* dereference the C pointer from the wrapper object */ - descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd); - if (descriptor == -1) - { - throwJavaIoIOExceptionClosed (env); - return -1; - } - /** - * If the descriptor represents StdIn, call the hytty port library. - */ - if (descriptor == 0) - { - return hytty_available (); - } - currentPosition = hyfile_seek (descriptor, 0, HySeekCur); - endOfFile = hyfile_seek (descriptor, 0, HySeekEnd); - hyfile_seek (descriptor, currentPosition, HySeekSet); - return (jint) (endOfFile - currentPosition); -} - -/** - * This will close a file descriptor - */ -void -new_ioh_close (JNIEnv * env, jobject recv, jfieldID fdFID) -{ - jobject fd; - jfieldID descriptorFID; - IDATA descriptor; - PORT_ACCESS_FROM_ENV (env); - - descriptorFID = getJavaIoFileDescriptorDescriptorFID (env); - if (NULL == descriptorFID) - { - return; - } - - /* fetch the fd field from the object */ - fd = (*env)->GetObjectField (env, recv, fdFID); - - /* dereference the C pointer from the wrapper object */ - descriptor = (IDATA) getJavaIoFileDescriptorContentsAsPointer (env, fd); - - /* Check for closed file, in, out, and err */ - if (descriptor >= -1 && descriptor <= 2) - { - return; - } - - hyfile_close (descriptor); - setJavaIoFileDescriptorContentsAsPointer (env, fd, (void *) -1); - return; -} - -/** - * This will retrieve the 'descriptor' field value from a java.io.FileDescriptor - */ -void * -getJavaIoFileDescriptorContentsAsPointer (JNIEnv * env, jobject fd) -{ - jfieldID descriptorFID = getJavaIoFileDescriptorDescriptorFID (env); - if (NULL == descriptorFID) - { - return (void *) -1; - } - return (void *)(IDATA) ((*env)->GetLongField (env, fd, descriptorFID)); -} - -/** - * This will set the 'descriptor' field value in the java.io.FileDescriptor - * @fd to the value @desc - */ -void -setJavaIoFileDescriptorContentsAsPointer (JNIEnv * env, jobject fd, - void *value) -{ - jfieldID fid = getJavaIoFileDescriptorDescriptorFID (env); - if (NULL != fid) - { - (*env)->SetLongField (env, fd, fid, (IDATA)value); - } -} - -/** - * Answer the errorString corresponding to the errorNumber, if available. - * This function will answer a default error string, if the errorNumber is not - * recognized. - * - * This function will have to be reworked to handle internationalization properly, removing - * the explicit strings. - * - * @param anErrorNum the error code to resolve to a human readable string - * - * @return a human readable error string - */ - -char * -ioLookupErrorString (JNIEnv * env, I_32 anErrorNum) -{ - PORT_ACCESS_FROM_ENV (env); - switch (anErrorNum) - { - case HYPORT_ERROR_FILE_NOTFOUND: - return "File not found"; - case HYPORT_ERROR_FILE_NOPERMISSION: - return "Lacking proper permissions to perform the operation"; - case HYPORT_ERROR_FILE_DISKFULL: - return "Disk is full"; - case HYPORT_ERROR_FILE_NOENT: - return "A component of the path name does not exist"; - case HYPORT_ERROR_FILE_NOTDIR: - return "A component of the path name is not a directory"; - case HYPORT_ERROR_FILE_BADF: - return "File descriptor invalid"; - case HYPORT_ERROR_FILE_EXIST: - return "File already exists"; - case HYPORT_ERROR_FILE_INVAL: - return "A parameter is invalid"; - case HYPORT_ERROR_FILE_LOOP: - return "Followed too many symbolic links, possibly stuck in loop"; - case HYPORT_ERROR_FILE_NAMETOOLONG: - return "Filename exceeds maximum length"; - default: - return (char *) hyfile_error_message (); - } -} - -/** - * This will retrieve the 'descriptor' field value from a java.io.FileDescriptor - */ -jfieldID -getJavaIoFileDescriptorDescriptorFID (JNIEnv * env) -{ - jclass descriptorCLS; - jfieldID descriptorFID; - - descriptorFID = JCL_CACHE_GET (env, FID_java_io_FileDescriptor_descriptor); - if (NULL != descriptorFID) - { - return descriptorFID; - } - descriptorCLS = (*env)->FindClass (env, "java/io/FileDescriptor"); - if (NULL == descriptorCLS) - { - return NULL; - } - descriptorFID = (*env)->GetFieldID (env, descriptorCLS, "descriptor", "J"); - if (NULL == descriptorFID) - { - return NULL; - } - JCL_CACHE_SET (env, FID_java_io_FileDescriptor_descriptor, descriptorFID); - return descriptorFID; } Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/jclglob.h URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/jclglob.h?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/jclglob.h (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/common/shared/jclglob.h Thu Oct 25 07:44:56 2007 @@ -22,8 +22,6 @@ #define JCL_ID_CACHE Lib_JCL_ID_CACHE typedef struct LibJniIDCache { - - jfieldID FID_java_io_FileDescriptor_descriptor; int attachCount; } LibJniIDCache; #define JniIDCache LibJniIDCache Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hynls.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hynls.c?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hynls.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hynls.c Thu Oct 25 07:44:56 2007 @@ -540,7 +540,7 @@ portLibrary->portGlobals->nls_data.catalogues[position++] = add_catalog; portLibrary->file_close (portLibrary, fd); #if defined(NLS_DEBUG) - portLibrary->tty_printf (portLibrary, "NLS - succesfully opened %s\n", catalog); + portLibrary->tty_printf (portLibrary, "NLS - successfully opened %s\n", catalog); #endif successfully_opened = 1; fd = -1; Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.c?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.c Thu Oct 25 07:44:56 2007 @@ -590,7 +590,7 @@ { char *endPathPtr = NULL; char *launcherName = NULL; - char **pathSet = portLib->mem_allocate_memory (portLib, sizeof(char*)*2); + const char **pathSet = portLib->mem_allocate_memory (portLib, sizeof(char*)*2); char *vmPath = NULL; hysysinfo_get_executable_name (portLib, NULL, &launcherName); @@ -616,7 +616,7 @@ portLib->nls_set_catalog (portLib, pathSet, 2, "harmony", "properties"); // Free memory for launcherName -- necessary ?? portLib->mem_free_memory (portLib, launcherName); - portLib->mem_free_memory (portLib, pathSet); + portLib->mem_free_memory (portLib, (void*) pathSet); portLib->mem_free_memory (portLib, vmPath); } } Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.nls URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.nls?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.nls (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hyport.nls Thu Oct 25 07:44:56 2007 @@ -24,7 +24,7 @@ # Note to translators: # # This file uses printf style substitutions. Sequences such as %s, %.*s, %10d -# etc. will be subsituted at runtime. The special case of %% is not a substitution. +# etc. will be substituted at runtime. The special case of %% is not a substitution. # It indicates a single percent sign. Please do not modify the format specifiers, or # change their order. For instance, in a message like "from %d to %s", %d # MUST appear before %s in any translated message, or a run-time crash Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hystr.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hystr.c?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hystr.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/shared/hystr.c Thu Oct 25 07:44:56 2007 @@ -29,6 +29,7 @@ #include "hycomp.h" #include "hyport.h" +#include "utf8encode.h" #define HYFTYPE_U64 1 #define HYFTYPE_U32 2 @@ -81,8 +82,6 @@ static const char digits_hex_lower[] = "0123456789abcdef"; static const char digits_hex_upper[] = "0123456789ABCDEF"; -extern U_32 encodeUTF8Char (UDATA unicode, U_8 * result); - static const char *parseTagChar (const char *format, HyFormatData * result); static void readValues (struct HyPortLibrary *portLibrary, HyFormatData * result, va_list args); @@ -111,7 +110,7 @@ U_8 tag); /** - * Write characaters to a string as specified by format. + * Write characters to a string as specified by format. * * @param[in] portLibrary The port library. * @param[in, out] buf The string buffer to be written. @@ -138,7 +137,7 @@ } /** - * Write characaters to a string as specified by format. + * Write characters to a string as specified by format. * * @param[in] portLibrary The port library. * @param[in, out] buf The string buffer to be written. Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hyfiletext.c URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hyfiletext.c?rev=588245&r1=588244&r2=588245&view=diff ============================================================================== --- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hyfiletext.c (original) +++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hyfiletext.c Thu Oct 25 07:44:56 2007 @@ -62,8 +62,7 @@ #endif /* HYVM_USE_ICONV (autogen) */ #if (defined(HYVM_USE_WCTOMB)) -U_32 decodeUTF8CharN (const U_8 * input, U_16 * result, U_32 bytesRemaining); -U_32 decodeUTF8Char (const U_8 * input, U_16 * result); +#include "utf8decode.h" #endif #if (defined(HYVM_USE_WCTOMB))