Skip to content

Commit 96c5bf5

Browse files
committed
修复一个偶发的ConstantData压缩bug
修复一个MyHashMap的树节点扩容的bug 修复Tokenizer做参数tokenize的问题 重构MethodWriter CodeVisitor出错时会报告位置了 完成之前CI的重构,实现新架构 重构映射缓存系统,现在才叫“正常”的代码 支持jar签名 支持多工作空间 支持链式依赖 支持source depend 支持binary depend 支持变量替换 可选写入编译时间 修复泛型转换bug 加入了全新的彩虹特效,更加流畅! 序列化器现已支持Map使用非字符串key 修复AsmxLauncher启动带数字签名的自身时的崩溃
1 parent ee5cf3a commit 96c5bf5

File tree

93 files changed

+4434
-2136
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4434
-2136
lines changed

docs/Re_Lavac.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ var list = [1, 2, 3]; // List<Integer> (不可变)
127127
### finally优化 (已实现)
128128
在多个嵌套的finally块中,防止代码体积暴增
129129
### 预编译函数 (已实现)
130-
在编译期间执行标为【可预编译 @roj.compiler.plugins.eval.Constant】并已知入参的函数,并生成常量结果
130+
在编译期间执行标为【可预编译 @roj.compiler.plugins.eval.Constexpr】并已知入参的函数,并生成常量结果
131131
### 数组压缩
132132
将基本类型数组压缩为字符串(Base128),减少文件体积
133133
### 隐式导入|ImportAny (已实现)

