1576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers/*
2576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * Copyright (C) 2011 The Android Open Source Project
3576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers *
4576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * Licensed under the Apache License, Version 2.0 (the "License");
5576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * you may not use this file except in compliance with the License.
6576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * You may obtain a copy of the License at
7576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers *
8576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers *      http://www.apache.org/licenses/LICENSE-2.0
9576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers *
10576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * Unless required by applicable law or agreed to in writing, software
11576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * distributed under the License is distributed on an "AS IS" BASIS,
12576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * See the License for the specific language governing permissions and
14576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers * limitations under the License.
15576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers */
16576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
1768d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers#ifndef ART_RUNTIME_JNI_ENV_EXT_INL_H_
1868d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers#define ART_RUNTIME_JNI_ENV_EXT_INL_H_
19576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
2068d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers#include "jni_env_ext.h"
21576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
22c15a2f4f45661a7f5f542e406282c146ea1a968dAndreas Gampe#include "mirror/object.h"
23576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
24576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogersnamespace art {
25576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
26576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogerstemplate<typename T>
278778c521de4f686118549ef7b20ae497e53b9e93Mathieu Chartierinline T JNIEnvExt::AddLocalReference(ObjPtr<mirror::Object> obj) {
28576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers  IndirectRef ref = locals.Add(local_ref_cookie, obj);
29576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
30576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers  // TODO: fix this to understand PushLocalFrame, so we can turn it on.
31576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers  if (false) {
32576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers    if (check_jni) {
33576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers      size_t entry_count = locals.Capacity();
34576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers      if (entry_count > 16) {
353fec9ac0d5af1358d216eb2fdc2000ec0205f3f0Andreas Gampe        locals.Dump(LOG_STREAM(WARNING) << "Warning: more than 16 JNI local references: "
36d6e54bbc09595465309aa7909b7a3965defe4419Andreas Gampe                                        << entry_count << " (most recent was a "
37709b070044354d9f47641f273edacaeeb0240ab7David Sehr                                        << mirror::Object::PrettyTypeOf(obj) << ")\n");
383fec9ac0d5af1358d216eb2fdc2000ec0205f3f0Andreas Gampe      // TODO: LOG(FATAL) in a later release?
39576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers      }
40576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers    }
41576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers  }
42576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
43576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers  return reinterpret_cast<T>(ref);
44576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers}
45576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
46576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers}  // namespace art
47576ca0cd692c0b6ae70e776de91015b8ff000a08Ian Rogers
4868d8b42ddec39ec0174162d90d4abaa004d1983eIan Rogers#endif  // ART_RUNTIME_JNI_ENV_EXT_INL_H_
49