Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Jamie Mansfield
asm
Commits
01a551c4
Commit
01a551c4
authored
May 04, 2018
by
Eric Bruneton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move the code to replace the ASM specific instructions to a separate method.
parent
71a78ab5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
25 deletions
+38
-25
asm/src/main/java/org/objectweb/asm/ClassWriter.java
asm/src/main/java/org/objectweb/asm/ClassWriter.java
+36
-23
asm/src/test/java/org/objectweb/asm/ClassWriterTest.java
asm/src/test/java/org/objectweb/asm/ClassWriterTest.java
+2
-2
No files found.
asm/src/main/java/org/objectweb/asm/ClassWriter.java
View file @
01a551c4
...
...
@@ -644,35 +644,48 @@ public class ClassWriter extends ClassVisitor {
firstAttribute
.
putAttributes
(
symbolTable
,
result
);
}
// Third step: do a ClassReader->ClassWriter round trip if the generated class contains ASM
// specific instructions due to large forward jumps.
// Third step: replace the ASM specific instructions, if any.
if
(
hasAsmInstructions
)
{
Attribute
[]
attributes
=
getAttributePrototypes
();
firstField
=
null
;
lastField
=
null
;
firstMethod
=
null
;
lastMethod
=
null
;
lastRuntimeVisibleAnnotation
=
null
;
lastRuntimeInvisibleAnnotation
=
null
;
lastRuntimeVisibleTypeAnnotation
=
null
;
lastRuntimeInvisibleTypeAnnotation
=
null
;
moduleWriter
=
null
;
nestHostClassIndex
=
0
;
numberOfNestMemberClasses
=
0
;
nestMemberClasses
=
null
;
firstAttribute
=
null
;
compute
=
hasFrames
?
MethodWriter
.
COMPUTE_INSERTED_FRAMES
:
MethodWriter
.
COMPUTE_NOTHING
;
new
ClassReader
(
result
.
data
,
0
,
/* checkClassVersion = */
false
)
.
accept
(
this
,
attributes
,
(
hasFrames
?
ClassReader
.
EXPAND_FRAMES
:
0
)
|
ClassReader
.
EXPAND_ASM_INSNS
);
return
toByteArray
();
return
replaceAsmInstructions
(
result
.
data
,
hasFrames
);
}
else
{
return
result
.
data
;
}
}
/**
* Returns the equivalent of the given class file, with the ASM specific instructions replaced
* with standard ones. This is done with a ClassReader -> ClassWriter round trip.
*
* @param classFile a class file containing ASM specific instructions, generated by this
* ClassWriter.
* @param hasFrames whether there is at least one stack map frames in 'classFile'.
* @return an equivalent of 'classFile', with the ASM specific instructions replaced with standard
* ones.
*/
private
byte
[]
replaceAsmInstructions
(
final
byte
[]
classFile
,
final
boolean
hasFrames
)
{
Attribute
[]
attributes
=
getAttributePrototypes
();
firstField
=
null
;
lastField
=
null
;
firstMethod
=
null
;
lastMethod
=
null
;
lastRuntimeVisibleAnnotation
=
null
;
lastRuntimeInvisibleAnnotation
=
null
;
lastRuntimeVisibleTypeAnnotation
=
null
;
lastRuntimeInvisibleTypeAnnotation
=
null
;
moduleWriter
=
null
;
nestHostClassIndex
=
0
;
numberOfNestMemberClasses
=
0
;
nestMemberClasses
=
null
;
firstAttribute
=
null
;
compute
=
hasFrames
?
MethodWriter
.
COMPUTE_INSERTED_FRAMES
:
MethodWriter
.
COMPUTE_NOTHING
;
new
ClassReader
(
classFile
,
0
,
/* checkClassVersion = */
false
)
.
accept
(
this
,
attributes
,
(
hasFrames
?
ClassReader
.
EXPAND_FRAMES
:
0
)
|
ClassReader
.
EXPAND_ASM_INSNS
);
return
toByteArray
();
}
/**
* Returns the prototypes of the attributes used by this class, its fields and its methods.
*
...
...
asm/src/test/java/org/objectweb/asm/ClassWriterTest.java
View file @
01a551c4
...
...
@@ -55,8 +55,8 @@ public class ClassWriterTest extends AsmTest {
/**
* Tests that the non-static fields of ClassWriter are the expected ones. This test is designed to
* fail each time new fields are added to ClassWriter, and serves as a reminder to update the
* field reset logic in {@link ClassWriter#
toByteArray
()}, if needed, each time a new
field is
* added.
* field reset logic in {@link ClassWriter#
replaceAsmInstructions
()}, if needed, each time a new
*
field is
added.
*/
@Test
public
void
testInstanceFields
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment