Return-Path: X-Original-To: apmail-lucene-dev-archive@www.apache.org Delivered-To: apmail-lucene-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 9F5B395A2 for ; Fri, 16 Mar 2012 22:59:03 +0000 (UTC) Received: (qmail 60722 invoked by uid 500); 16 Mar 2012 22:59:02 -0000 Delivered-To: apmail-lucene-dev-archive@lucene.apache.org Received: (qmail 60669 invoked by uid 500); 16 Mar 2012 22:59:02 -0000 Mailing-List: contact dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list dev@lucene.apache.org Received: (qmail 60652 invoked by uid 99); 16 Mar 2012 22:59:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Mar 2012 22:59:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Mar 2012 22:59:00 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 911A82310E for ; Fri, 16 Mar 2012 22:58:40 +0000 (UTC) Date: Fri, 16 Mar 2012 22:58:40 +0000 (UTC) From: "Uwe Schindler (Commented) (JIRA)" To: dev@lucene.apache.org Message-ID: <739203394.26901.1331938720598.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <465341840.11785.1331706218099.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (LUCENE-3867) RamUsageEstimator.NUM_BYTES_ARRAY_HEADER and other constants are incorrect MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LUCENE-3867?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D132= 31719#comment-13231719 ]=20 Uwe Schindler commented on LUCENE-3867: --------------------------------------- bq. I don't think it's "fixed" =E2=80=93 see the -XX:ObjectAlignmentInBytes= =3D32 above. But the defaults seem to be the same on all systems. I would like to have the rounding also dynamic, but this is not possible to= find out with Unsafe, at least for this I have no idea :( =20 > RamUsageEstimator.NUM_BYTES_ARRAY_HEADER and other constants are incorrec= t > -------------------------------------------------------------------------= - > > Key: LUCENE-3867 > URL: https://issues.apache.org/jira/browse/LUCENE-3867 > Project: Lucene - Java > Issue Type: Bug > Components: core/index > Reporter: Shai Erera > Assignee: Shai Erera > Priority: Trivial > Fix For: 3.6, 4.0 > > Attachments: LUCENE-3867-compressedOops.patch, LUCENE-3867.patch,= LUCENE-3867.patch, LUCENE-3867.patch, LUCENE-3867.patch, LUCENE-3867.patch= , LUCENE-3867.patch, LUCENE-3867.patch, LUCENE-3867.patch, LUCENE-3867.patc= h > > > RamUsageEstimator.NUM_BYTES_ARRAY_HEADER is computed like that: NUM_BYTES= _OBJECT_HEADER + NUM_BYTES_INT + NUM_BYTES_OBJECT_REF. The NUM_BYTES_OBJECT= _REF part should not be included, at least not according to this page: http= ://www.javamex.com/tutorials/memory/array_memory_usage.shtml > {quote} > A single-dimension array is a single object. As expected, the array has t= he usual object header. However, this object head is 12 bytes to accommodat= e a four-byte array length. Then comes the actual array data which, as you = might expect, consists of the number of elements multiplied by the number o= f bytes required for one element, depending on its type. The memory usage f= or one element is 4 bytes for an object reference ... > {quote} > While on it, I wrote a sizeOf(String) impl, and I wonder how do people fe= el about including such helper methods in RUE, as static, stateless, method= s? It's not perfect, there's some room for improvement I'm sure, here it is= : > {code} > =09/** > =09 * Computes the approximate size of a String object. Note that if this= object > =09 * is also referenced by another object, you should add > =09 * {@link RamUsageEstimator#NUM_BYTES_OBJECT_REF} to the result of thi= s > =09 * method. > =09 */ > =09public static int sizeOf(String str) { > =09=09return 2 * str.length() + 6 // chars + additional safeness for arra= ys alignment > =09=09=09=09+ 3 * RamUsageEstimator.NUM_BYTES_INT // String maintains 3 i= ntegers > =09=09=09=09+ RamUsageEstimator.NUM_BYTES_ARRAY_HEADER // char[] array > =09=09=09=09+ RamUsageEstimator.NUM_BYTES_OBJECT_HEADER; // String object > =09} > {code} > If people are not against it, I'd like to also add sizeOf(int[] / byte[] = / long[] / double[] ... and String[]). -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrato= rs: https://issues.apache.org/jira/secure/ContactAdministrators!default.jsp= a For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org For additional commands, e-mail: dev-help@lucene.apache.org