Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit775cfdc

Browse files
committed
7904095: jdis,jasm: tools that read or write reference types may corrupt Constant Pool entries
1 parenteb19796 commit775cfdc

19 files changed

+434
-273
lines changed

‎build/productinfo.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ PRODUCT_NAME =asmtools
2727
PRODUCT_JAR_NAME =asmtools.jar
2828
PRODUCT_VERSION =9.0
2929
PRODUCT_MILESTONE =ea
30-
PRODUCT_BUILDNUMBER =12
30+
PRODUCT_BUILDNUMBER =14
3131
PRODUCT_NAME_LONG =Java Assembler Tools

‎src/org/openjdk/asmtools/common/structure/ELocation.java‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024,2025,Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,10 +27,20 @@
2727
* Table 4.7-C. Predefined class file attributes (by location)
2828
*/
2929
publicenumELocation {
30-
UNKNOWN,
31-
ClassFile,
32-
field_info,
33-
method_info,
34-
record_component_info,
35-
Code
30+
unknown("Unknown"),
31+
class_file("ClassFile"),
32+
field_info("field_info"),
33+
method_info("method_info"),
34+
record_component_info("record_component_info"),
35+
code_atribute("Code");
36+
37+
publicStringgetDescription() {
38+
returndescription;
39+
}
40+
41+
privatefinalStringdescription;
42+
43+
ELocation(Stringdescription) {
44+
this.description =description;
45+
}
3646
}

