1 /*
2 * Copyright (c) 2003, 2017, 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 *
29 #include "prims/jvmtiGetLoadedClasses.hpp"
30 #include "runtime/thread.hpp"
31 #include "utilities/stack.inline.hpp"
32
33
34 // The closure for GetLoadedClasses
35 class LoadedClassesClosure : public KlassClosure {
36 private:
37 Stack<jclass, mtInternal> _classStack;
38 JvmtiEnv* _env;
39 Thread* _cur_thread;
40
41 public:
42 LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
43 assert(_cur_thread == Thread::current(), "must be current thread");
44 }
45
46 void do_klass(Klass* k) {
47 // Collect all jclasses
48 _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
49 }
50
51 int extract(jclass* result_list) {
52 // The size of the Stack will be 0 after extract, so get it here
53 int count = (int)_classStack.size();
54 int i = count;
55
56 // Pop all jclasses, fill backwards
57 while (!_classStack.is_empty()) {
58 result_list[--i] = _classStack.pop();
59 }
60
61 // Return the number of elements written
62 return count;
63 }
64
65 // Return current size of the Stack
66 int get_count() {
67 return (int)_classStack.size();
68 }
|
1 /*
2 * Copyright (c) 2003, 2018, 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 *
29 #include "prims/jvmtiGetLoadedClasses.hpp"
30 #include "runtime/thread.hpp"
31 #include "utilities/stack.inline.hpp"
32
33
34 // The closure for GetLoadedClasses
35 class LoadedClassesClosure : public KlassClosure {
36 private:
37 Stack<jclass, mtInternal> _classStack;
38 JvmtiEnv* _env;
39 Thread* _cur_thread;
40
41 public:
42 LoadedClassesClosure(Thread* thread, JvmtiEnv* env) : _cur_thread(thread), _env(env) {
43 assert(_cur_thread == Thread::current(), "must be current thread");
44 }
45
46 void do_klass(Klass* k) {
47 // Collect all jclasses
48 _classStack.push((jclass) _env->jni_reference(Handle(_cur_thread, k->java_mirror())));
49 Klass::ensure_klass_alive(k->java_mirror());
50 }
51
52 int extract(jclass* result_list) {
53 // The size of the Stack will be 0 after extract, so get it here
54 int count = (int)_classStack.size();
55 int i = count;
56
57 // Pop all jclasses, fill backwards
58 while (!_classStack.is_empty()) {
59 result_list[--i] = _classStack.pop();
60 }
61
62 // Return the number of elements written
63 return count;
64 }
65
66 // Return current size of the Stack
67 int get_count() {
68 return (int)_classStack.size();
69 }
|