java/roj/RojLib.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void linkLibrary(int bit) {
3434
public static Object getLibrary() {return LibraryLoader.INSTANCE.loadLibraryEx(RojLib.class, LibFile);}
3535

3636
private static final String LibName = "libcpp";
37-
private static File LibFile = new File("D:\\mc\\FMD-1.5.2\\projects\\implib\\libcpp\\bin\\libcpp.dll");
37+
private static File LibFile = new File("D:\\mc\\MCMake\\projects\\rojlib-jni\\bin\\libcpp.dll");
3838

3939
public static final boolean ASM_DEBUG = false;
4040
public static final boolean IS_DEV;

java/roj/archive/zip/ZEntry.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import roj.text.TextUtil;
88
import roj.util.ByteList;
99
import roj.util.DynByteBuf;
10+
import roj.util.Helpers;
1011

1112
import java.nio.file.attribute.FileTime;
1213
import java.util.TimeZone;
@@ -19,7 +20,7 @@
1920
* @author Roj234
2021
* @since 2023/3/14 0014 0:43
2122
*/
22-
public class ZEntry implements RSegmentTree.Range, ArchiveEntry {
23+
public class ZEntry implements RSegmentTree.Range, ArchiveEntry, Cloneable {
2324
//00: no compression
2425
//08: deflated
2526
//14: LZMA
@@ -431,6 +432,15 @@ public static int java2DosTime(long time) {
431432
return (year << 25) | (arr[ACalendar.MONTH] << 21) | (arr[ACalendar.DAY] << 16) | (arr[ACalendar.HOUR] << 11) | (arr[ACalendar.MINUTE] << 5) | (arr[ACalendar.SECOND] >> 1);
432433
}
433434

435+
@Override
436+
protected ZEntry clone() {
437+
try {
438+
return (ZEntry) super.clone();
439+
} catch (CloneNotSupportedException e) {
440+
return Helpers.nonnull();
441+
}
442+
}
443+
434444
private static final long WINDOWS_TIME_NOT_AVAILABLE = Long.MIN_VALUE;
435445
public static long checkAndSet0(long time) { return time == WINDOWS_TIME_NOT_AVAILABLE ? 0 : time; }
436446
private static final long WINDOWS_EPOCH_IN_MICROSECONDS = -11644473600000000L;

java/roj/archive/zip/ZipArchive.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.zip.ZipException;
3333

3434
import static roj.archive.zip.ZEntry.MZ_NoCrc;
35+
import static roj.reflect.ReflectionUtils.u;
3536

3637
/**
3738
* 支持分卷压缩文件
@@ -417,7 +418,10 @@ public void accept(List<? extends Range> files, long length) {
417418
*/
418419
public void reopen() throws IOException {
419420
if (file == null) throw new IOException("不是从文件打开");
420-
if (r == null) r = ArchiveUtils.tryOpenSplitArchive(file, false);
421+
if (r == null) {
422+
r = ArchiveUtils.tryOpenSplitArchive(file, false);
423+
fpRead = null;
424+
}
421425
}
422426

423427
private static void checkName(EntryMod entry) {

java/roj/archive/zip/ZipFile.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040
*/
4141
public class ZipFile implements ArchiveFile {
4242
Source r;
43-
private Source fpRead;
43+
Source fpRead;
4444
private static final long FPREAD_OFFSET = ReflectionUtils.fieldOffset(ZipFile.class, "fpRead");
4545

4646
private static final XHashSet.Shape<String, ZEntry> ENTRY_SHAPE = XHashSet.noCreation(ZEntry.class, "name", "next");
4747

4848
XHashSet<String, ZEntry> namedEntries;
49-
SimpleList<ZEntry> entries;
49+
SimpleList<ZEntry> entries = new SimpleList<>();
5050

5151
private ByteList buf;
5252
final Charset cs;
@@ -128,7 +128,7 @@ public void close() throws IOException {
128128
}
129129

130130
public final void reload() throws IOException {
131-
entries = new SimpleList<>();
131+
entries.clear();
132132
namedEntries = null;
133133
cDirLen = cDirOffset = 0;
134134

@@ -338,7 +338,7 @@ private void readLOC(SimpleList<ZEntry> locEntries) throws IOException {
338338
// 8; HAS EXT
339339
if ((flags & 8) != 0 && cSize == 0) {
340340
// skip method
341-
InflateIn in1 = (InflateIn) getCachedInflater(r.asInputStream());
341+
InflateIn in1 = (InflateIn) getCachedInflater(new SourceInputStream(r, Long.MAX_VALUE, false));
342342
byte[] tmp = buf.list;
343343
while (in1.read(tmp) >= 0);
344344

@@ -487,7 +487,8 @@ private void readEND64() throws IOException {
487487
cDirOffset = buf.readLongLE(36);
488488
}
489489

490-
private void verifyEntry(Source r, ZEntry entry) throws IOException {
490+
public void validateEntry(ZEntry entry) throws IOException {validateEntry(r, entry);}
491+
private void validateEntry(Source r, ZEntry entry) throws IOException {
491492
if ((entry.mzFlag & ZEntry.MZ_ERROR) != 0 && (flags & FLAG_VERIFY) != 0) throw new ZipException(entry+"报告自身已损坏");
492493
if ((entry.mzFlag & ZEntry.MZ_BACKWARD) == 0) return;
493494

@@ -566,7 +567,7 @@ public final InputStream getFileStream(ZEntry entry) throws IOException {
566567
Source src = (Source) u.getAndSetObject(this, FPREAD_OFFSET, null);
567568
if (src == null) src = r.threadSafeCopy();
568569

569-
verifyEntry(src, entry);
570+
validateEntry(src, entry);
570571
src.seek(entry.offset);
571572
return new SourceInputStream.Shared(src, entry.cSize, this, FPREAD_OFFSET);
572573
}

java/roj/archive/zip/ZipFileWriter.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ public ZipFileWriter(Source file, int compression) throws IOException {
5454
public void setComment(byte[] comment) { this.comment = comment; }
5555

5656
public void writeNamed(String name, ByteList b) throws IOException { writeNamed(name, b, ZipEntry.DEFLATED); }
57-
public void writeNamed(String name, ByteList b, int method) throws IOException {
57+
public void writeNamed(String name, ByteList b, int method) throws IOException { writeNamed(name, b, method, System.currentTimeMillis()); }
58+
public void writeNamed(String name, ByteList b, int method, long modTime) throws IOException {
5859
if (entry != null) closeEntry();
5960
if (name.endsWith("/")) throw new ZipException("目录不是空的: "+name);
6061

6162
int crc = CRC32s.once(b.list, b.arrayOffset()+b.rIndex, b.readableBytes());
6263

63-
int time = ZEntry.java2DosTime(System.currentTimeMillis());
64+
int time = ZEntry.java2DosTime(modTime);
6465
ByteList buf = this.buf;
6566
buf.clear();
6667
buf.putInt(HEADER_LOC)
@@ -133,7 +134,18 @@ public void copy(ArchiveFile o, ArchiveEntry e) throws IOException {
133134

134135
if (this.entry != null) closeEntry();
135136
long entryBeginOffset = file.position();
136-
file.put(owner.source(), entry.startPos(), entry.endPos() - entry.startPos());
137+
138+
// 20250221 fixed 文件中不知道长度的Entry但是经过读取已经知道了,所以复制之前需要重写CEntry
139+
owner.validateEntry(entry);
140+
if ((entry.flags & GP_HAS_EXT) != 0 && entry.getCompressedSize() != 0) {
141+
entry = entry.clone();
142+
entry.flags &= ~GP_HAS_EXT;
143+
ZipArchive.writeLOC(file, buf, entry);
144+
file.put(owner.source(), entry.getOffset(), entry.getCompressedSize());
145+
} else {
146+
file.put(owner.source(), entry.startPos(), entry.endPos() - entry.startPos());
147+
}
148+
137149
long delta = entryBeginOffset - entry.startPos();
138150
entry.offset += delta;
139151
buf.clear();

java/roj/archive/zip/ZipOutput.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@ public ZipOutput(File file) {
2727
public boolean isCompress() { return compress; }
2828
public void setCompress(boolean compress) { this.compress = compress; }
2929

30-
public void begin(boolean allModifyMode) throws IOException {
30+
public boolean isUseZFW() {return useZFW;}
31+
public ZipFileWriter getZFW() {return all;}
32+
33+
public void begin(boolean increment) throws IOException {
3134
if (work) end();
3235

33-
useZFW = allModifyMode;
34-
if (allModifyMode) {
36+
useZFW = !increment;
37+
if (increment) {
38+
if (some == null) {
39+
some = new ZipArchive(file);
40+
} else {
41+
some.reopen();
42+
}
43+
} else {
3544
all = new ZipFileWriter(file);
3645
if (some != null) {
3746
some.close();
3847
some = null;
3948
}
40-
} else if (some == null) {
41-
some = new ZipArchive(file);
42-
} else {
43-
some.reopen();
4449
}
4550
work = true;
4651
}
@@ -63,26 +68,34 @@ public void set(String name, Supplier<ByteList> data) throws IOException {
6368
}
6469
}
6570

66-
public void set(String name, InputStream in) throws IOException {
71+
public void set(String name, Supplier<ByteList> data, long modTime) throws IOException {
72+
if (useZFW) {
73+
all.writeNamed(name, data.get(), compress ? ZipEntry.DEFLATED : ZipEntry.STORED, modTime);
74+
} else {
75+
some.put(name, data, compress).entry.setModificationTime(modTime);
76+
}
77+
}
78+
79+
public void setStream(String name, Supplier<InputStream> data, long modTime) throws IOException {
6780
if (useZFW) {
6881
ZEntry ze = new ZEntry(name);
6982
ze.setMethod(compress ? ZipEntry.DEFLATED : ZipEntry.STORED);
83+
ze.setModificationTime(modTime);
7084
all.beginEntry(ze);
7185

7286
byte[] b = IOUtil.getSharedByteBuf().list;
7387
int r;
74-
try {
88+
try (var in = data.get()) {
7589
do {
7690
r = in.read(b);
7791
if (r < 0) break;
7892
all.write(b, 0, r);
7993
} while (r == b.length);
8094
} finally {
81-
in.close();
8295
all.closeEntry();
8396
}
8497
} else {
85-
some.putStream(name, in, compress);
98+
some.putStream(name, data, compress);
8699
}
87100
}
88101

java/roj/asm/cp/ConstantPool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ public void setUTFValue(CstUTF c, String str) {
284284
}
285285

286286
private void addConstant(Constant c) {
287-
int size = constants.size();
288-
if (size >= 0xFFFE) throw new UnsupportedOperationException("constant overflow!");
289-
c.setIndex(size+1);
290287
refMap.add(c);
291288
constants.add(c);
289+
int size = constants.size();
290+
c.setIndex(size);
291+
if (size >= 0xFFFF) throw new UnsupportedOperationException("constant overflow!");
292292

293293
switch (c.type()) {
294294
case UTF -> length += 3 + DynByteBuf.byteCountDioUTF(((CstUTF) c).str());

java/roj/asm/tree/anno/AnnVal.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
public abstract class AnnVal {
1616
public static AnnVal valueOf(String v) { return new AnnValString(v); }
17+
public static AnnVal valueOf(boolean v) { return new AnnValInt(BOOLEAN, v ? 1 : 0); }
1718
public static AnnVal valueOf(byte v) { return new AnnValInt(BYTE, v); }
1819
public static AnnVal valueOf(char v) { return new AnnValInt(CHAR, v); }
1920
public static AnnVal valueOf(short v) { return new AnnValInt(SHORT, v); }

java/roj/asm/type/Generic.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import roj.text.logging.Logger;
66
import roj.util.Helpers;
77

8+
import java.util.Arrays;
89
import java.util.List;
910
import java.util.function.UnaryOperator;
1011

@@ -37,6 +38,9 @@ public Generic(String owner, int array, byte extendType) {
3738
setArrayDim(array);
3839
}
3940

41+
public static Type type(String type) {return new Type(type);}
42+
public static Generic generic(String type, IType...rest) {return new Generic(type, Arrays.asList(rest));}
43+
4044
public boolean canBeAny() { return extendType == EX_EXTENDS && owner.equals("java/lang/Object") && children.isEmpty() && sub == null; }
4145

4246
public void toDesc(CharList sb) {

0 commit comments

Comments
 (0)