src/hotspot/share/jfr/recorder/stringpool/jfrStringPool.cpp
author egahlin
Tue, 15 May 2018 20:24:34 +0200
changeset 50113 caf115bb98ad
child 50429 83aec1d357d4
permissions -rw-r--r--
8199712: Flight Recorder Reviewed-by: coleenp, ihse, erikj, dsamersoff, mseledtsov, egahlin, mgronlun Contributed-by: erik.gahlin@oracle.com, markus.gronlund@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#include "classfile/javaClasses.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
#include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdEpoch.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "jfr/recorder/service/jfrOptionSet.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "jfr/recorder/storage/jfrMemorySpace.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    30
#include "jfr/recorder/repository/jfrChunkWriter.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    31
#include "jfr/recorder/storage/jfrStorageUtils.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
#include "jfr/recorder/stringpool/jfrStringPool.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    33
#include "jfr/recorder/stringpool/jfrStringPoolWriter.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
#include "jfr/utilities/jfrTypes.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
#include "logging/log.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
#include "runtime/atomic.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
#include "runtime/mutexLocker.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
#include "runtime/orderAccess.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
#include "runtime/safepoint.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
#include "runtime/thread.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
typedef JfrStringPool::Buffer* BufferPtr;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
static JfrStringPool* _instance = NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
JfrStringPool& JfrStringPool::instance() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
  return *_instance;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
