1 // Copyright 2016 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_ 6 #define V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_ 7 8 #include "src/codegen/handler-table.h" 9 #include "src/interpreter/bytecode-register.h" 10 #include "src/interpreter/bytecodes.h" 11 #include "src/objects/fixed-array.h" 12 #include "src/zone/zone-containers.h" 13 14 namespace v8 { 15 namespace internal { 16 17 template <typename T> 18 class Handle; 19 class HandlerTable; 20 class Isolate; 21 22 namespace interpreter { 23 24 // A helper class for constructing exception handler tables for the interpreter. 25 class V8_EXPORT_PRIVATE HandlerTableBuilder final { 26 public: 27 explicit HandlerTableBuilder(Zone* zone); 28 HandlerTableBuilder(const HandlerTableBuilder&) = delete; 29 HandlerTableBuilder& operator=(const HandlerTableBuilder&) = delete; 30 31 // Builds the actual handler table by copying the current values into a heap 32 // object. Any further mutations to the builder won't be reflected. 33 template <typename IsolateT> 34 Handle<ByteArray> ToHandlerTable(IsolateT* isolate); 35 36 // Creates a new handler table entry and returns a {hander_id} identifying the 37 // entry, so that it can be referenced by below setter functions. 38 int NewHandlerEntry(); 39 40 // Setter functions that modify certain values within the handler table entry 41 // being referenced by the given {handler_id}. All values will be encoded by 42 // the resulting {HandlerTable} class when copied into the heap. 43 void SetTryRegionStart(int handler_id, size_t offset); 44 void SetTryRegionEnd(int handler_id, size_t offset); 45 void SetHandlerTarget(int handler_id, size_t offset); 46 void SetPrediction(int handler_id, HandlerTable::CatchPrediction prediction); 47 void SetContextRegister(int handler_id, Register reg); 48 49 private: 50 struct Entry { 51 size_t offset_start; // Bytecode offset starting try-region. 52 size_t offset_end; // Bytecode offset ending try-region. 53 size_t offset_target; // Bytecode offset of handler target. 54 Register context; // Register holding context for handler. 55 // Optimistic prediction for handler. 56 HandlerTable::CatchPrediction catch_prediction_; 57 }; 58 59 ZoneVector<Entry> entries_; 60 }; 61 62 } // namespace interpreter 63 } // namespace internal 64 } // namespace v8 65 66 #endif // V8_INTERPRETER_HANDLER_TABLE_BUILDER_H_ 67