-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code model attribute hard-coded #290
Open
asotona
wants to merge
18
commits into
openjdk:code-reflection
Choose a base branch
from
asotona:CodeModel-attribute-hard-coded
base: code-reflection
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3cd8a01
Initial draft of CodeModelAttribute and CodeModelAttributeMapper
asotona 91a7083
merge into CodeModelAttribute
asotona 911c6c2
CodeModelAttribute work in progress
asotona f7577ec
CodeModelAttribute work in progress
asotona 88d4163
CodeModelAttribute work in progress
asotona 981ae7c
fixed types serialization
asotona e8a63d8
custom serialization of location attribute
asotona ea9ebcc
CodeModeAtrtribute documentation work in progress
asotona 72721a9
CodeModelAttribute structure cleanup + javadoc work in progress
asotona e8dcde5
typo
asotona ce1ec7d
Hard-coded CodeModelAttribute work in progress
asotona b123f6a
Hard-coded CodeModelAttribute work in progress
asotona 2f289ba
Hard-coded CodeModelAttribute work in progress
asotona 5be4e87
Hard-coded CodeModelAttribute work in progress
asotona 8a83e96
Hard-coded CodeModelAttribute work in progress
asotona cc859f0
code cleanup
asotona 7a94d8d
code cleanup
asotona 15f241e
code cleanup
asotona File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/CodeModelAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (c) 2024, 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.incubator.code.internal; | ||
|
||
import java.lang.classfile.AttributeMapper; | ||
import java.lang.classfile.AttributedElement; | ||
import java.lang.classfile.BufWriter; | ||
import java.lang.classfile.ClassReader; | ||
import java.lang.classfile.CustomAttribute; | ||
import jdk.incubator.code.Op; | ||
|
||
public class CodeModelAttribute extends CustomAttribute<CodeModelAttribute>{ | ||
|
||
enum Tag { | ||
LocationAttr, | ||
|
||
// CoreOp | ||
AddOp, AndOp, ArrayLoadOp, ArrayStoreOp, ArrayLengthOp, AshrOp, AssertOp, BranchOp, CastOp, ClosureCallOp, | ||
ClosureOp, ComplOp, ConcatOp, ConditionalBranchOp, ConstantOp, ConvOp, DivOp, EqOp, ExceptionRegionEnter, | ||
ExceptionRegionExit, FieldLoadOp, FieldStoreOp, FuncCallOp, FuncOp, GeOp, GtOp, InstanceOfOp, InvokeOp, | ||
LambdaOp, LeOp, LshlOp, LshrOp, LtOp, ModOp, ModuleOp, MonitorEnterOp, MonitorExitOp, MulOp, NegOp, NeqOp, | ||
NewOp, NotOp, OrOp, QuotedOp, ReturnOp, SubOp, ThrowOp, TupleLoadOp, TupleOp, TupleWithOp, UnreachableOp, | ||
VarLoadOp, VarStoreOp, VarOp, XorOp, YieldOp, | ||
|
||
// ExtendedOp | ||
JavaBlockOp, JavaBreakOp, JavaConditionalAndOp, JavaConditionalExpressionOp, JavaConditionalOrOp, | ||
JavaContinueOp, JavaDoWhileOp, JavaEnhancedForOp, JavaForOp, JavaIfOp, JavaLabeledOp, JavaSwitchExpressionOp, | ||
JavaSwitchFallthroughOp, JavaSwitchStatementOp, JavaSynchronizedOp, JavaTryOp, JavaYieldOp, JavaWhileOp, | ||
MatchAllPatternOp, MatchOp, RecordPatternOp, TypePatternOp; | ||
} | ||
|
||
public static final String NAME = "CodeModel"; | ||
|
||
public static final AttributeMapper<CodeModelAttribute> MAPPER = new AttributeMapper<>() { | ||
|
||
@Override | ||
public String name() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public CodeModelAttribute readAttribute(AttributedElement enclosing, ClassReader cr, int pos) { | ||
return new CodeModelAttribute(new OpReader(cr, pos).readOp(null, null)); | ||
} | ||
|
||
@Override | ||
public void writeAttribute(BufWriter buf, CodeModelAttribute attr) { | ||
buf.writeIndex(buf.constantPool().utf8Entry(NAME)); | ||
int lengthIndex = buf.size(); | ||
buf.writeInt(0); | ||
new OpWriter(buf).writeOp(attr.op); | ||
int written = buf.size() - lengthIndex - 4; | ||
buf.patchInt(lengthIndex, 4, written); | ||
} | ||
|
||
@Override | ||
public AttributeMapper.AttributeStability stability() { | ||
return AttributeMapper.AttributeStability.CP_REFS; | ||
} | ||
}; | ||
|
||
public static CodeModelAttribute of(Op op) { | ||
return new CodeModelAttribute(op); | ||
} | ||
|
||
private final Op op; | ||
|
||
private CodeModelAttribute(Op op) { | ||
super(MAPPER); | ||
this.op = op; | ||
} | ||
|
||
public Op op() { | ||
return op; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of maintenance, I wonder if there could be a way to connect the tag more directly to the op classes. E.g. so that if an op is added/removed, we may rely on static checks to detect that our reading/writing logic needs updating.
But maybe that works already: after all, the writing logic does a switch on the
op
instance - if that switch is made exhaustive, we could prevent mistakes when new ops are added. (when ops are removed, the mistake will be detected more easily, as the serialization code will refer to no longer existing classes).