blob: 2717180b4d5102aafbabe1556ad4f7a50d50ee0a [file] [log] [blame]
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001/*
2 * Copyright (C) 2014 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_RUNTIME_HANDLE_SCOPE_INL_H_
18#define ART_RUNTIME_HANDLE_SCOPE_INL_H_
19
Ian Rogers22d5e732014-07-15 22:23:51 -070020#include "handle_scope.h"
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070021
22#include "handle.h"
23#include "thread.h"
24
25namespace art {
26
27template<size_t kNumReferences>
Mathieu Chartier421c5372014-05-14 14:11:40 -070028inline StackHandleScope<kNumReferences>::StackHandleScope(Thread* self)
Ian Rogers59c07062014-10-10 13:03:39 -070029 : HandleScope(self->GetTopHandleScope(), kNumReferences), self_(self), pos_(0) {
30 COMPILE_ASSERT(kNumReferences >= 1, stack_handle_scope_must_contain_at_least_1_reference);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070031 // TODO: Figure out how to use a compile assert.
Ian Rogers59c07062014-10-10 13:03:39 -070032 CHECK_EQ(&storage_[0], GetReferences());
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070033 for (size_t i = 0; i < kNumReferences; ++i) {
34 SetReference(i, nullptr);
35 }
36 self_->PushHandleScope(this);
37}
38
39template<size_t kNumReferences>
Mathieu Chartier421c5372014-05-14 14:11:40 -070040inline StackHandleScope<kNumReferences>::~StackHandleScope() {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070041 HandleScope* top_handle_scope = self_->PopHandleScope();
42 DCHECK_EQ(top_handle_scope, this);
43}
44
45} // namespace art
46
47#endif // ART_RUNTIME_HANDLE_SCOPE_INL_H_