Return-Path: X-Original-To: apmail-devicemap-dev-archive@www.apache.org Delivered-To: apmail-devicemap-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3691310008 for ; Tue, 30 Dec 2014 16:07:18 +0000 (UTC) Received: (qmail 7152 invoked by uid 500); 30 Dec 2014 16:07:18 -0000 Delivered-To: apmail-devicemap-dev-archive@devicemap.apache.org Received: (qmail 7115 invoked by uid 500); 30 Dec 2014 16:07:18 -0000 Mailing-List: contact dev-help@devicemap.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@devicemap.apache.org Delivered-To: mailing list dev@devicemap.apache.org Received: (qmail 7095 invoked by uid 99); 30 Dec 2014 16:07:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Dec 2014 16:07:16 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of volkan.yazici@gmail.com designates 209.85.215.45 as permitted sender) Received: from [209.85.215.45] (HELO mail-la0-f45.google.com) (209.85.215.45) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Dec 2014 16:06:51 +0000 Received: by mail-la0-f45.google.com with SMTP id gq15so12824649lab.32 for ; Tue, 30 Dec 2014 08:06:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=xn6gekmi5LHO6Tx5UjnLdAfLsUE2bhsDQtUB6DEIeJM=; b=oB+zF4/dKzn2tbjHPomK0exeO4qpPdqZTKR8ZZnCcyhhG3V9Wk3+/FhAStRitm0gN0 aVK7TPqz34ospPLMl0wbtxvS4UhiUh/xhx0V79TQkNBA7h9LE+Tu4P/O+P7xeHuR4Zbz QHdA1J17fONxsoG/XdHnXwwspnh15uNvpDVKC2zFfsBk1d+aCjbE7pPAKMGElrofztt6 rzScyI2EjQuveWlbumScNQZl/PLGanqrDpL0/pXHKwcDaDZQmXNay9IJU+UO9YSVVvcL wsU9hCWlSjX5w5DjMBbt4I6smdonTDENdSPlwcMiSTEXJAlQ+w26Ob6TlOp/m6CIze8B VzDA== MIME-Version: 1.0 X-Received: by 10.112.50.239 with SMTP id f15mr61957135lbo.31.1419955565139; Tue, 30 Dec 2014 08:06:05 -0800 (PST) Received: by 10.112.141.2 with HTTP; Tue, 30 Dec 2014 08:06:05 -0800 (PST) In-Reply-To: <86wjeix8pap79lxoxqmd84l4.1419953466053@email.android.com> References: <86wjeix8pap79lxoxqmd84l4.1419953466053@email.android.com> Date: Tue, 30 Dec 2014 17:06:05 +0100 Message-ID: Subject: Re: Pattern.rank From: =?UTF-8?B?Vm9sa2FuIFlhesSxY8Sx?= To: "dev@devicemap.apache.org" Content-Type: multipart/alternative; boundary=001a113368d40e9b43050b712b48 X-Virus-Checked: Checked by ClamAV on apache.org --001a113368d40e9b43050b712b48 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Honestly, I believe JMM is *rocket science* and I am not an expert on the subject -- which is also apparent from my wrong alarm. That being said, these materials might get you warmed up: - TSM01-J. Do not let the this reference escape during object construction - TSM03-J. Do not publish partially initialized objects - Safe Object Publication in Java - Safe Publication and Safe Initialization in Java Let me briefly explain what I understand from the Pattern class issue: class A { final int x, y; A(int x) { this.x =3D x; this.y =3D f(); } int f() { return x; } } This is totally safe, since "final" fields enforce a happens-before relationship. class A { int x, y; A(int x) { this.x =3D x; this.y =3D f(); } int f() { return x; } } This is also safe, because JMM allows optimizations (e.g. assignment re-ordering) such that a single-threaded execution should always produce the same output. class A { static A a; *int* x; A(int x) { this.x =3D x; a =3D this; } } This is unsafe, we leaked "this" prior to initialization. Another thread accessing A.a instance might observe an uninitialized x. I think I mis-interpreted the "An object is in a predictable, consistent state only after its constructor returns" statement from JCP book. I will consider this case more thoroughly tomorrow, maybe even write a blog post about it. On Tue, Dec 30, 2014 at 4:31 PM, Reza Naghibi < reza.naghibi@yahoo.com.invalid> wrote: > Is this because the JVM may optimize and reorder the code? So I come from > a c and assembly background, just trying to better understand... :) > > > > >
-------- Original message --------
From: Volkan Yaz=C4=B1c= =C4=B1 < > volkan.yazici@gmail.com>
Date:12/30/2014 9:55 AM (GMT-05:00) >
To: dev@devicemap.apache.org
Cc: >
Subject: Re: Pattern.rank
>
You're right Reza, it is not unsafe. I confused it with leaking > "this" in > ctor -- even in that case "final" modifier of the fields impose the > happens-before relationship constraint, which is also fine. It needed qui= te > some debate on FreeNode to get things resolved. Sorry for the wrong alarm= . > > > On Tue, Dec 30, 2014 at 3:04 PM, Reza Naghibi < > reza.naghibi@yahoo.com.invalid> wrote: > > > Hmm... can you provide a reference or some kind of example showing that= a > > single threaded read after write is unreliable? I'm thinking if this is > > true, huge swaths of programs would be deemed unsafe since read after > write > > is quite a common memory pattern... :) No? > > > > > > > >
-------- Original message --------
From: Volkan Yaz=C4= =B1c=C4=B1 < > > volkan.yazici@gmail.com>
Date:12/30/2014 8:31 AM > (GMT-05:00) > >
To: dev@devicemap.apache.org
Cc: > >
Subject: Re: Pattern.rank
> >
A related excerpt from the Java Concurrency in Practice: "An obje= ct > > is in a > > predictable, consistent state only after its constructor returns, ..." = In > > its current form of Pattern: > > > > Pattern(...) { > > ... > > this.boost =3D boost; > > this.rank =3D rank(); > > } > > > > public long rank() { > > // access to this.boost > > } > > > > > > this.boost might not have been completely initialized when rank() tries > to > > access to it. > > > > On Tue, Dec 30, 2014 at 2:14 PM, Reza Naghibi < > > reza.naghibi@yahoo.com.invalid> wrote: > > > > > Interesting... you cannot access instance variables in the constructo= r? > > > > > > Also, this hasn't been fully implemented. Boost is going to be a DRR > > > pattern attribute which will allow 1 pattern to be configured to rank > > > higher than another. > > > > > > > > > > > > > > >
-------- Original message --------
From: Volkan YAZICI= < > > > volkan.yazici@gmail.com>
Date:12/30/2014 4:41 AM > > (GMT-05:00) > > >
To: dev@devicemap.apache.org
Cc: > > >
Subject: Pattern.rank
> > >
Hi, > > > > > > I have an objection and a question about Pattern class in Java client= . > > > > > > *Objection:* Pattern.rank() instance method gets called in ctor and > > > accesses to instance variables, which might not have been initialized > yet > > > due to JMM semantics. I propose to fix it as in DMAP-115 > > > . > > > > > > *Question:* Shall we remove boost option on Pattern ctor? It is neith= er > > > used, nor available in .NET client. > > > > > > Best. > > > > > > --001a113368d40e9b43050b712b48--