title: Boxing/unboxing costs and do boxed objects have copy on write?
body: <p>From what I understand, Java has boxed (heap) and unboxed (stack) variables, and if I assign a boxed type to an unboxed type or vice-versa there is a(n) (un)boxing cost involved.</p>
  <p>Is unboxing cheaper than allocating a new boxed object? And do boxed objects support COW if used readonly?</p>
  <pre class="lang-java prettyprint-override"><code>class MyClass {
     public String myString;
     public Long myLong;
     public MyClass(String s, Long l) {
        myString = s;
        myLong = l;
     }
  }
  
  MyClass cls = new MyClass(&quot;A string&quot;, 5L);
  Long l2 = cls.myLong; // does l2 and cls.myLong share memory or is new memory allocated here?
  if (l2 &lt; 10) {
     l2 += 5; // now l2 must have its own memory
  }
  </code></pre>