What is a `monitor` in JVM(Hotspot), a specific object? [duplicate]

Multi tool use
Multi tool use












0















This question already has an answer here:




  • What's a monitor in Java?

    7 answers



  • Semaphore vs. Monitors - what's the difference?

    6 answers




In Java Language Spec, Section 17.1: Synchronization, it says




Each object in Java is associated with a monitor, which a thread can lock or unlock.




Section 17.2:




Every object, in addition to having an associated monitor, has an associated wait set. A wait set is a set of threads.



When an object is first created, its wait set is empty. Elementary actions that add threads to and remove threads from wait sets are atomic. Wait sets are manipulated solely through the methods Object.wait, Object.notify, and Object.notifyAll.




A question here is, what is monitor, seems it is an object which contain a wait set?



I have take a look at a similar question What's a monitor in Java? on stackoverflow, but the answers were not so clearly.




A monitor is mechanism to control concurrent access to an object.



A monitor is an entity that possesses both a lock and a wait set. In Java, any Object can serve as a monitor.




I got some more info on Hotspot runtime overview




Per-object synchronization state is encoded in the first word (the so-called mark word) of the VM's object representation. For several states, the mark word is multiplexed to point to additional synchronization metadata. (As an aside, in addition, the mark word is also multiplexed to contain GC age data, and the object's identity hashCode value.) The states are:





  • Neutral: Unlocked


  • Biased: Locked/Unlocked + Unshared


  • Stack-Locked: Locked + Shared but uncontended The mark points to
    displaced mark word on the owner thread's stack.


  • Inflated: Locked/Unlocked + Shared and contended Threads are blocked
    in monitorenter or wait(). The mark points to heavy-weight
    "objectmonitor" structure.[8]



I guess if a monitor is a objectmonitor structure? But objectmonitor does not created at first, only used when heavy weight lock is used due to contention.










share|improve this question















