Skip to content

Commit

Permalink
Fix line ending, update corpus test
Browse files Browse the repository at this point in the history
  • Loading branch information
liach committed Sep 20, 2023
1 parent 0dbf9ec commit c3429f6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.classfile.impl;

import jdk.internal.classfile.BufWriter;
import jdk.internal.classfile.Label;
import jdk.internal.classfile.constantpool.Utf8Entry;

/**
* Utilities for writing logic shared for attributes that are streamable.
*/
public final class AttributeHelpers {
private AttributeHelpers() {
}

public static boolean writeLocalVariable(LabelContext lc, BufWriter b, Label start, Label end,
Utf8Entry name, Utf8Entry type, int slot) {
int startBci = lc.labelToBci(start);
int endBci = lc.labelToBci(end);
if (startBci == -1 || endBci == -1) {
return false;
}
writeLocalVariableInfo(b, startBci, endBci - startBci, name, type, slot);
return true;
}

public static void writeLocalVariableInfo(BufWriter b, int startPc, int length,
Utf8Entry name, Utf8Entry type, int slot) {
b.writeU2(startPc);
b.writeU2(length);
b.writeIndex(name);
b.writeIndex(type);
b.writeU2(slot);
}
}
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.internal.classfile.impl;

import jdk.internal.classfile.BufWriter;
import jdk.internal.classfile.Label;
import jdk.internal.classfile.constantpool.Utf8Entry;

/**
* Utilities for writing logic shared for attributes that are streamable.
*/
public final class AttributeHelpers {
private AttributeHelpers() {
}

public static boolean writeLocalVariable(LabelContext lc, BufWriter b, Label start, Label end,
Utf8Entry name, Utf8Entry type, int slot) {
int startBci = lc.labelToBci(start);
int endBci = lc.labelToBci(end);
if (startBci == -1 || endBci == -1) {
return false;
}
writeLocalVariableInfo(b, startBci, endBci - startBci, name, type, slot);
return true;
}

public static void writeLocalVariableInfo(BufWriter b, int startPc, int length,
Utf8Entry name, Utf8Entry type, int slot) {
b.writeU2(startPc);
b.writeU2(length);
b.writeIndex(name);
b.writeIndex(type);
b.writeU2(slot);
}
}
39 changes: 19 additions & 20 deletions test/jdk/jdk/classfile/CorpusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import helpers.ClassRecord;
import helpers.ClassRecord.CompatibilityFilter;
import helpers.Transforms;
import jdk.internal.classfile.impl.AttributeHelpers;
import jdk.internal.classfile.impl.BufWriterImpl;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

import java.io.ByteArrayInputStream;
import java.util.*;

import static helpers.ClassRecord.assertEqualsDeep;
Expand All @@ -58,7 +58,6 @@
import jdk.internal.classfile.Classfile;
import jdk.internal.classfile.ClassTransform;
import jdk.internal.classfile.CodeTransform;
import jdk.internal.classfile.constantpool.ConstantPool;
import jdk.internal.classfile.constantpool.PoolEntry;
import jdk.internal.classfile.constantpool.Utf8Entry;
import jdk.internal.classfile.impl.DirectCodeBuilder;
Expand Down Expand Up @@ -95,30 +94,30 @@ public void writeBody(BufWriter b) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(1);
var lc = ((BufWriterImpl) b).labelContext();
int startBci = lc.labelToBci(lv.startScope());
int endBci = lc.labelToBci(lv.endScope());
int length = endBci - startBci;
b.writeU2(startBci);
b.writeU2(length);
b.writeIndex(lv.name());
b.writeIndex(lv.type());
b.writeU2(lv.slot());
AttributeHelpers.writeLocalVariable(
((BufWriterImpl) b).labelContext(),
b,
lv.startScope(),
lv.endScope(),
lv.name(),
lv.type(),
lv.slot()
);
}
});
case LocalVariableType lvt -> dcob.writeAttribute(new UnboundAttribute.AdHocAttribute<>(Attributes.LOCAL_VARIABLE_TYPE_TABLE) {
@Override
public void writeBody(BufWriter b) {
b.writeU2(1);
var lc = ((BufWriterImpl) b).labelContext();
int startBci = lc.labelToBci(lvt.startScope());
int endBci = lc.labelToBci(lvt.endScope());
int length = endBci - startBci;
b.writeU2(startBci);
b.writeU2(length);
b.writeIndex(lvt.name());
b.writeIndex(lvt.signature());
b.writeU2(lvt.slot());
AttributeHelpers.writeLocalVariable(
((BufWriterImpl) b).labelContext(),
b,
lvt.startScope(),
lvt.endScope(),
lvt.name(),
lvt.signature(),
lvt.slot()
);
}
});
default -> cob.with(coe);
Expand Down

0 comments on commit c3429f6

Please sign in to comment.