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;








0















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.










share|improve this question






















  • Your copy constructor should never try to modify the content of the input argument.

    – FredK
    Mar 23 at 20:16

















0















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.










share|improve this question






















  • Your copy constructor should never try to modify the content of the input argument.

    – FredK
    Mar 23 at 20:16













0












0








0


1






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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer



























      1














      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.






      share|improve this answer

























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 12:28









        nvelosonveloso

        262




        262





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현