marked as duplicate by shmosel java
Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 28 '18 at 3:28


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















    0















    This question already has an answer here:




    • What's a monitor in Java?

      7 answers



    • Semaphore vs. Monitors - what's the difference?

      6 answers




    In Java Language Spec, Section 17.1: Synchronization, it says




    Each object in Java is associated with a monitor, which a thread can lock or unlock.




    Section 17.2:




    Every object, in addition to having an associated monitor, has an associated wait set. A wait set is a set of threads.



    When an object is first created, its wait set is empty. Elementary actions that add threads to and remove threads from wait sets are atomic. Wait sets are manipulated solely through the methods Object.wait, Object.notify, and Object.notifyAll.




    A question here is, what is monitor, seems it is an object which contain a wait set?



    I have take a look at a similar question What's a monitor in Java? on stackoverflow, but the answers were not so clearly.




    A monitor is mechanism to control concurrent access to an object.



    A monitor is an entity that possesses both a lock and a wait set. In Java, any Object can serve as a monitor.




    I got some more info on Hotspot runtime overview




    Per-object synchronization state is encoded in the first word (the so-called mark word) of the VM's object representation. For several states, the mark word is multiplexed to point to additional synchronization metadata. (As an aside, in addition, the mark word is also multiplexed to contain GC age data, and the object's identity hashCode value.) The states are:





    • Neutral: Unlocked


    • Biased: Locked/Unlocked + Unshared


    • Stack-Locked: Locked + Shared but uncontended The mark points to
      displaced mark word on the owner thread's stack.


    • Inflated: Locked/Unlocked + Shared and contended Threads are blocked
      in monitorenter or wait(). The mark points to heavy-weight
      "objectmonitor" structure.[8]



    I guess if a monitor is a objectmonitor structure? But objectmonitor does not created at first, only used when heavy weight lock is used due to contention.










    share|improve this question















    marked as duplicate by shmosel java
    Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Dec 28 '18 at 3:28


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















      0












      0








      0








      This question already has an answer here:




      • What's a monitor in Java?

        7 answers



      • Semaphore vs. Monitors - what's the difference?

        6 answers




      In Java Language Spec, Section 17.1: Synchronization, it says




      Each object in Java is associated with a monitor, which a thread can lock or unlock.




      Section 17.2:




      Every object, in addition to having an associated monitor, has an associated wait set. A wait set is a set of threads.



      When an object is first created, its wait set is empty. Elementary actions that add threads to and remove threads from wait sets are atomic. Wait sets are manipulated solely through the methods Object.wait, Object.notify, and Object.notifyAll.




      A question here is, what is monitor, seems it is an object which contain a wait set?



      I have take a look at a similar question What's a monitor in Java? on stackoverflow, but the answers were not so clearly.




      A monitor is mechanism to control concurrent access to an object.



      A monitor is an entity that possesses both a lock and a wait set. In Java, any Object can serve as a monitor.




      I got some more info on Hotspot runtime overview




      Per-object synchronization state is encoded in the first word (the so-called mark word) of the VM's object representation. For several states, the mark word is multiplexed to point to additional synchronization metadata. (As an aside, in addition, the mark word is also multiplexed to contain GC age data, and the object's identity hashCode value.) The states are:





      • Neutral: Unlocked


      • Biased: Locked/Unlocked + Unshared


      • Stack-Locked: Locked + Shared but uncontended The mark points to
        displaced mark word on the owner thread's stack.


      • Inflated: Locked/Unlocked + Shared and contended Threads are blocked
        in monitorenter or wait(). The mark points to heavy-weight
        "objectmonitor" structure.[8]



      I guess if a monitor is a objectmonitor structure? But objectmonitor does not created at first, only used when heavy weight lock is used due to contention.










      share|improve this question
















      This question already has an answer here:




      • What's a monitor in Java?

        7 answers



      • Semaphore vs. Monitors - what's the difference?

        6 answers




      In Java Language Spec, Section 17.1: Synchronization, it says




      Each object in Java is associated with a monitor, which a thread can lock or unlock.




      Section 17.2:




      Every object, in addition to having an associated monitor, has an associated wait set. A wait set is a set of threads.



      When an object is first created, its wait set is empty. Elementary actions that add threads to and remove threads from wait sets are atomic. Wait sets are manipulated solely through the methods Object.wait, Object.notify, and Object.notifyAll.




      A question here is, what is monitor, seems it is an object which contain a wait set?



      I have take a look at a similar question What's a monitor in Java? on stackoverflow, but the answers were not so clearly.




      A monitor is mechanism to control concurrent access to an object.



      A monitor is an entity that possesses both a lock and a wait set. In Java, any Object can serve as a monitor.




      I got some more info on Hotspot runtime overview




      Per-object synchronization state is encoded in the first word (the so-called mark word) of the VM's object representation. For several states, the mark word is multiplexed to point to additional synchronization metadata. (As an aside, in addition, the mark word is also multiplexed to contain GC age data, and the object's identity hashCode value.) The states are:





      • Neutral: Unlocked


      • Biased: Locked/Unlocked + Unshared


      • Stack-Locked: Locked + Shared but uncontended The mark points to
        displaced mark word on the owner thread's stack.


      • Inflated: Locked/Unlocked + Shared and contended Threads are blocked
        in monitorenter or wait(). The mark points to heavy-weight
        "objectmonitor" structure.[8]



      I guess if a monitor is a objectmonitor structure? But objectmonitor does not created at first, only used when heavy weight lock is used due to contention.





      This question already has an answer here:




      • What's a monitor in Java?

        7 answers



      • Semaphore vs. Monitors - what's the difference?

        6 answers








      java multithreading jvm-hotspot






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 28 '18 at 3:33

























      asked Dec 28 '18 at 3:26









      Jacky

      1,350825




      1,350825




      marked as duplicate by shmosel java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 28 '18 at 3:28


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by shmosel java
      Users with the  java badge can single-handedly close java questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 28 '18 at 3:28


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          1














          A monitor is a concept on which you can perform certain operations. Anything that implements the abstract operations of the concept of a monitor is a good implementation.



          The concept is implemented in HotSpot in the mark word plus everything described in the text that you quoted about the mark word. It is not a single data structure.






          share|improve this answer



















          • 1




            Does that mean Every object, in addition to having an associated monitor, has an associated wait set. its wait set is empty. is just a conceptual description, not involved with implementation details.
            – Jacky
            Dec 28 '18 at 3:38








          • 1




            Yes, that's correct.
            – Louis Wasserman
            Dec 28 '18 at 3:46










          • Indeed that's correct
            – Erwin Bolwidt
            Dec 28 '18 at 4:01


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          A monitor is a concept on which you can perform certain operations. Anything that implements the abstract operations of the concept of a monitor is a good implementation.



          The concept is implemented in HotSpot in the mark word plus everything described in the text that you quoted about the mark word. It is not a single data structure.






          share|improve this answer



















          • 1




            Does that mean Every object, in addition to having an associated monitor, has an associated wait set. its wait set is empty. is just a conceptual description, not involved with implementation details.
            – Jacky
            Dec 28 '18 at 3:38








          • 1




            Yes, that's correct.
            – Louis Wasserman
            Dec 28 '18 at 3:46










          • Indeed that's correct
            – Erwin Bolwidt
            Dec 28 '18 at 4:01
















          1














          A monitor is a concept on which you can perform certain operations. Anything that implements the abstract operations of the concept of a monitor is a good implementation.



          The concept is implemented in HotSpot in the mark word plus everything described in the text that you quoted about the mark word. It is not a single data structure.






          share|improve this answer



















          • 1




            Does that mean Every object, in addition to having an associated monitor, has an associated wait set. its wait set is empty. is just a conceptual description, not involved with implementation details.
            – Jacky
            Dec 28 '18 at 3:38








          • 1




            Yes, that's correct.
            – Louis Wasserman
            Dec 28 '18 at 3:46










          • Indeed that's correct
            – Erwin Bolwidt
            Dec 28 '18 at 4:01














          1












          1








          1






          A monitor is a concept on which you can perform certain operations. Anything that implements the abstract operations of the concept of a monitor is a good implementation.



          The concept is implemented in HotSpot in the mark word plus everything described in the text that you quoted about the mark word. It is not a single data structure.






          share|improve this answer














          A monitor is a concept on which you can perform certain operations. Anything that implements the abstract operations of the concept of a monitor is a good implementation.



          The concept is implemented in HotSpot in the mark word plus everything described in the text that you quoted about the mark word. It is not a single data structure.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 28 '18 at 4:01

























          answered Dec 28 '18 at 3:32









          Erwin Bolwidt

          23.8k123858




          23.8k123858








          • 1




            Does that mean Every object, in addition to having an associated monitor, has an associated wait set. its wait set is empty. is just a conceptual description, not involved with implementation details.
            – Jacky
            Dec 28 '18 at 3:38








          • 1




            Yes, that's correct.
            – Louis Wasserman
            Dec 28 '18 at 3:46










          • Indeed that's correct
            – Erwin Bolwidt
            Dec 28 '18 at 4:01














          • 1




            Does that mean Every object, in addition to having an associated monitor, has an associated wait set. its wait set is empty. is just a conceptual description, not involved with implementation details.
            – Jacky
            Dec 28 '18 at 3:38








          • 1




            Yes, that's correct.
            – Louis Wasserman
            Dec 28 '18 at 3:46










          • Indeed that's correct
            – Erwin Bolwidt
            Dec 28 '18 at 4:01








          1




          1




          Does that mean Every object, in addition to having an associated monitor, has an associated wait set. its wait set is empty. is just a conceptual description, not involved with implementation details.
          – Jacky
          Dec 28 '18 at 3:38






          Does that mean Every object, in addition to having an associated monitor, has an associated wait set. its wait set is empty. is just a conceptual description, not involved with implementation details.
          – Jacky
          Dec 28 '18 at 3:38






          1




          1




          Yes, that's correct.
          – Louis Wasserman
          Dec 28 '18 at 3:46




          Yes, that's correct.
          – Louis Wasserman
          Dec 28 '18 at 3:46












          Indeed that's correct
          – Erwin Bolwidt
          Dec 28 '18 at 4:01




          Indeed that's correct
          – Erwin Bolwidt
          Dec 28 '18 at 4:01



          S4I,h4c,hBFFfDVyVAecKK OcS
          83Sx6jPnQGjuo5RO eFX 02F,t,WaTC,NT36 mTgxg,1HZFb0xv,rJrxdbZ,YiIKV8fRDQzBRzEG

          Popular posts from this blog

          Monofisismo

          compose and upload a new article using a custom form

          “attempting to read past stream EOM” using Sybase.AdoNet4.AseClient