JfrStringPool* JfrStringPool::create(JfrChunkWriter& cw) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
  assert(_instance == NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
  _instance = new JfrStringPool(cw);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
  return _instance;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
void JfrStringPool::destroy() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
  assert(_instance != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
  delete _instance;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
  _instance = NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
JfrStringPool::JfrStringPool(JfrChunkWriter& cw) : _free_list_mspace(NULL), _lock(NULL), _chunkwriter(cw) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
JfrStringPool::~JfrStringPool() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
  if (_free_list_mspace != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
    delete _free_list_mspace;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    67
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    68
  if (_lock != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    69
    delete _lock;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    70
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    71
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    72
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    73
static const size_t unlimited_mspace_size = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    74
static const size_t string_pool_cache_count = 2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    75
static const size_t string_pool_buffer_size = 512 * K;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    76
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    77
bool JfrStringPool::initialize() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    78
  assert(_free_list_mspace == NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    79
  _free_list_mspace = new JfrStringPoolMspace(string_pool_buffer_size, unlimited_mspace_size, string_pool_cache_count, this);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    80
  if (_free_list_mspace == NULL || !_free_list_mspace->initialize()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    81
    return false;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    82
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
  assert(_lock == NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
  _lock = new Mutex(Monitor::leaf - 1, "Checkpoint mutex", Mutex::_allow_vm_block_flag, Monitor::_safepoint_check_never);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
  return _lock != NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    86
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
* If the buffer was a "lease" from the global system, release back.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
* The buffer is effectively invalidated for the thread post-return,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
* and the caller should take means to ensure that it is not referenced any longer.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
*/
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
static void release(BufferPtr buffer, Thread* thread) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
  assert(buffer != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
  assert(buffer->lease(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
  assert(buffer->acquired_by_self(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
  buffer->clear_lease();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
  buffer->release();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
BufferPtr JfrStringPool::flush(BufferPtr old, size_t used, size_t requested, Thread* thread) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
  assert(old != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
  assert(old->lease(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
  if (0 == requested) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   106
    // indicates a lease is being returned
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   107
    release(old, thread);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   108
    return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   109
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   110
  // migration of in-flight information
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   111
  BufferPtr const new_buffer = lease_buffer(thread, used + requested);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   112
  if (new_buffer != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   113
    migrate_outstanding_writes(old, new_buffer, used, requested);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
  release(old, thread);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
  return new_buffer; // might be NULL
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   117
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   119
static const size_t lease_retry = 10;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   120
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   121
BufferPtr JfrStringPool::lease_buffer(Thread* thread, size_t size /* 0 */) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   122
  BufferPtr buffer = mspace_get_free_lease_with_retry(size, instance()._free_list_mspace, lease_retry, thread);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   123
  if (buffer == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   124
    buffer = mspace_allocate_transient_lease_to_free(size,  instance()._free_list_mspace, thread);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   125
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   126
  assert(buffer->acquired_by_self(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   127
  assert(buffer->lease(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   128
  return buffer;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   129
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   130
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   131
bool JfrStringPool::add(bool epoch, jlong id, jstring string, JavaThread* jt) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   132
  assert(jt != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   133
  const bool current_epoch = JfrTraceIdEpoch::epoch();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   134
  if (current_epoch == epoch) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   135
    JfrStringPoolWriter writer(jt);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   136
    writer.write(id);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   137
    writer.write(string);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   138
    writer.inc_nof_strings();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   139
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   140
  return current_epoch;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   141
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   142
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   143
class StringPoolWriteOp  {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   144
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   145
  typedef JfrStringPoolBuffer Type;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   146
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   147
  UnBufferedWriteToChunk<Type> _writer;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   148
  Thread* _thread;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   149
  size_t _strings_processed;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   150
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   151
  StringPoolWriteOp(JfrChunkWriter& writer, Thread* thread) : _writer(writer), _thread(thread), _strings_processed(0) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   152
  bool write(Type* buffer, const u1* data, size_t size) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   153
    buffer->acquire(_thread); // blocking
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   154
    const u4 nof_strings_used = (const u4)buffer->string_count();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   155
    assert(nof_strings_used > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   156
    buffer->set_string_top(buffer->string_top() + nof_strings_used);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   157
    // "size processed" for string pool buffers is the number of processed string elements
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   158
    _strings_processed += nof_strings_used;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   159
    const bool ret = _writer.write(buffer, data, size);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   160
    buffer->release();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   161
    return ret;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   162
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   163
  size_t processed() { return _strings_processed; }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   164
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   165
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   166
typedef StringPoolWriteOp WriteOperation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   167
typedef ConcurrentWriteOp<WriteOperation> ConcurrentWriteOperation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   168
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   169
size_t JfrStringPool::write() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   170
  Thread* const thread = Thread::current();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   171
  WriteOperation wo(_chunkwriter, thread);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   172
  ConcurrentWriteOperation cwo(wo);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   173
  assert(_free_list_mspace->is_full_empty(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   174
  process_free_list(cwo, _free_list_mspace);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   175
  return wo.processed();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   176
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   177
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   178
typedef MutexedWriteOp<WriteOperation> MutexedWriteOperation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   179
typedef ReleaseOp<JfrStringPoolMspace> StringPoolReleaseOperation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   180
typedef CompositeOperation<MutexedWriteOperation, StringPoolReleaseOperation> StringPoolWriteOperation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   181
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   182
size_t JfrStringPool::write_at_safepoint() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   183
  assert(SafepointSynchronize::is_at_safepoint(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   184
  Thread* const thread = Thread::current();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   185
  WriteOperation wo(_chunkwriter, thread);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   186
  MutexedWriteOperation mwo(wo);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   187
  StringPoolReleaseOperation spro(_free_list_mspace, thread, false);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   188
  StringPoolWriteOperation spwo(&mwo, &spro);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   189
  assert(_free_list_mspace->is_full_empty(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   190
  process_free_list(spwo, _free_list_mspace);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   191
  return wo.processed();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   192
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   193
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   194
class StringPoolBufferDiscarder {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   195
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   196
  Thread* _thread;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   197
  size_t _processed;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   198
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   199
  typedef JfrStringPoolBuffer Type;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   200
  StringPoolBufferDiscarder() : _thread(Thread::current()), _processed(0) {}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   201
  bool process(Type* buffer) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   202
    buffer->acquire(_thread); // serialized access
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   203
    const u1* const current_top = buffer->top();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   204
    const size_t unflushed_size = buffer->pos() - current_top;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   205
    if (unflushed_size == 0) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   206
      assert(buffer->string_count() == 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   207
      buffer->release();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   208
      return true;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   209
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   210
    buffer->set_top(current_top + unflushed_size);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   211
    const u4 nof_strings_used = buffer->string_count();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   212
    buffer->set_string_top(buffer->string_top() + nof_strings_used);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   213
    // "size processed" for string pool buffers is the number of string elements
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   214
    _processed += nof_strings_used;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   215
    buffer->release();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   216
    return true;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   217
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   218
  size_t processed() const { return _processed; }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   219
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   220
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   221
size_t JfrStringPool::clear() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   222
  StringPoolBufferDiscarder discard_operation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   223
  assert(_free_list_mspace->is_full_empty(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   224
  process_free_list(discard_operation, _free_list_mspace);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   225
  return discard_operation.processed();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   226
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   227
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   228
void JfrStringPool::register_full(BufferPtr t, Thread* thread) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   229
  // nothing here at the moment
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   230
  assert(t->retired(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   231
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   232
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   233
void JfrStringPool::lock() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   234
  assert(!_lock->owned_by_self(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   235
  _lock->lock_without_safepoint_check();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   236
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   237
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   238
void JfrStringPool::unlock() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   239
  _lock->unlock();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   240
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   241
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   242
#ifdef ASSERT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   243
bool JfrStringPool::is_locked() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   244
  return _lock->owned_by_self();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   245
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   246
#endif