How to know to which object instance a field belongs to in javassist?How do I copy an object in Java?object references an unsaved transient instance - save the transient instance before flushingHow to get a class instance of generics type TConstructor.newInstance() without knowing parameter sequence?Ignoring new fields on JSON objects using JacksonCreate the perfect JPA entityDoes anyone have benchmarks (code & results) comparing performance of Android apps written in Xamarin C# and Java?How to add a SerialVersionUID to a Class[_] instance in Scala?how to access arraylist belonging to an object inside an arraylistjava instantiating object without knowing which subclass it will belong to until runtime
Farthing / Riding
How to play vs. 1.e4 e5 2.Nf3 Nc6 3.Bc4 d6?
Barron states that 4.18×10⁸ joules equal 1 kcal, is this correct?
How could Dwarves prevent sand from filling up their settlements
What should I wear to go and sign an employment contract?
Is there a realtime, uncut video of Saturn V ignition through tower clear?
Buying a Mountain Bike from a friend
Warped chessboard
What is this dime sized black bug with white on the segments near Loveland Colorodao?
Gambler's Fallacy Dice
Difference in 1 user doing 1000 iterations and 1000 users doing 1 iteration in Load testing
Connecting circles clockwise in TikZ
What city and town structures are important in a low fantasy medieval world?
Way of refund if scammed?
How is dynamic resistance of a diode modeled for large voltage variations?
If the Charles SSL Proxy shows me sensitive data, is that data insecure/exposed?
Rotate and duplicate row values in Google Sheets
On a piano, are the effects of holding notes and the sustain pedal the same for a single chord?
Is being an extrovert a necessary condition to be a manager?
Is there any mention of ghosts who live outside the Hogwarts castle?
Was Tyrion always a poor strategist?
How could the B-29 bomber back up under its own power?
How would a physicist explain this starship engine?
Reverse Array, Let Elements in New Array Equal Length of Original Array Elements - JavaScript
How to know to which object instance a field belongs to in javassist?
How do I copy an object in Java?object references an unsaved transient instance - save the transient instance before flushingHow to get a class instance of generics type TConstructor.newInstance() without knowing parameter sequence?Ignoring new fields on JSON objects using JacksonCreate the perfect JPA entityDoes anyone have benchmarks (code & results) comparing performance of Android apps written in Xamarin C# and Java?How to add a SerialVersionUID to a Class[_] instance in Scala?how to access arraylist belonging to an object inside an arraylistjava instantiating object without knowing which subclass it will belong to until runtime
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to develop a application using javassist, which should count the number of writes and reads to a field in an object. However when a field is written to inside the constructor it shouldn't be counted, only reads. My problem is that if I have a constructor that receives an object of the same type as a parameter and a field of that object is affected I want to count that write. However I don't know how to know to which object instance in javassist that field belongs to. For example taking this constructor as example:
Person(Person p)
this.firstname = p.firstname;
p.surname = "";
this.surname = p.surname;
I want to count the first and third lines as reads, since a read is valid in a constructor. But the only write I want to count is in the second line since it is a write to a field of a different instance of the object.
At the moment I have search the documentation on javassist and can't find a way to find in runtime to which instance a field belongs to. What I have so far is:
for (CtConstructor ctConstructor : ctClass.getDeclaredConstructors())
ctConstructor.instrument(new ExprEditor()
public void edit(FieldAccess fa) throws CannotCompileException
);
And my problem is in the second condition of the predicate in the lambda function.
The output I'm looking for is Total reads: 2 Total writes: 1, but I either get no writes, or 3 writes and both options are wrong in my problem.
java javassist
add a comment |
I'm trying to develop a application using javassist, which should count the number of writes and reads to a field in an object. However when a field is written to inside the constructor it shouldn't be counted, only reads. My problem is that if I have a constructor that receives an object of the same type as a parameter and a field of that object is affected I want to count that write. However I don't know how to know to which object instance in javassist that field belongs to. For example taking this constructor as example:
Person(Person p)
this.firstname = p.firstname;
p.surname = "";
this.surname = p.surname;
I want to count the first and third lines as reads, since a read is valid in a constructor. But the only write I want to count is in the second line since it is a write to a field of a different instance of the object.
At the moment I have search the documentation on javassist and can't find a way to find in runtime to which instance a field belongs to. What I have so far is:
for (CtConstructor ctConstructor : ctClass.getDeclaredConstructors())
ctConstructor.instrument(new ExprEditor()
public void edit(FieldAccess fa) throws CannotCompileException
);
And my problem is in the second condition of the predicate in the lambda function.
The output I'm looking for is Total reads: 2 Total writes: 1, but I either get no writes, or 3 writes and both options are wrong in my problem.
java javassist
Your copy constructor should never try to modify the content of the input argument.
– FredK
Mar 23 at 20:16
add a comment |
I'm trying to develop a application using javassist, which should count the number of writes and reads to a field in an object. However when a field is written to inside the constructor it shouldn't be counted, only reads. My problem is that if I have a constructor that receives an object of the same type as a parameter and a field of that object is affected I want to count that write. However I don't know how to know to which object instance in javassist that field belongs to. For example taking this constructor as example:
Person(Person p)
this.firstname = p.firstname;
p.surname = "";
this.surname = p.surname;
I want to count the first and third lines as reads, since a read is valid in a constructor. But the only write I want to count is in the second line since it is a write to a field of a different instance of the object.
At the moment I have search the documentation on javassist and can't find a way to find in runtime to which instance a field belongs to. What I have so far is:
for (CtConstructor ctConstructor : ctClass.getDeclaredConstructors())
ctConstructor.instrument(new ExprEditor()
public void edit(FieldAccess fa) throws CannotCompileException
);
And my problem is in the second condition of the predicate in the lambda function.
The output I'm looking for is Total reads: 2 Total writes: 1, but I either get no writes, or 3 writes and both options are wrong in my problem.
java javassist
I'm trying to develop a application using javassist, which should count the number of writes and reads to a field in an object. However when a field is written to inside the constructor it shouldn't be counted, only reads. My problem is that if I have a constructor that receives an object of the same type as a parameter and a field of that object is affected I want to count that write. However I don't know how to know to which object instance in javassist that field belongs to. For example taking this constructor as example:
Person(Person p)
this.firstname = p.firstname;
p.surname = "";
this.surname = p.surname;
I want to count the first and third lines as reads, since a read is valid in a constructor. But the only write I want to count is in the second line since it is a write to a field of a different instance of the object.
At the moment I have search the documentation on javassist and can't find a way to find in runtime to which instance a field belongs to. What I have so far is:
for (CtConstructor ctConstructor : ctClass.getDeclaredConstructors())
ctConstructor.instrument(new ExprEditor()
public void edit(FieldAccess fa) throws CannotCompileException
);
And my problem is in the second condition of the predicate in the lambda function.
The output I'm looking for is Total reads: 2 Total writes: 1, but I either get no writes, or 3 writes and both options are wrong in my problem.
java javassist
java javassist
asked Mar 23 at 19:58
RuiDTLimaRuiDTLima
1529
1529
Your copy constructor should never try to modify the content of the input argument.
– FredK
Mar 23 at 20:16
add a comment |
Your copy constructor should never try to modify the content of the input argument.
– FredK
Mar 23 at 20:16
Your copy constructor should never try to modify the content of the input argument.
– FredK
Mar 23 at 20:16
Your copy constructor should never try to modify the content of the input argument.
– FredK
Mar 23 at 20:16
add a comment |
1 Answer
1
active
oldest
votes
You only know to which object instance a field belongs during the runtime. You need to inject code that verifies it. One possible solution is to inject this code
if (this != $0) writeCounter++;
Remember that it is only possible because the field you want to count is an instance and not a static field.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317814%2fhow-to-know-to-which-object-instance-a-field-belongs-to-in-javassist%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You only know to which object instance a field belongs during the runtime. You need to inject code that verifies it. One possible solution is to inject this code
if (this != $0) writeCounter++;
Remember that it is only possible because the field you want to count is an instance and not a static field.
add a comment |
You only know to which object instance a field belongs during the runtime. You need to inject code that verifies it. One possible solution is to inject this code
if (this != $0) writeCounter++;
Remember that it is only possible because the field you want to count is an instance and not a static field.
add a comment |
You only know to which object instance a field belongs during the runtime. You need to inject code that verifies it. One possible solution is to inject this code
if (this != $0) writeCounter++;
Remember that it is only possible because the field you want to count is an instance and not a static field.
You only know to which object instance a field belongs during the runtime. You need to inject code that verifies it. One possible solution is to inject this code
if (this != $0) writeCounter++;
Remember that it is only possible because the field you want to count is an instance and not a static field.
answered Mar 24 at 12:28
nvelosonveloso
262
262
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317814%2fhow-to-know-to-which-object-instance-a-field-belongs-to-in-javassist%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your copy constructor should never try to modify the content of the input argument.
– FredK
Mar 23 at 20:16