Mercurial > hg > graal-compiler
annotate 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 |
rev | line source |
---|---|
1428
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
1 /* |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
2 * Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved. |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
4 * |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
8 * |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
14 * |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
18 * |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
21 * have any questions. |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
22 * |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
23 */ |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
24 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
25 # include "incls/_precompiled.incl" |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
26 # include "incls/_c1x_VmIds.cpp.incl" |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
27 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
28 // VmIds implementation |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
29 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
30 GrowableArray<address>* VmIds::_stubs = NULL; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
31 GrowableArray<jobject>* VmIds::_localHandles = NULL; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
32 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
33 void VmIds::initializeObjects() { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
34 if (_stubs == NULL) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
35 assert(_localHandles == NULL, "inconsistent state"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
36 _stubs = new(ResourceObj::C_HEAP) GrowableArray<address>(64, true); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
37 _localHandles = new(ResourceObj::C_HEAP) GrowableArray<jobject>(64, true); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
38 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
39 assert(_localHandles->length() == 0, "invalid state"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
40 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
41 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
42 void VmIds::cleanupLocalObjects() { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
43 for (int i=0; i<_localHandles->length(); i++) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
44 JNIHandles::destroy_global(_localHandles->at(i)); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
45 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
46 _localHandles->clear(); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
47 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
48 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
49 jlong VmIds::addStub(address stub) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
50 assert(!_stubs->contains(stub), "duplicate stub"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
51 return _stubs->append(stub) | STUB; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
52 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
53 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
54 jlong VmIds::add(Handle obj, CompilerObjectType type) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
55 assert(!obj.is_null(), "cannot add NULL handle"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
56 int idx = -1; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
57 for (int i=0; i<_localHandles->length(); i++) |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
58 if (JNIHandles::resolve_non_null(_localHandles->at(i)) == obj()) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
59 idx = i; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
60 break; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
61 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
62 if (idx = -1) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
63 if (JavaThread::current()->thread_state() == _thread_in_vm) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
64 idx = _localHandles->append(JNIHandles::make_global(obj)); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
65 } else { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
66 VM_ENTRY_MARK; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
67 idx = _localHandles->append(JNIHandles::make_global(obj)); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
68 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
69 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
70 return idx | type; |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
71 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
72 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
73 address VmIds::getStub(jlong id) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
74 assert((id & TYPE_MASK) == STUB, "wrong id type, STUB expected"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
75 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _stubs->length(), "STUB index out of bounds"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
76 return _stubs->at(id & ~TYPE_MASK); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
77 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
78 |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
79 oop VmIds::getObject(jlong id) { |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
80 assert((id & TYPE_MASK) != STUB, "wrong id type"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
81 assert((id & ~TYPE_MASK) >= 0 && (id & ~TYPE_MASK) < _localHandles->length(), "index out of bounds"); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
82 return JNIHandles::resolve_non_null(_localHandles->at(id & ~TYPE_MASK)); |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
83 } |
695451afc619
refactoring classes into separate files
Lukas Stadler <lukas.stadler@oracle.com>
parents:
diff
changeset
|
84 |