Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.java.programmer > #5865

Re: Why "lock" functionality is introduced for all the objects?

From BGB <cr88192@hotmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Why "lock" functionality is introduced for all the objects?
Date 2011-07-05 12:15 -0700
Organization albasani.net
Message-ID <iuvo57$e5i$1@news.albasani.net> (permalink)
References <d0bb9e06-16f0-4282-a37e-47e9ca9630ec@r2g2000vbj.googlegroups.com> <alpine.DEB.2.00.1106302251380.3024@urchin.earth.li> <iuitc4$etp$1@speranza.aioe.org> <alpine.DEB.2.00.1107012123070.21859@urchin.earth.li> <iulgh3$7mq$1@speranza.aioe.org>

Show all headers | View raw


On 7/1/2011 3:08 PM, KitKat wrote:
> On 01/07/2011 4:40 PM, Tom Anderson wrote:
>> On Thu, 30 Jun 2011, KitKat wrote:
>>
>>> Are you sure that last one was a "chap"? "Tamiya" sounds rather
>>> feminine to me.
>>
>> Perhaps - and a quick google reveals that it is a girl's name in Hebrew.
>> However, in Japanese, i believe it's a family name, and that Tamiya
>> Onodera is Dr Tamiya's name written in the normal Japanese order,
>> putting his family name first. Although i could be wrong.
>
> ???
>
> Regardless of which, "Onodera" also sounds feminine.
>

grr... the name is not latin-based, not everything that ends in 'a' is 
female.

not like it is some guy with a name like "Chibichibi Hitomi" or 
something, which would be a bit suspect.


"anata wa des-ka?"
"chibi-chibi hitomi wa deeesuuu!" (meanwhile doing an imbalanced stance).

as other people look with a solidly "WTF?" expression upon hearing this.

another person stands up, puts his hands to his face, and a background 
voice exclaims "shaaku!" (IOW: "shock!").


>> The object's identity hash is shuffled between the object and its lock
>> according to whether it has an expanded lock or not.
>
> That would work, if that's what the second word in the object header
> normally is. Assuming it's the heap address at time of creation, and
> objects are aligned on word boundaries, the two least order bits of the
> identity hash are going to be zero, so you can use those bits for
> something else and mask them off to get the hash.
>
> On the other hand, that suggests a way to make object headers of only
> *one* word.
>
> Consider: how likely are we to have four billion vtables in a running
> 32-bit JVM? Let alone Long.MAX_VALUE - Long.MIN_VALUE + 1 in a 64-bit one?
>

well, that is the cost of full pointers probably.
everything is addressable.

storing type-IDs as an id-number can also work, then one fetches the 
vtable/... via an array index. a downside though is that this would have 
a potential performance impact, as additional operations are now needed 
to access the vtable.


or, one can reserve a chunk of memory (wherever it is) and subtract out 
the address. then one can re-add the relative address to the base address.

say, a 64-bit base address known to the VM, and only a 32-bit relative 
address is stored in the object (possibly shifted right 3 bits with the 
top-3 used for the lock).

in x86-64, this can be done mostly with a single instruction, say:
lea rcx, [rbx+rax*8]

or, say, one calls a method (rdx=object, rbx=magic base pointer):
mov eax, [rdx]           ;fetch vtable word from object
mov ecx, [rbx+rax*8+72]  ;access vtable entry at offset 72
lea r8, [rbx+rcx]        ;add method address to base
call r8                  ;call method


> Reserve a low chunk of the address space (and call it part of permgen?)
> for vtables and your vtable pointers get quite short. The vtable pointer
> plus a few bits of the object's initial address would still make a
> pretty decent identity hash for collections with heterogeneous keys;
> homogeneous keys, in my experience, are usually value objects with
> overridden hashCode such as Strings and you can make the
> initial-address-bits (and the thin lock bit) the low order bits. Shift
> right one bit to lose the lock bit and have the hash; shift right n bits
> for some fairly small n to get the vtable pointer. Vtable lookup is a
> tiny bit slower due to a test of the lock bit plus one added shift
> instruction on each lookup, but the critical performance points tend to
> get JITted into direct calls or branch-predictable is-it-a-Foo?
> jump-or-normal-vtable-lookup choices. And the vast majority of
> production Java code is I/O bound anyway.
>
> Well, except when the object needs a fat lock. Then the whole word
> becomes a pointer to a structure that points to the vtable and contains
> the lock and identity hash. Now vtable lookup has an added indirection.
> But the bottleneck with such objects will usually be contention for the
> lock itself, not CPU cycles.
>


