Mercurial > hg > graal-compiler
comparison src/share/vm/c1x/c1x_VmIds.cpp @ 1428:695451afc619
refactoring classes into separate files
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Thu, 19 Aug 2010 14:34:52 -0700 |
parents | |
children | b61a43cd1255 |
comparison
equal
deleted
inserted
replaced
1427:149b1d2316de | 1428:695451afc619 |
---|---|
1 /* | |
2 * Copyright 2000-2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_c1x_VmIds.cpp.incl" | |
27 | |
28 // VmIds implementation | |
29 | |
30 GrowableArray<address>* VmIds::_stubs = NULL; | |
31 GrowableArray<jobject>* VmIds::_localHandles = NULL; | |
32 | |
33 void VmIds::initializeObjects() { | |
34 if (_stubs == NULL) { | |
35 assert(_localHandles == NULL, "inconsistent state"); | |
36 _stubs = new(ResourceObj::C_HEAP) GrowableArray<address>(64, true); | |
37 _localHandles = new(ResourceObj::C_HEAP) GrowableArray<jobject>(64, true); | |
38 } | |
39 assert(_localHandles->length() == 0, "invalid state"); | |
40 } | |
41 | |
42 void VmIds::cleanupLocalObjects() { | |
43 for (int i=0; i<_localHandles->length(); i++) { | |
44 JNIHandles::destroy_global(_localHandles->at(i)); | |
45 } | |
46 _localHandles->clear(); | |
47 } | |
48 | |
49 jlong VmIds::addStub(address stub) { | |
50 assert(!_stubs->contains(stub), "duplicate stub"); | |
51 return _stubs->append(stub) | STUB; | |
52 } | |
53 | |
54 jlong VmIds::add(Handle obj, CompilerObjectType type) { | |
55 assert(!obj.is_null(), "cannot add NULL handle"); | |
56 int idx = -1; | |
57 for (int i=0; i<_localHandles->length(); i++) | |
58 if (JNIHandles::resolve_non_null(_localHandles->at(i)) == obj()) { | |
59 idx = i; | |
60 break; | |
61 } | |
62 if (idx = -1) { | |
63 if (JavaThread::current()->thread_state() == _thread_in_vm) { | |
64 idx = _localHandles->append(JNIHandles::make_global(obj)); | |
65 } else { | |
66 VM_ENTRY_MARK; | |
67 idx = _localHandles->append(JNIHandles::make_global(obj)); | |
68 } | |
69 } | |
70 return idx | type; | |
71 } | |
72 | |
73 address VmIds::getStub(jlong id) { | |
74 assert((id & TYPE_MASK) == STUB, "wrong id type, STUB expected"); | |
75 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _stubs->length(), "STUB index out of bounds"); | |
76 return _stubs->at(id & ~TYPE_MASK); | |
77 } | |
78 | |
79 oop VmIds::getObject(jlong id) { | |
80 assert((id & TYPE_MASK) != STUB, "wrong id type"); | |
81 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _localHandles->length(), "index out of bounds"); | |
82 return JNIHandles::resolve_non_null(_localHandles->at(id & ~TYPE_MASK)); | |
83 } | |
84 |