blob: 7c318165d6ca89b5ad8f81fa94206513b3bb01c9 [file] [log] [blame]
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_GREENLAND_GBC_CONTEXT_H_
18#define ART_SRC_GREENLAND_GBC_CONTEXT_H_
19
20#include "dex_lang.h"
21
22#include "macros.h"
23
24#include <llvm/LLVMContext.h>
25
26namespace llvm {
27 class Module;
28} // namespace llvm
29
30namespace art {
31namespace greenland {
32
33class IntrinsicHelper;
34
35class GBCContext {
36 private:
37 llvm::LLVMContext context_;
38 llvm::Module* module_;
39 DexLang::Context* dex_lang_ctx_;
40
41 mutable volatile int32_t ref_count_;
42 volatile int32_t mem_usage_;
43
44 ~GBCContext();
45
46 public:
47 GBCContext();
48
49 inline llvm::LLVMContext& GetLLVMContext()
50 { return context_; }
51 inline llvm::Module& GetOutputModule()
52 { return *module_; }
53
54 inline IntrinsicHelper& GetIntrinsicHelper()
55 { return dex_lang_ctx_->GetIntrinsicHelper(); }
56 inline const IntrinsicHelper& GetIntrinsicHelper() const
57 { return dex_lang_ctx_->GetIntrinsicHelper(); }
58
59 inline DexLang::Context& GetDexLangContext()
60 { return *dex_lang_ctx_; }
61 inline const DexLang::Context& GetDexLangContext() const
62 { return *dex_lang_ctx_; }
63
64 GBCContext& IncRef();
65 const GBCContext& IncRef() const;
66 void DecRef() const;
67
68 void AddMemUsageApproximation(size_t usage);
69 inline bool IsMemUsageThresholdReached() const {
70 return (mem_usage_ > (30 << 20)); // (threshold: 30MiB)
71 }
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(GBCContext);
75};
76
77} // namespace greenland
78} // namespace art
79
80#endif // ART_SRC_GREENLAND_GBC_CONTEXT_H_