1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_SNAPSHOT_MEM_SNAPSHOT_H 17 #define ECMASCRIPT_SNAPSHOT_MEM_SNAPSHOT_H 18 19 #include "libpandabase/macros.h" 20 #include "libpandafile/file.h" 21 22 #include "ecmascript/snapshot/mem/slot_bit.h" 23 #include "ecmascript/mem/c_string.h" 24 25 namespace panda::ecmascript { 26 class Program; 27 class EcmaVM; 28 29 class SnapShot final { 30 public: SnapShot(EcmaVM * vm)31 explicit SnapShot(EcmaVM *vm) : vm_(vm) {} 32 ~SnapShot() = default; 33 34 void MakeSnapShotProgramObject(Program *program, const panda_file::File *pf, 35 const CString &fileName = "./snapshot"); 36 std::unique_ptr<const panda_file::File> DeserializeGlobalEnvAndProgram( 37 const CString &fileName = "./snapshot"); 38 39 private: 40 struct Header { 41 uint32_t snapshot_size; 42 uint32_t panda_file_begin; 43 }; 44 45 private: 46 size_t AlignUpPageSize(size_t spaceSize); 47 std::pair<bool, CString> VerifyFilePath(const CString &filePath); 48 49 NO_MOVE_SEMANTIC(SnapShot); 50 NO_COPY_SEMANTIC(SnapShot); 51 52 EcmaVM *vm_; 53 }; 54 } // namespace panda::ecmascript 55 #endif // ECMASCRIPT_SNAPSHOT_MEM_SNAPSHOT_H