• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
3  * Description: add ref tracker.
4  * Create: 2020/11/20
5  */
6 
7 #ifndef EXT_TRACKER_H
8 #define EXT_TRACKER_H
9 
10 #if defined(JERRY_REF_TRACKER)
11 
12 #include "jcontext.h"
13 
14 typedef struct {
15   size_t size;
16   size_t* data;
17 } Storage;
18 
19 typedef enum {
20   kObjectRefInfo = 0,
21   kStringRefInfo = 1
22 } StorageType;
23 
24 typedef enum {
25   kRefNative = 1 << 0,
26   kRefInit = 1 << 1,
27   kRefRef = 1 << 2,
28   kRefDeref = 1 << 3,
29   kRefMark = 1 << 4,
30   kRefUnmark = 1 << 5
31 } RefInfoItemFlags;
32 
33 typedef struct IStorageItem_s {
34   struct IStorageItem_s* next;
35 } IStorageItem;
36 
37 typedef struct RefInfoItem_s {
38   struct RefInfoItem_s* next;
39   char* stacktrace;
40   RefInfoItemFlags flags;
41 } RefInfoItem; // Implements IStorageItem.
42 
43 // Deleter.
44 void RefInfoResetFn(IStorageItem* item);
45 
46 #define ECMA_OBJECT_TO_STORAGE_KEY(x) (size_t)((uintptr_t)x - (uintptr_t)&JERRY_HEAP_CONTEXT(first))
47 #define ECMA_OBJECT_FROM_STORAGE_KEY(x) (ecma_object_t*)((uintptr_t)x + (uintptr_t)&JERRY_HEAP_CONTEXT(first))
48 
49 bool GetRefTrackerEnabled(void);
50 void SetRefTrackerEnabled(bool flag);
51 
52 void LogTrackerInit(const char* filepath);
53 void LogTrackerClose(void);
54 
55 void InitTracker(void);
56 void StorageInit(Storage* storage, size_t size);
57 void StoragePut(Storage* storage, size_t key, size_t value);
58 size_t StorageGet(Storage* storage, size_t key);
59 void StorageReset(Storage* storage, size_t key, void(*reset_fn)(IStorageItem*));
60 char* GetStacktraceString(ecma_string_t* stack);
61 RefInfoItem* CreateRefInfoItem(RefInfoItemFlags flags, char* stack_str);
62 void ReportObjRefManip(ecma_object_t* obj, RefInfoItemFlags flags);
63 void ReportObjDelete(ecma_object_t* obj);
64 void DumpTracker(void);
65 
66 #endif
67 #endif
68