‎src/org/openjdk/asmtools/jasm/ClassData.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ClassData extends MemberData<JasmEnvironment> {
9292
*/
9393
publicClassData(JasmEnvironmentenvironment,CFVersioncfv) {
9494
super(newConstantPool(environment),environment);// for a class, these get initialized in the super - later.
95-
this.attributeLocation =ELocation.ClassFile;
95+
this.attributeLocation =ELocation.class_file;
9696
this.environment =environment;
9797
this.cdos =newCDOutputStream();
9898
this.cfv =cfv;

‎src/org/openjdk/asmtools/jasm/CodeAttr.java‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ private StackMapData getPreviousStackMapEntry() {
486486

487487
@Override
488488
publicintattrLength() {
489-
return2 +2 +4// for max_stack, max_locals, and cur_pc
490-
+curPC// + 2+trap_table.size()*8
489+
return2 +2 +4// for max_stack, max_locals, and cur_pc
490+
+curPC// + 2+trap_table.size()*8
491491
+exceptionTable.getLength() +attributes.getLength();
492492
}
493493

@@ -507,6 +507,15 @@ public void write(CheckedDataOutputStream out)
507507
attributes.write(out);
508508
}
509509

510+
/**
511+
* Checks if the code attribute is empty, i.e., it contains no instructions.
512+
*
513+
* @return true if the code attribute is empty, false otherwise
514+
*/
515+
publicbooleanisEmpty() {
516+
returncurPC ==0;
517+
}
518+
510519
/* CodeAttr inner classes */
511520
staticpublicclassLocalextendsIndexer {
512521
Stringname;
@@ -517,18 +526,12 @@ public Local(String name) {
517526
}
518527
}
519528

520-
/**
521-
*
522-
*/
523529
staticpublicclassLabelextendsLocal {
524530
publicLabel(Stringname) {
525531
super(name);
526532
}
527533
}
528534

529-
/**
530-
*
531-
*/
532535
staticclassRangePCextendsLocal {
533536
intstart_pc =Indexer.NotSet;
534537
intend_pc =Indexer.NotSet;

‎src/org/openjdk/asmtools/jasm/JasmTokens.java‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
*/
2323
packageorg.openjdk.asmtools.jasm;
2424

25-
importjava.util.Arrays;
26-
importjava.util.EnumSet;
27-
importjava.util.Optional;
28-
importjava.util.Set;
25+
importjava.util.*;
2926
importjava.util.stream.Collectors;
3027

3128
/**
@@ -79,7 +76,7 @@ public enum TokenType {
7976
JASM_IDENT("Jasm identifier"),
8077
MODULE_NAME("Module Name"),// The token can be used as Module Name
8178
TYPE_PATH_KIND("Type path kind"),// Table 4.7.20.2-A Interpretation of type_path_kind values
82-
CLASS_NAME("Class Name");// The token can be used as Class Name
79+
CLASS_NAME("Class Name");// The token can be used as Class Name
8380

8481
privatefinalStringprintValue;
8582

@@ -536,4 +533,15 @@ public String toString() {
536533
publicstaticTokenkeyword_token_ident(StringidValue) {
537534
returnToken.get(idValue,KeywordType.KEYWORD).orElse(Token.IDENT);
538535
}
536+
537+
publicstaticStringasString(List<Token>tokens) {
538+
StringBuildersb =newStringBuilder("");
539+
for (Tokentoken :tokens) {
540+
if(sb .length() >0) {
541+
sb.append(", ");
542+
}
543+
sb.append('\'').append(token.parseKey()).append('\'');
544+
}
545+
returnsb.toString();
546+
}
539547
}

‎src/org/openjdk/asmtools/jasm/MemberData.java‎

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996,2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996,2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -47,7 +47,7 @@ abstract public class MemberData<T extends Environment<? extends ToolLogger>> {
4747
protectedDataVectorAttr<TypeAnnotationData>type_annotAttrVis =null;
4848
protectedDataVectorAttr<TypeAnnotationData>type_annotAttrInv =null;
4949
protectedAttrDatasignatureAttr;
50-
protectedELocationattributeLocation =ELocation.UNKNOWN;
50+
protectedELocationattributeLocation =ELocation.unknown;
5151

5252
publicMemberData(ConstantPoolpool,Tenvironment) {
5353
this(pool,environment,0);
@@ -112,6 +112,13 @@ public ConstantPool getPool() {
112112
}
113113

114114
publicvoidsetSignatureAttr(ConstCellvalue_cpx) {
115+
if (this.signatureAttr !=null) {
116+
CPXAttrcpx = (CPXAttr)signatureAttr;
117+
if (value_cpx.cpIndex !=cpx.cell.cpIndex) {
118+
environment.warning("warn.redeclared.attribute",SIGNATURE.parseKey(),
119+
this.attributeLocation.getDescription());
120+
}
121+
}
115122
signatureAttr =newCPXAttr(pool,EAttribute.ATT_Signature,value_cpx);
116123
}
117124

@@ -120,12 +127,21 @@ public void setSignatureAttr(ConstCell value_cpx, long position) {
120127
CPXAttrcpx = (CPXAttr)signatureAttr;
121128
if (value_cpx.cpIndex !=cpx.cell.cpIndex) {
122129
environment.warning(position,"warn.redeclared.attribute",
123-
SIGNATURE.parseKey(),ELocation.ClassFile.toString());
130+
SIGNATURE.parseKey(),this.attributeLocation.getDescription());
124131
}
125132
}
126133
signatureAttr =newCPXAttr(pool,EAttribute.ATT_Signature,value_cpx);
127134
}
128135

136+
/**
137+
* Retrieves the signature attribute associated with this member.
138+
*
139+
* @return the signature attribute, or null if it has not been set
140+
*/
141+
publicAttrDatagetSignatureAttr() {
142+
returnsignatureAttr;
143+
}
144+
129145

130146
protectedabstract <DextendsDataWriter>DataVector<D>getAttrVector();
131147

@@ -153,41 +169,44 @@ protected final <D extends DataWriter> DataVector<D> getDataVector(D... extraAtt
153169
returnattrs;
154170
}
155171

156-
publicvoidaddAnnotations(ArrayList<AnnotationData>list) {
157-
for (AnnotationDataitem :list) {
158-
booleaninvisible =item.invisible;
159-
160-
if (iteminstanceofTypeAnnotationDatatypeAnnotationData) {
161-
// Type Annotations
162-
if (invisible) {
163-
if (type_annotAttrInv ==null) {
164-
type_annotAttrInv =newDataVectorAttr<>(pool,
165-
EAttribute.ATT_RuntimeInvisibleTypeAnnotations);
166-
}
167-
type_annotAttrInv.add(typeAnnotationData);
168-
}else {
169-
if (type_annotAttrVis ==null) {
170-
type_annotAttrVis =newDataVectorAttr<>(pool,
171-
EAttribute.ATT_RuntimeVisibleTypeAnnotations);
172-
}
173-
type_annotAttrVis.add(typeAnnotationData);
174-
}
175-
}else {
176-
// Regular Annotations
177-
if (invisible) {
178-
if (annotAttrInv ==null) {
179-
annotAttrInv =newDataVectorAttr<>(pool,
180-
EAttribute.ATT_RuntimeInvisibleAnnotations);
172+
publicMemberData<T>addAnnotations(ArrayList<AnnotationData>list) {
173+
if(list !=null ) {
174+
for (AnnotationDataitem :list) {
175+
booleaninvisible =item.invisible;
176+
177+
if (iteminstanceofTypeAnnotationDatatypeAnnotationData) {
178+
// Type Annotations
179+
if (invisible) {
180+
if (type_annotAttrInv ==null) {
181+
type_annotAttrInv =newDataVectorAttr<>(pool,
182+
EAttribute.ATT_RuntimeInvisibleTypeAnnotations);
183+
}
184+
type_annotAttrInv.add(typeAnnotationData);
185+
}else {
186+
if (type_annotAttrVis ==null) {
187+
type_annotAttrVis =newDataVectorAttr<>(pool,
188+
EAttribute.ATT_RuntimeVisibleTypeAnnotations);
189+
}
190+
type_annotAttrVis.add(typeAnnotationData);
181191
}
182-
annotAttrInv.add(item);
183192
}else {
184-
if (annotAttrVis ==null) {
185-
annotAttrVis =newDataVectorAttr<>(pool,
186-
EAttribute.ATT_RuntimeVisibleAnnotations);
193+
// Regular Annotations
194+
if (invisible) {
195+
if (annotAttrInv ==null) {
196+
annotAttrInv =newDataVectorAttr<>(pool,
197+
EAttribute.ATT_RuntimeInvisibleAnnotations);
198+
}
199+
annotAttrInv.add(item);
200+
}else {
201+
if (annotAttrVis ==null) {
202+
annotAttrVis =newDataVectorAttr<>(pool,
203+
EAttribute.ATT_RuntimeVisibleAnnotations);
204+
}
205+
annotAttrVis.add(item);
187206
}
188-
annotAttrVis.add(item);
189207
}
190208
}
191209
}
210+
returnthis;
192211
}
193212
}

‎src/org/openjdk/asmtools/jasm/MethodData.java‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996,2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996,2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -142,17 +142,44 @@ public MethodData(ClassData classData, int access, ConstCell<?> name, ConstCell<
142142
super(classData.pool,classData.getEnvironment(),access);
143143
this.classData =classData;
144144
this.attributeLocation =ELocation.method_info;
145+
this.addExceptions(exc_table);
145146
nameCell =name;
146147
sigCell =signature;
147-
if ((exc_table !=null) && (!exc_table.isEmpty())) {
148-
exceptions =newDataVectorAttr<>(classData.pool,EAttribute.ATT_Exceptions,exc_table);
149-
}
150148
// Normalize the modifiers to access flags
151149
if (EModifier.hasPseudoMod(access)) {
152150
createPseudoMod();
153151
}
154152
}
155153

154+
publicvoidaddExceptions(ArrayList<ConstCell<?>>exc_table) {
155+
if ((exc_table !=null) && (!exc_table.isEmpty())) {
156+
if (exceptions ==null) {
157+
exceptions =newDataVectorAttr<>(classData.pool,EAttribute.ATT_Exceptions,exc_table);
158+
}else {
159+
exceptions.addAll(exc_table);
160+
}
161+
}
162+
}
163+
164+
publicDataVectorAttr<ConstCell<?>>getExceptions() {
165+
returnexceptions;
166+
}
167+
168+
publicbooleanhasExceptions() {
169+
return (exceptions !=null) && (!exceptions.isEmpty());
170+
}
171+
172+
/**
173+
* Retrieves the default annotation attribute associated with this method.
174+
* The default annotation is used to store the default value of an annotation
175+
* method.
176+
*
177+
* @return the default annotation attribute, or null if it has not been set
178+
*/
179+
publicDefaultAnnotationAttrgetDefaultAnnotation() {
180+
returndefaultAnnot;
181+
}
182+
156183
publicvoidaddMethodParameter(inttotalParams,intparamNum,ConstCell<?>name,intaccess) {
157184
getEnvironment().traceln("addMethodParameter Param[" +paramNum +"] (name: " +name.toString() +", Flags (" +access +").");
158185
if (methodParameters ==null) {
@@ -170,7 +197,7 @@ public CodeAttr startCode(int paramCount, Indexer max_stack, Indexer max_locals)
170197
returncode;
171198
}
172199

173-
publicvoidaddDefaultAnnotation(DefaultAnnotationAttrdata) {
200+
publicvoidsetDefaultAnnotation(DefaultAnnotationAttrdata) {
174201
defaultAnnot =data;
175202
}
176203

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp