hotspot/src/share/vm/classfile/metadataOnStackMark.cpp
author coleenp
Wed, 27 Mar 2013 08:19:50 -0400
changeset 16588 7e90e795813e
parent 15430 7c35f12cf1e5
child 21519 72e63a0dbda2
permissions -rw-r--r--
8009531: Crash when redefining class with annotated method Summary: Neglected to copy the annotations in clone_with_new_data when they were moved to ConstMethod. Reviewed-by: acorn, sspitsyn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15430
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     1
/*
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     4
 *
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     8
 *
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    13
 * accompanied this code).
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    14
 *
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    18
 *
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    21
 * questions.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    22
 *
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    23
 */
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    24
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    25
#include "precompiled.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    26
#include "classfile/metadataOnStackMark.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    27
#include "code/codeCache.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    28
#include "compiler/compileBroker.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    29
#include "oops/metadata.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    30
#include "runtime/synchronizer.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    31
#include "runtime/thread.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    32
#include "utilities/growableArray.hpp"
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    33
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    34
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    35
// Keep track of marked on-stack metadata so it can be cleared.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    36
GrowableArray<Metadata*>* _marked_objects = NULL;
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    37
NOT_PRODUCT(bool MetadataOnStackMark::_is_active = false;)
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    38
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    39
// Walk metadata on the stack and mark it so that redefinition doesn't delete
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    40
// it.  Class unloading also walks the previous versions and might try to
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    41
// delete it, so this class is used by class unloading also.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    42
MetadataOnStackMark::MetadataOnStackMark() {
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    43
  assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    44
  NOT_PRODUCT(_is_active = true;)
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    45
  if (_marked_objects == NULL) {
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    46
    _marked_objects = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(1000, true);
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    47
  }
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    48
  Threads::metadata_do(Metadata::mark_on_stack);
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    49
  CodeCache::alive_nmethods_do(nmethod::mark_on_stack);
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    50
  CompileBroker::mark_on_stack();
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    51
}
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    52
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    53
MetadataOnStackMark::~MetadataOnStackMark() {
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    54
  assert(SafepointSynchronize::is_at_safepoint(), "sanity check");
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    55
  // Unmark everything that was marked.   Can't do the same walk because
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    56
  // redefine classes messes up the code cache so the set of methods
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    57
  // might not be the same.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    58
  for (int i = 0; i< _marked_objects->length(); i++) {
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    59
    _marked_objects->at(i)->set_on_stack(false);
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    60
  }
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    61
  _marked_objects->clear();   // reuse growable array for next time.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    62
  NOT_PRODUCT(_is_active = false;)
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    63
}
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    64
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    65
// Record which objects are marked so we can unmark the same objects.
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    66
void MetadataOnStackMark::record(Metadata* m) {
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    67
  assert(_is_active, "metadata on stack marking is active");
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    68
  _marked_objects->push(m);
7c35f12cf1e5 8006040: NPG: on_stack processing wastes space in ConstantPool
coleenp
parents:
diff changeset
    69
}