>> That might be memory-efficient, but it would not be at all
>> time-efficient, as it would require a map lookup to lock an object.
>
> Map lookups are O(1) and a low level implementation in C built into the
> JVM would boil down to masking and shifting the hash and then a pointer
> addition and dereference, only needed when you wanted to lock or unlock
> an object -- and again, the time spent on this will be dwarfed by the
> time spent in contention for the lock anyway, fairly often. Branch
> prediction and pipelining might help in the case of high-CPU areas that
> lock an object with low contention, in that some of the work might
> proceed in parallel with lock acquisition in the absence of contention
> (though, only as far as work that can be done in cache or registers,
> since the lock must be held prior to any memory reads or writes in the
> guarded object, and on initial acquisition failure that work may have to
> be repeated later on acquisitoon).

yep.

a table need not be all that expensive.

in my VM at least, interface method dispatch is itself done via the use 
of a hash table (as well as using a table for any object locking).


actually, a variant of the relative-address scheme is used as well on 
x86-64, but in this case more due to the x86-64 ISA generally using 
32-bit offsets for everything (calls/jumps/... are limited to 32-bits 
unless one wants to use GPRs to hold the temporary addresses, meaning it 
is much more efficient to try to have most of ones' JITted code/data be 
within a +-2GB window).

in this case, calls outside of this window are generally handled via 
trampolines within the window.

in effect, this window forms an "executable heap". granted, currently 
the whole region is read/write/execute, where I guess on some systems 
SELinux may make a problem for this, but I have yet to address this 
(seems to work fine on my systems... mostly tested with Fedora x86-64).

(note: I also target Win64 and Win32 as well, with Win64 being done in 
roughly the same way, and all this being N/A to Win32).

sadly, the region currently uses manual-MM. the GC can scan the region 
for references, but code/data/bss sections are not automatically 
reclaimed, as I found out after initial implementation that this would 
create serious implementation problems, and so instead opted with using 
different executable memory for GCed code, as well as it having to 
follow special rules, ...


current setup:
4GB RWX (combined code/data/bss, allocation starts from the middle and 
follows an even/odd "spiral" pattern).

theoretically, one would have to double-map the code-heap in this case, say:
2GB RX (code/rodata), 2GB RW (data/bss), 2GB RW (alias for code-heap)
or:
2GB RX (code/rodata), 2GB RW (data/bss, alias to first region)


presumably, the standard JVM does something similar internally?...


in the hypothetical object situation, this region would also be used for 
object vtables/... as well (but, as given before, would additionally 
require a region-base pointer, that or use relative addresses, which 
have their own complexities, and require "movsx rax, dword [...]" 
instructions).


