Thu, 13 Jan 2011 22:15:41 -0800
4926272: methodOopDesc::method_from_bcp is unsafe
Reviewed-by: coleenp, jrose, kvn, dcubed
1 /*
2 * Copyright (c) 1999, 2010, 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 */
25 #include "precompiled.hpp"
26 #include "ci/ciSymbol.hpp"
27 #include "ci/ciUtilities.hpp"
28 #include "memory/oopFactory.hpp"
30 // ------------------------------------------------------------------
31 // ciSymbol::ciSymbol
32 //
33 // Preallocated handle variant. Used with handles from vmSymboHandles.
34 ciSymbol::ciSymbol(symbolHandle h_s, vmSymbols::SID sid)
35 : ciObject(h_s), _sid(sid)
36 {
37 assert(sid_ok(), "must be in vmSymbols");
38 }
40 // Normal case for non-famous symbols.
41 ciSymbol::ciSymbol(symbolOop s)
42 : ciObject(s), _sid(vmSymbols::NO_SID)
43 {
44 assert(sid_ok(), "must not be in vmSymbols");
45 }
47 // ciSymbol
48 //
49 // This class represents a symbolOop in the HotSpot virtual
50 // machine.
52 // ------------------------------------------------------------------
53 // ciSymbol::as_utf8
54 //
55 // The text of the symbol as a null-terminated C string.
56 const char* ciSymbol::as_utf8() {
57 VM_QUICK_ENTRY_MARK;
58 symbolOop s = get_symbolOop();
59 return s->as_utf8();
60 }
62 // ------------------------------------------------------------------
63 // ciSymbol::base
64 jbyte* ciSymbol::base() {
65 GUARDED_VM_ENTRY(return get_symbolOop()->base();)
66 }
68 // ------------------------------------------------------------------
69 // ciSymbol::byte_at
70 int ciSymbol::byte_at(int i) {
71 GUARDED_VM_ENTRY(return get_symbolOop()->byte_at(i);)
72 }
74 // ------------------------------------------------------------------
75 // ciSymbol::starts_with
76 //
77 // Tests if the symbol starts with the given prefix.
78 bool ciSymbol::starts_with(const char* prefix, int len) const {
79 GUARDED_VM_ENTRY(return get_symbolOop()->starts_with(prefix, len);)
80 }
82 // ------------------------------------------------------------------
83 // ciSymbol::index_of
84 //
85 // Determines where the symbol contains the given substring.
86 int ciSymbol::index_of_at(int i, const char* str, int len) const {
87 GUARDED_VM_ENTRY(return get_symbolOop()->index_of_at(i, str, len);)
88 }
90 // ------------------------------------------------------------------
91 // ciSymbol::utf8_length
92 int ciSymbol::utf8_length() {
93 GUARDED_VM_ENTRY(return get_symbolOop()->utf8_length();)
94 }
96 // ------------------------------------------------------------------
97 // ciSymbol::print_impl
98 //
99 // Implementation of the print method
100 void ciSymbol::print_impl(outputStream* st) {
101 st->print(" value=");
102 print_symbol_on(st);
103 }
105 // ------------------------------------------------------------------
106 // ciSymbol::print_symbol_on
107 //
108 // Print the value of this symbol on an outputStream
109 void ciSymbol::print_symbol_on(outputStream *st) {
110 GUARDED_VM_ENTRY(get_symbolOop()->print_symbol_on(st);)
111 }
113 // ------------------------------------------------------------------
114 // ciSymbol::make_impl
115 //
116 // Make a ciSymbol from a C string (implementation).
117 ciSymbol* ciSymbol::make_impl(const char* s) {
118 EXCEPTION_CONTEXT;
119 // For some reason, oopFactory::new_symbol doesn't declare its
120 // char* argument as const.
121 symbolOop sym = oopFactory::new_symbol((char*)s, (int)strlen(s), THREAD);
122 if (HAS_PENDING_EXCEPTION) {
123 CLEAR_PENDING_EXCEPTION;
124 CURRENT_THREAD_ENV->record_out_of_memory_failure();
125 return ciEnv::_unloaded_cisymbol;
126 }
127 return CURRENT_THREAD_ENV->get_object(sym)->as_symbol();
128 }
130 // ------------------------------------------------------------------
131 // ciSymbol::make
132 //
133 // Make a ciSymbol from a C string.
134 ciSymbol* ciSymbol::make(const char* s) {
135 GUARDED_VM_ENTRY(return make_impl(s);)
136 }