Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalVmIds.cpp @ 2890:c23d45daff9b
Renamed cpp/hpp file directory.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 08 Jun 2011 13:40:25 +0200 |
parents | src/share/vm/c1x/graalVmIds.cpp@2fb867285938 |
children | 75a99b4f1c98 |
comparison
equal
deleted
inserted
replaced
2889:2fb867285938 | 2890:c23d45daff9b |
---|---|
1 /* | |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 | |
24 #include "precompiled.hpp" | |
25 #include "c1x/c1x_VmIds.hpp" | |
26 #include "ci/ciUtilities.hpp" | |
27 | |
28 // VmIds implementation | |
29 | |
30 GrowableArray<address>* VmIds::_stubs = NULL; | |
31 GrowableArray<jobject>* VmIds::_localHandles = NULL; | |
32 | |
33 | |
34 void VmIds::initializeObjects() { | |
35 if (_stubs == NULL) { | |
36 assert(_localHandles == NULL, "inconsistent state"); | |
37 _stubs = new (ResourceObj::C_HEAP) GrowableArray<address> (64, true); | |
38 _localHandles = new (ResourceObj::C_HEAP) GrowableArray<jobject> (64, true); | |
39 } | |
40 assert(_localHandles->length() == 0, "invalid state"); | |
41 } | |
42 | |
43 void VmIds::cleanupLocalObjects() { | |
44 for (int i = 0; i < _localHandles->length(); i++) { | |
45 JNIHandles::destroy_global(_localHandles->at(i)); | |
46 } | |
47 _localHandles->clear(); | |
48 } | |
49 | |
50 jlong VmIds::addStub(address stub) { | |
51 assert(!_stubs->contains(stub), "duplicate stub"); | |
52 return _stubs->append(stub) | STUB; | |
53 } | |
54 | |
55 jlong VmIds::add(Handle obj, jlong type) { | |
56 assert(!obj.is_null(), "cannot add NULL handle"); | |
57 int idx = -1; | |
58 for (int i = 0; i < _localHandles->length(); i++) | |
59 if (JNIHandles::resolve_non_null(_localHandles->at(i)) == obj()) { | |
60 idx = i; | |
61 break; | |
62 } | |
63 if (idx == -1) { | |
64 if (JavaThread::current()->thread_state() == _thread_in_vm) { | |
65 idx = _localHandles->append(JNIHandles::make_global(obj)); | |
66 } else { | |
67 VM_ENTRY_MARK; | |
68 idx = _localHandles->append(JNIHandles::make_global(obj)); | |
69 } | |
70 } | |
71 return idx | type; | |
72 } | |
73 | |
74 address VmIds::getStub(jlong id) { | |
75 assert((id & TYPE_MASK) == STUB, "wrong id type, STUB expected"); | |
76 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _stubs->length(), "STUB index out of bounds"); | |
77 return _stubs->at(id & ~TYPE_MASK); | |
78 } | |
79 | |
80 oop VmIds::getObject(jlong id) { | |
81 assert((id & TYPE_MASK) != STUB, "wrong id type"); | |
82 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _localHandles->length(), "index out of bounds"); | |
83 return JNIHandles::resolve_non_null(_localHandles->at(id & ~TYPE_MASK)); | |
84 } | |
85 |