From patchwork Fri Jul 27 12:59:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurynas Biveinis X-Patchwork-Id: 173665 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 7EA902C007E for ; Fri, 27 Jul 2012 23:00:22 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343998822; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=SGpqFHn +oRzS+8C79eAwbfmtK1k=; b=IZADQ9xTrd8bYloESIwU8VoWBnXthXM9cMYMHgd Kx+58duL6hXIY45cvz8fWH8TOwXTbzB5xdeknDxHOy/o99yqACDcJGif3xK/kXIG hgcWA4Xdv+orZTxcROo7a6sXQdF7Mnrx8r8ds4Dg8c4kubOKYEc4m9zQUW7+xs9+ gjV8= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=pS7/FDX2WfiQCql2LX4n/Wowf6BsNq7IwO0GFES47XljW4U8Z7riFQhiVq4zjc 0hWzkA1s3u8kKptndg03Pw0rjxe9mjriAMdRhxlMnA87qDx/9MxzOETZQRCUBhpo nd0vpyd22ACOnyrD6Cx22k0WARf0zCwd2sJYXImHno0io=; Received: (qmail 3226 invoked by alias); 27 Jul 2012 13:00:15 -0000 Received: (qmail 3184 invoked by uid 22791); 27 Jul 2012 13:00:12 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE X-Spam-Check-By: sourceware.org Received: from mail-bk0-f47.google.com (HELO mail-bk0-f47.google.com) (209.85.214.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 27 Jul 2012 12:59:55 +0000 Received: by bkcik5 with SMTP id ik5so1682834bkc.20 for ; Fri, 27 Jul 2012 05:59:54 -0700 (PDT) Received: by 10.205.128.3 with SMTP id hc3mr981237bkc.29.1343393994073; Fri, 27 Jul 2012 05:59:54 -0700 (PDT) Received: from [192.168.0.3] (data-184-214.cgates.lt. [5.20.184.214]) by mx.google.com with ESMTPS id fu8sm926746bkc.5.2012.07.27.05.59.51 (version=SSLv3 cipher=OTHER); Fri, 27 Jul 2012 05:59:53 -0700 (PDT) Message-ID: <5012909E.5070309@gmail.com> Date: Fri, 27 Jul 2012 15:59:10 +0300 From: Laurynas Biveinis User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: gcc-patches@gcc.gnu.org Subject: [PATCH]: Use GTY atomic option for arrays, new atomic vector type X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This is a slightly expanded version of the patch in [1]. The main difference is that I expanded gengtype diagnostics to error on GTY length option applied to strings too, in addition to other arrays of atomic types. This in turn uncovered another place where a correct GTY option should be used . Java and libcpp parts are already approved. Tested on x86_64 linux, no regressions. OK for trunk? [1] http://gcc.gnu.org/ml/gcc-patches/2012-07/msg01204.html gcc: 2012-07-27 Laurynas Biveinis Steven Bosscher * gengtype.c (adjust_field_type): Diagnose duplicate "length" option applications and option being applied to arrays of atomic types. (walk_type): Allow "atomic" option on strings too. * dwarf2out.h (struct dw_vec_struct): Use the "atomic" GTY option for the array field. * vec.h: Describe the atomic object "A" type of the macros in the header comment. (VEC_T_GTY_ATOMIC, DEF_VEC_A, DEF_VEC_ALLOC_A): Define. * emit-rtl.c (locations_locators_vals): use the atomic object vector. * doc/gty.texi: Clarify that GTY option "length" is only for arrays of non-atomic objects. Fix typo in the description of the "atomic" option. gcc/java: 2012-07-24 Laurynas Biveinis * jcf.h (CPool): Use the "atomic" GTY option for the tags field. (bootstrap_method): Likewise for the bootstrap_arguments field. libcpp: 2012-07-24 Laurynas Biveinis * include/line-map.h (line_map_macro): Use the "atomic" GTY option for the macro_locations field. gcc: 2012-07-27 Laurynas Biveinis Steven Bosscher * gengtype.c (adjust_field_type): Diagnose duplicate "length" option applications and option being applied to arrays of atomic types. (walk_type): Allow "atomic" option on strings too. * dwarf2out.h (struct dw_vec_struct): Use the "atomic" GTY option for the array field. * vec.h: Describe the atomic object "A" type of the macros in the header comment. (VEC_T_GTY_ATOMIC, DEF_VEC_A, DEF_VEC_ALLOC_A): Define. * emit-rtl.c (locations_locators_vals): use the atomic object vector. * doc/gty.texi: Clarify that GTY option "length" is only for arrays of non-atomic objects. Fix typo in the description of the "atomic" option. gcc/java: 2012-07-24 Laurynas Biveinis * jcf.h (CPool): Use the "atomic" GTY option for the tags field. (bootstrap_method): Likewise for the bootstrap_arguments field. libcpp: 2012-07-24 Laurynas Biveinis * include/line-map.h (line_map_macro): Use the "atomic" GTY option for the macro_locations field. Index: gcc/gengtype.c =================================================================== --- gcc/gengtype.c (revision 189893) +++ gcc/gengtype.c (working copy) @@ -1256,7 +1256,17 @@ for (; opt; opt = opt->next) if (strcmp (opt->name, "length") == 0) - length_p = 1; + { + if (length_p) + error_at_line (&lexer_line, "duplicate `%s' option", opt->name); + if (t->u.p->kind == TYPE_SCALAR || t->u.p->kind == TYPE_STRING) + { + error_at_line (&lexer_line, + "option `%s' may not be applied to " + "arrays of atomic types", opt->name); + } + length_p = 1; + } else if ((strcmp (opt->name, "param_is") == 0 || (strncmp (opt->name, "param", 5) == 0 && ISDIGIT (opt->name[5]) @@ -2495,7 +2505,7 @@ return; } - if (atomic_p && (t->kind != TYPE_POINTER)) + if (atomic_p && (t->kind != TYPE_POINTER) && (t->kind != TYPE_STRING)) { error_at_line (d->line, "field `%s' has invalid option `atomic'\n", d->val); return; Index: gcc/dwarf2out.h =================================================================== --- gcc/dwarf2out.h (revision 189893) +++ gcc/dwarf2out.h (working copy) @@ -160,7 +160,7 @@ /* Describe a floating point constant value, or a vector constant value. */ typedef struct GTY(()) dw_vec_struct { - unsigned char * GTY((length ("%h.length"))) array; + unsigned char * GTY((atomic)) array; unsigned length; unsigned elt_size; } Index: gcc/vec.h =================================================================== --- gcc/vec.h (revision 189893) +++ gcc/vec.h (working copy) @@ -95,24 +95,25 @@ the 'space' predicate will tell you whether there is spare capacity in the vector. You will not normally need to use these two functions. - Vector types are defined using a DEF_VEC_{O,P,I}(TYPEDEF) macro, to + Vector types are defined using a DEF_VEC_{O,A,P,I}(TYPEDEF) macro, to get the non-memory allocation version, and then a - DEF_VEC_ALLOC_{O,P,I}(TYPEDEF,ALLOC) macro to get memory managed + DEF_VEC_ALLOC_{O,A,P,I}(TYPEDEF,ALLOC) macro to get memory managed vectors. Variables of vector type are declared using a VEC(TYPEDEF,ALLOC) macro. The ALLOC argument specifies the allocation strategy, and can be either 'gc' or 'heap' for garbage collected and heap allocated respectively. It can be 'none' to get a vector that must be explicitly allocated (for instance as a - trailing array of another structure). The characters O, P and I - indicate whether TYPEDEF is a pointer (P), object (O) or integral - (I) type. Be careful to pick the correct one, as you'll get an - awkward and inefficient API if you use the wrong one. There is a - check, which results in a compile-time warning, for the P and I - versions, but there is no check for the O versions, as that is not - possible in plain C. Due to the way GTY works, you must annotate - any structures you wish to insert or reference from a vector with a - GTY(()) tag. You need to do this even if you never declare the GC - allocated variants. + trailing array of another structure). The characters O, A, P and I + indicate whether TYPEDEF is a pointer (P), object (O), atomic object + (A) or integral (I) type. Be careful to pick the correct one, as + you'll get an awkward and inefficient API if you use the wrong one or + a even a crash if you pick the atomic object version when the object + version should have been chosen instead. There is a check, which + results in a compile-time warning, for the P and I versions, but there + is no check for the O versions, as that is not possible in plain C. + Due to the way GTY works, you must annotate any structures you wish to + insert or reference from a vector with a GTY(()) tag. You need to do + this even if you never declare the GC allocated variants. An example of their use would be, @@ -530,6 +531,13 @@ T GTY ((length ("%h.prefix.num"))) vec[1]; \ } VEC(T,B) +#define VEC_T_GTY_ATOMIC(T,B) \ +typedef struct GTY(()) VEC(T,B) \ +{ \ + struct vec_prefix prefix; \ + T GTY ((atomic)) vec[1]; \ +} VEC(T,B) + /* Derived vector type, user visible. */ #define VEC_TA_GTY(T,B,A,GTY) \ typedef struct GTY VEC(T,A) \ @@ -904,6 +912,14 @@ DEF_VEC_NONALLOC_FUNCS_O(T,A) \ struct vec_swallow_trailing_semi +/* Vector of atomic object. */ +#define DEF_VEC_A(T) \ +VEC_T_GTY_ATOMIC(T,base); \ +VEC_TA(T,base,none); \ +DEF_VEC_FUNC_O(T) \ +struct vec_swallow_trailing_semi +#define DEF_VEC_ALLOC_A(T,A) DEF_VEC_ALLOC_O(T,A) + #define DEF_VEC_FUNC_O(T) \ static inline unsigned VEC_OP (T,base,length) (const VEC(T,base) *vec_) \ { \ Index: gcc/java/jcf.h =================================================================== --- gcc/java/jcf.h (revision 189893) +++ gcc/java/jcf.h (working copy) @@ -82,7 +82,7 @@ /* The constant_pool_count. */ int count; - uint8* GTY((length ("%h.count"))) tags; + uint8 * GTY((atomic)) tags; union cpool_entry * GTY((length ("%h.count"), desc ("cpool_entry_is_tree (%1.tags%a)"))) data; @@ -91,7 +91,7 @@ typedef struct GTY(()) bootstrap_method { unsigned method_ref; unsigned num_arguments; - unsigned* GTY((length ("%h.num_arguments"))) bootstrap_arguments; + unsigned * GTY((atomic)) bootstrap_arguments; } bootstrap_method; typedef struct GTY(()) BootstrapMethods { Index: gcc/emit-rtl.c =================================================================== --- gcc/emit-rtl.c (revision 189893) +++ gcc/emit-rtl.c (working copy) @@ -5910,8 +5910,8 @@ static VEC(int,heap) *block_locators_locs; static GTY(()) VEC(tree,gc) *block_locators_blocks; static VEC(int,heap) *locations_locators_locs; -DEF_VEC_O(location_t); -DEF_VEC_ALLOC_O(location_t,heap); +DEF_VEC_A(location_t); +DEF_VEC_ALLOC_A(location_t,heap); static VEC(location_t,heap) *locations_locators_vals; int prologue_locator; int epilogue_locator; Index: gcc/doc/gty.texi =================================================================== --- gcc/doc/gty.texi (revision 189893) +++ gcc/doc/gty.texi (working copy) @@ -134,8 +134,8 @@ @item length ("@var{expression}") There are two places the type machinery will need to be explicitly told -the length of an array. The first case is when a structure ends in a -variable-length array, like this: +the length of an array of non-atomic objects. The first case is when a +structure ends in a variable-length array, like this: @smallexample struct GTY(()) rtvec_def @{ int num_elem; /* @r{number of elements} */ @@ -163,6 +163,11 @@ static GTY((length("reg_known_value_size"))) rtx *reg_known_value; @end verbatim +Note that the @code{length} option is only meant for use with arrays of +non-atomic objects, that is, objects that contain pointers pointing to +other GTY-managed objects. For other GC-allocated arrays and strings +you should use @code{atomic}. + @findex skip @item skip @@ -411,7 +416,7 @@ @smallexample struct GTY(()) my_struct @{ int number_of_elements; - unsigned int GTY ((atomic)) * elements; + unsigned int * GTY ((atomic)) elements; @}; @end smallexample In this case, @code{elements} is a pointer under GC, and the memory it Index: libcpp/include/line-map.h =================================================================== --- libcpp/include/line-map.h (revision 189893) +++ libcpp/include/line-map.h (working copy) @@ -165,7 +165,7 @@ In the example above x1 (for token "+") is going to be the same as y1. x0 is the spelling location for the argument token "1", and x2 is the spelling location for the argument token "2". */ - source_location * GTY((length ("2 * %h.n_tokens"))) macro_locations; + source_location * GTY((atomic)) macro_locations; /* This is the location of the expansion point of the current macro map. It's the location of the macro name. That location is held