or such...

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Why "lock" functionality is introduced for all the objects? Alex J <vstrength@gmail.com> - 2011-06-28 02:29 -0700
  Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 07:33 -0400
    OT "sic" (was Re: Why "lock" functionality is introduced for all the objects? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-06-28 15:56 +0000
      Re: OT "sic" (was Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 12:19 -0400
    Re: Why "lock" functionality is introduced for all the objects? Michal Kleczek <kleku75@gmail.com> - 2011-06-28 18:41 +0200
      Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 13:10 -0400
        Re: Why "lock" functionality is introduced for all the objects? Michal Kleczek <kleku75@gmail.com> - 2011-06-28 19:53 +0200
          Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 14:13 -0400
            Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-28 14:23 -0400
              Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 14:33 -0400
                Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-28 14:52 -0400
                Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 16:20 -0400
                Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-29 00:53 -0400
                Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-29 01:04 -0400
                Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-29 01:43 -0400
              Re: Why "lock" functionality is introduced for all the objects? Patricia Shanahan <pats@acm.org> - 2011-06-28 11:42 -0700
                Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-28 14:54 -0400
                Re: Why "lock" functionality is introduced for all the objects? Patricia Shanahan <pats@acm.org> - 2011-06-28 12:34 -0700
                Re: Why "lock" functionality is introduced for all the objects? markspace <-@.> - 2011-06-28 13:20 -0700
                Re: Why "lock" functionality is introduced for all the objects? Patricia Shanahan <pats@acm.org> - 2011-06-28 13:44 -0700
                Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-29 01:05 -0400
                Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 16:21 -0400
                Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-29 01:06 -0400
                Re: Why "lock" functionality is introduced for all the objects? BGB <cr88192@hotmail.com> - 2011-06-28 14:30 -0700
          Re: Why "lock" functionality is introduced for all the objects? Robert Klemme <shortcutter@googlemail.com> - 2011-06-29 18:56 +0200
      Re: Why "lock" functionality is introduced for all the objects? BGB <cr88192@hotmail.com> - 2011-06-28 13:43 -0700
        Re: Why "lock" functionality is introduced for all the objects? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-06-28 20:43 -0400
          Re: Why "lock" functionality is introduced for all the objects? BGB <cr88192@hotmail.com> - 2011-06-28 21:14 -0700
        Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-06-29 01:12 -0400
          Re: Why "lock" functionality is introduced for all the objects? Joshua Maurice <joshuamaurice@gmail.com> - 2011-07-01 18:28 -0700
            Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-02 00:19 -0400
          Re: Why "lock" functionality is introduced for all the objects? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-07-01 19:05 -0700
            Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-02 00:26 -0400
            Re: Why "lock" functionality is introduced for all the objects? BGB <cr88192@hotmail.com> - 2011-07-04 09:39 -0700
              Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-05 02:11 -0400
    Re: Why "lock" functionality is introduced for all the objects? Alex J <vstrength@gmail.com> - 2011-07-05 16:56 -0700
      Re: Why "lock" functionality is introduced for all the objects? "John B. Matthews" <nospam@nospam.invalid> - 2011-07-06 00:57 -0400
      Re: Why "lock" functionality is introduced for all the objects? supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-07-06 05:55 -0400
  Re: Why "lock" functionality is introduced for all the objects? Lew <noone@lewscanon.com> - 2011-06-28 14:40 -0400
  Re: Why "lock" functionality is introduced for all the objects? Robert Klemme <shortcutter@googlemail.com> - 2011-06-29 19:15 +0200
  Re: Why "lock" functionality is introduced for all the objects? Tom Anderson <twic@urchin.earth.li> - 2011-06-30 23:04 +0100
    Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-06-30 18:29 -0400
      Re: Why "lock" functionality is introduced for all the objects? Patricia Shanahan <pats@acm.org> - 2011-06-30 17:05 -0700
        Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-06-30 20:17 -0400
          Re: Why "lock" functionality is introduced for all the objects? Tom Anderson <twic@urchin.earth.li> - 2011-07-01 21:22 +0100
      Re: Why "lock" functionality is introduced for all the objects? Tom Anderson <twic@urchin.earth.li> - 2011-07-01 21:40 +0100
        Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-01 18:08 -0400
          Re: Why "lock" functionality is introduced for all the objects? BGB <cr88192@hotmail.com> - 2011-07-05 12:15 -0700
            Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-05 15:30 -0400
              Re: Why "lock" functionality is introduced for all the objects? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-05 21:10 +0000
                Re: Why "lock" functionality is introduced for all the objects? BGB <cr88192@hotmail.com> - 2011-07-05 22:08 -0700
                Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-06 05:57 -0400
                Re: Why "lock" functionality is introduced for all the objects? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-06 17:07 +0000
                Re: Why "lock" functionality is introduced for all the objects? Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-07 04:08 +1000
                Re: Why "lock" functionality is introduced for all the objects? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-06 19:09 +0000
                Re: Why "lock" functionality is introduced for all the objects? Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-07 09:26 +1000
                Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-06 20:25 -0400
                Re: Why "lock" functionality is introduced for all the objects? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-07 19:37 +0000
                Re: Why "lock" functionality is introduced for all the objects? blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-07 19:35 +0000
                Re: Why "lock" functionality is introduced for all the objects? Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-07 14:34 -0700
                OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-08 17:19 +0000
                Re: OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-09 05:41 +1000
                Re: OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-08 19:58 +0000
                Re: OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) lewbloch <lewbloch@gmail.com> - 2011-07-08 13:45 -0700
                Re: OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-10 01:50 -0400
                Re: OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) blmblm@myrealbox.com <blmblm.myrealbox@gmail.com> - 2011-07-10 19:15 +0000
                Re: OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) KitKat <kitkat_11697@gmail.example.com> - 2011-07-10 18:38 -0400
                Re: OT names/nyms/etc. (was Re: Why "lock" functionality is introduced for all the objects?) KitKat <kitkat_11697@gmail.example.com> - 2011-07-09 00:29 -0400
                Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-09 00:26 -0400
                Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-06 20:05 -0400
                Re: Why "lock" functionality is introduced for all the objects? Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-07 10:24 +1000
                Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-06 21:52 -0400
                Re: Why "lock" functionality is introduced for all the objects? Steve Erwin <trollHunter@Usenet.4.usenetizens.org.invalid> - 2011-07-07 12:43 +1000
                Re: Why "lock" functionality is introduced for all the objects? KitKat <kitkat_11697@gmail.example.com> - 2011-07-06 23:00 -0400

csiph-web