< prev index next >

src/hotspot/share/jfr/recorder/repository/jfrChunkWriter.cpp

Print this page


   1 /*
   2  * Copyright (c) 2012, 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  *


  30 #include "jfr/utilities/jfrTypes.hpp"
  31 #include "runtime/mutexLocker.hpp"
  32 #include "runtime/os.hpp"
  33 #include "runtime/os.inline.hpp"
  34 
  35 const u2 JFR_VERSION_MAJOR = 2;
  36 const u2 JFR_VERSION_MINOR = 0;
  37 
  38 static const size_t MAGIC_LEN = 4;
  39 static const size_t FILEHEADER_SLOT_SIZE = 8;
  40 static const size_t CHUNK_SIZE_OFFSET = 8;
  41 
  42 JfrChunkWriter::JfrChunkWriter() : JfrChunkWriterBase(NULL), _chunkstate(NULL) {}
  43 
  44 bool JfrChunkWriter::initialize() {
  45   assert(_chunkstate == NULL, "invariant");
  46   _chunkstate = new JfrChunkState();
  47   return _chunkstate != NULL;
  48 }
  49 
  50 static fio_fd open_existing(const char* path) {
  51   return os::open(path, O_RDWR, S_IREAD | S_IWRITE);
  52 }
  53 
  54 static fio_fd open_chunk(const char* path) {
  55   assert(JfrStream_lock->owned_by_self(), "invariant");
  56   return path != NULL ? open_existing(path) : invalid_fd;


  57 }
  58 
  59 bool JfrChunkWriter::open() {
  60   assert(_chunkstate != NULL, "invariant");
  61   JfrChunkWriterBase::reset(open_chunk(_chunkstate->path()));
  62   const bool is_open = this->has_valid_fd();
  63   if (is_open) {
  64     this->bytes("FLR", MAGIC_LEN);
  65     this->be_write((u2)JFR_VERSION_MAJOR);
  66     this->be_write((u2)JFR_VERSION_MINOR);
  67     this->reserve(6 * FILEHEADER_SLOT_SIZE);
  68     // u8 chunk_size
  69     // u8 initial checkpoint offset
  70     // u8 metadata section offset
  71     // u8 chunk start nanos
  72     // u8 chunk duration nanos
  73     // u8 chunk start ticks
  74     this->be_write(JfrTime::frequency());
  75     // chunk capabilities, CompressedIntegers etc
  76     this->be_write((u4)JfrOptionSet::compressed_integers() ? 1 : 0);
  77     _chunkstate->reset();
  78   }
  79   return is_open;
  80 }
  81 


   1 /*
   2  * Copyright (c) 2012, 2019, 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  *


  30 #include "jfr/utilities/jfrTypes.hpp"
  31 #include "runtime/mutexLocker.hpp"
  32 #include "runtime/os.hpp"
  33 #include "runtime/os.inline.hpp"
  34 
  35 const u2 JFR_VERSION_MAJOR = 2;
  36 const u2 JFR_VERSION_MINOR = 0;
  37 
  38 static const size_t MAGIC_LEN = 4;
  39 static const size_t FILEHEADER_SLOT_SIZE = 8;
  40 static const size_t CHUNK_SIZE_OFFSET = 8;
  41 
  42 JfrChunkWriter::JfrChunkWriter() : JfrChunkWriterBase(NULL), _chunkstate(NULL) {}
  43 
  44 bool JfrChunkWriter::initialize() {
  45   assert(_chunkstate == NULL, "invariant");
  46   _chunkstate = new JfrChunkState();
  47   return _chunkstate != NULL;
  48 }
  49 
  50 static fio_fd open_chunk(const char* path, bool vm_error) {




  51   assert(JfrStream_lock->owned_by_self(), "invariant");
  52   int flags = vm_error ? (O_CREAT | O_WRONLY) : O_RDWR;
  53   const int mode = S_IREAD | S_IWRITE;
  54   return path != NULL ? os::open(path, flags, mode) : invalid_fd;
  55 }
  56 
  57 bool JfrChunkWriter::open(bool vm_error) {
  58   assert(_chunkstate != NULL, "invariant");
  59   JfrChunkWriterBase::reset(open_chunk(_chunkstate->path(), vm_error));
  60   const bool is_open = this->has_valid_fd();
  61   if (is_open) {
  62     this->bytes("FLR", MAGIC_LEN);
  63     this->be_write((u2)JFR_VERSION_MAJOR);
  64     this->be_write((u2)JFR_VERSION_MINOR);
  65     this->reserve(6 * FILEHEADER_SLOT_SIZE);
  66     // u8 chunk_size
  67     // u8 initial checkpoint offset
  68     // u8 metadata section offset
  69     // u8 chunk start nanos
  70     // u8 chunk duration nanos
  71     // u8 chunk start ticks
  72     this->be_write(JfrTime::frequency());
  73     // chunk capabilities, CompressedIntegers etc
  74     this->be_write((u4)JfrOptionSet::compressed_integers() ? 1 : 0);
  75     _chunkstate->reset();
  76   }
  77   return is_open;
  78 }
  79 


< prev index next >