rev 4213 : 8008382: Remove redundant use of Atomic::add(jlong, jlong *) in create_new_gc_id()
Summary: There is no need to use atomics in create_new_gc_id() since it is not called by multiple threads in parallel. Also, Atomic::add(jlong, jlong *) is broken for ARM.
Reviewed-by:

   1 /*
   2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "gc_implementation/shared/gcHeapSummary.hpp"
  27 #include "gc_implementation/shared/gcTimer.hpp"
  28 #include "gc_implementation/shared/gcTrace.hpp"
  29 #include "memory/referenceProcessorStats.hpp"
  30 #include "runtime/atomic.hpp"
  31 #include "utilities/globalDefinitions.hpp"
  32 
  33 #define assert_unset_gc_id() assert(_shared_gc_info.id() == SharedGCInfo::UNSET_GCID, "GC already started?")
  34 #define assert_set_gc_id() assert(_shared_gc_info.id() != SharedGCInfo::UNSET_GCID, "GC not started?")
  35 
  36 static volatile jlong GCTracer_next_gc_id = 0;
  37 static GCId create_new_gc_id() {
  38   return Atomic::add((jlong)1, &GCTracer_next_gc_id);
  39 }
  40 
  41 void GCTracer::report_gc_start_impl(GCCause::Cause cause, jlong timestamp) {
  42   assert_unset_gc_id();
  43 
  44   GCId gc_id = create_new_gc_id();
  45   _shared_gc_info.set_id(gc_id);
  46   _shared_gc_info.set_cause(cause);
  47   _shared_gc_info.set_start_timestamp(timestamp);
  48 }
  49 
  50 void GCTracer::report_gc_start(GCCause::Cause cause, jlong timestamp) {
  51   assert_unset_gc_id();
  52 
  53   report_gc_start_impl(cause, timestamp);
  54 }
  55 
  56 bool GCTracer::has_reported_gc_start() const {
  57   return _shared_gc_info.id() != SharedGCInfo::UNSET_GCID;
  58 }
  59 
  60 void GCTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) {
  61   assert_set_gc_id();
  62 
  63   _shared_gc_info.set_sum_of_pauses(time_partitions->sum_of_pauses());
  64   _shared_gc_info.set_longest_pause(time_partitions->longest_pause());
  65   _shared_gc_info.set_end_timestamp(timestamp);
  66 
  67   send_phase_events(time_partitions);
  68   send_garbage_collection_event();
  69 }
  70 
  71 void GCTracer::report_gc_end(jlong timestamp, TimePartitions* time_partitions) {
  72   assert_set_gc_id();
  73 
  74   report_gc_end_impl(timestamp, time_partitions);
  75 
  76   _shared_gc_info.set_id(SharedGCInfo::UNSET_GCID);
  77 }
  78 
  79 void GCTracer::report_gc_reference_processing(const ReferenceProcessorStats& rps) const {
  80   assert_set_gc_id();
  81 
  82   send_reference_processing_event(REF_SOFT, rps.soft_count());
  83   send_reference_processing_event(REF_WEAK, rps.weak_count());
  84   send_reference_processing_event(REF_FINAL, rps.final_count());
  85   send_reference_processing_event(REF_PHANTOM, rps.phantom_count());
  86 }
  87 
  88 void GCTracer::report_gc_heap_summary(GCWhen::Type when, const GCHeapSummary& heap_summary, const PermGenSummary& perm_gen_summary) const {
  89   assert_set_gc_id();
  90 
  91   send_gc_heap_summary_event(when, heap_summary);
  92   send_perm_gen_summary_event(when, perm_gen_summary);
  93 }
  94 
  95 void YoungGCTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) {
  96   assert_set_gc_id();
  97 
  98   GCTracer::report_gc_end_impl(timestamp, time_partitions);
  99   send_young_gc_event();
 100 }
 101 
 102 void YoungGCTracer::report_promotion_failed(size_t size, uint count) {
 103   assert_set_gc_id();
 104 
 105   young_gc_info().register_promotion_failed();
 106   send_promotion_failed_event(size, count);
 107 }
 108 
 109 
 110 void OldGCTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) {
 111   assert_set_gc_id();
 112 
 113   GCTracer::report_gc_end_impl(timestamp, time_partitions);
 114   send_old_gc_event();
 115 }
 116 
 117 void ParallelOldTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) {
 118   assert_set_gc_id();
 119 
 120   OldGCTracer::report_gc_end_impl(timestamp, time_partitions);
 121   send_parallel_old_event();
 122 }
 123 
 124 void ParallelOldTracer::report_dense_prefix(void* dense_prefix) {
 125   assert_set_gc_id();
 126 
 127   _parallel_old_gc_info.report_dense_prefix(dense_prefix);
 128 }
 129 
 130 #ifndef SERIALGC
 131 void G1NewTracer::report_yc_type(G1YCType type) {
 132   assert_set_gc_id();
 133 
 134   _g1_young_gc_info.set_type(type);
 135 }
 136 
 137 void G1NewTracer::report_gc_end_impl(jlong timestamp, TimePartitions* time_partitions) {
 138   assert_set_gc_id();
 139 
 140   YoungGCTracer::report_gc_end_impl(timestamp, time_partitions);
 141   send_g1_young_gc_event();
 142 }
 143 #endif
--- EOF ---