src/hotspot/share/jfr/recorder/stringpool/jfrStringPool.hpp
changeset 50113 caf115bb98ad
child 53244 9807daeb47c4
equal deleted inserted replaced
50112:7a2a740815b7 50113:caf115bb98ad
       
     1 /*
       
     2  * Copyright (c) 2016, 2018, 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 #ifndef SHARE_VM_JFR_RECORDER_STRINGPOOL_JFRSTRINGPOOL_HPP
       
    26 #define SHARE_VM_JFR_RECORDER_STRINGPOOL_JFRSTRINGPOOL_HPP
       
    27 
       
    28 #include "jni.h"
       
    29 #include "jfr/recorder/storage/jfrMemorySpace.hpp"
       
    30 #include "jfr/recorder/storage/jfrMemorySpaceRetrieval.hpp"
       
    31 #include "jfr/recorder/stringpool/jfrStringPoolBuffer.hpp"
       
    32 
       
    33 class JfrChunkWriter;
       
    34 class JfrStringPool;
       
    35 class Mutex;
       
    36 
       
    37 typedef JfrMemorySpace<JfrStringPoolBuffer, JfrMspaceSequentialRetrieval, JfrStringPool> JfrStringPoolMspace;
       
    38 
       
    39 //
       
    40 // Although called JfrStringPool, a more succinct description would be
       
    41 // "backing storage for the string pool located in Java"
       
    42 //
       
    43 // There are no lookups in native, only the encoding of string constants to the stream.
       
    44 //
       
    45 class JfrStringPool : public JfrCHeapObj {
       
    46  public:
       
    47   static bool add(bool epoch, jlong id, jstring string, JavaThread* jt);
       
    48   size_t write();
       
    49   size_t write_at_safepoint();
       
    50   size_t clear();
       
    51 
       
    52   typedef JfrStringPoolMspace::Type Buffer;
       
    53  private:
       
    54   JfrStringPoolMspace* _free_list_mspace;
       
    55   Mutex* _lock;
       
    56   JfrChunkWriter& _chunkwriter;
       
    57 
       
    58   // mspace callback
       
    59   void register_full(Buffer* t, Thread* thread);
       
    60   void lock();
       
    61   void unlock();
       
    62   DEBUG_ONLY(bool is_locked() const;)
       
    63 
       
    64   static Buffer* lease_buffer(Thread* thread, size_t size = 0);
       
    65   static Buffer* flush(Buffer* old, size_t used, size_t requested, Thread* t);
       
    66 
       
    67   JfrStringPool(JfrChunkWriter& cw);
       
    68   ~JfrStringPool();
       
    69 
       
    70   static JfrStringPool& instance();
       
    71   static JfrStringPool* create(JfrChunkWriter& cw);
       
    72   bool initialize();
       
    73   static void destroy();
       
    74 
       
    75   friend class JfrRecorder;
       
    76   friend class JfrRecorderService;
       
    77   friend class JfrStringPoolFlush;
       
    78   friend class JfrStringPoolWriter;
       
    79   template <typename, template <typename> class, typename>
       
    80   friend class JfrMemorySpace;
       
    81 };
       
    82 
       
    83 #endif // SHARE_VM_JFR_RECORDER_STRINGPOOL_JFRSTRINGPOOL_HPP