Mon, 29 Apr 2013 16:13:57 -0400
8011773: Some tests on Interned String crashed JVM with OOM
Summary: Instead of terminating the VM, throw OutOfMemoryError exceptions.
Reviewed-by: coleenp, dholmes
1 /*
2 * Copyright (c) 2012, 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 "memory/metaspaceCounters.hpp"
27 #include "memory/resourceArea.hpp"
28 #include "utilities/exceptions.hpp"
30 MetaspaceCounters* MetaspaceCounters::_metaspace_counters = NULL;
32 MetaspaceCounters::MetaspaceCounters() :
33 _capacity(NULL),
34 _used(NULL),
35 _max_capacity(NULL) {
36 if (UsePerfData) {
37 size_t min_capacity = MetaspaceAux::min_chunk_size();
38 size_t max_capacity = MetaspaceAux::reserved_in_bytes();
39 size_t curr_capacity = MetaspaceAux::capacity_in_bytes();
40 size_t used = MetaspaceAux::used_in_bytes();
42 initialize(min_capacity, max_capacity, curr_capacity, used);
43 }
44 }
46 static PerfVariable* create_ms_variable(const char *ns,
47 const char *name,
48 size_t value,
49 TRAPS) {
50 const char *path = PerfDataManager::counter_name(ns, name);
51 PerfVariable *result =
52 PerfDataManager::create_variable(SUN_GC, path, PerfData::U_Bytes, value,
53 CHECK_NULL);
54 return result;
55 }
57 static void create_ms_constant(const char *ns,
58 const char *name,
59 size_t value,
60 TRAPS) {
61 const char *path = PerfDataManager::counter_name(ns, name);
62 PerfDataManager::create_constant(SUN_GC, path, PerfData::U_Bytes, value, CHECK);
63 }
65 void MetaspaceCounters::initialize(size_t min_capacity,
66 size_t max_capacity,
67 size_t curr_capacity,
68 size_t used) {
70 if (UsePerfData) {
71 EXCEPTION_MARK;
72 ResourceMark rm;
74 const char *ms = "metaspace";
76 create_ms_constant(ms, "minCapacity", min_capacity, CHECK);
77 _max_capacity = create_ms_variable(ms, "maxCapacity", max_capacity, CHECK);
78 _capacity = create_ms_variable(ms, "capacity", curr_capacity, CHECK);
79 _used = create_ms_variable(ms, "used", used, CHECK);
80 }
81 }
83 void MetaspaceCounters::update_capacity() {
84 assert(UsePerfData, "Should not be called unless being used");
85 assert(_capacity != NULL, "Should be initialized");
86 size_t capacity_in_bytes = MetaspaceAux::capacity_in_bytes();
87 _capacity->set_value(capacity_in_bytes);
88 }
90 void MetaspaceCounters::update_used() {
91 assert(UsePerfData, "Should not be called unless being used");
92 assert(_used != NULL, "Should be initialized");
93 size_t used_in_bytes = MetaspaceAux::used_in_bytes();
94 _used->set_value(used_in_bytes);
95 }
97 void MetaspaceCounters::update_max_capacity() {
98 assert(UsePerfData, "Should not be called unless being used");
99 assert(_max_capacity != NULL, "Should be initialized");
100 size_t reserved_in_bytes = MetaspaceAux::reserved_in_bytes();
101 _max_capacity->set_value(reserved_in_bytes);
102 }
104 void MetaspaceCounters::update_all() {
105 if (UsePerfData) {
106 update_used();
107 update_capacity();
108 update_max_capacity();
109 }
110 }
112 void MetaspaceCounters::initialize_performance_counters() {
113 if (UsePerfData) {
114 assert(_metaspace_counters == NULL, "Should only be initialized once");
115 _metaspace_counters = new MetaspaceCounters();
116 }
117 }
119 void MetaspaceCounters::update_performance_counters() {
120 if (UsePerfData) {
121 assert(_metaspace_counters != NULL, "Should be initialized");
122 _metaspace_counters->update_all();
123 }
124 }