src/share/vm/runtime/handles.inline.hpp

changeset 4037
da91efe96a93
parent 3900
d2a62e0f25eb
child 4193
716c64bda5ba
     1.1 --- a/src/share/vm/runtime/handles.inline.hpp	Fri Aug 31 16:39:35 2012 -0700
     1.2 +++ b/src/share/vm/runtime/handles.inline.hpp	Sat Sep 01 13:25:18 2012 -0400
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -62,6 +62,63 @@
    1.11  }
    1.12  #endif // ASSERT
    1.13  
    1.14 +// Constructors for metadata handles
    1.15 +#define DEF_METADATA_HANDLE_FN(name, type) \
    1.16 +inline name##Handle::name##Handle(type* obj) : _value(obj), _thread(NULL) {       \
    1.17 +  if (obj != NULL) {                                                   \
    1.18 +    assert(((Metadata*)obj)->is_valid(), "obj is valid");              \
    1.19 +    _thread = Thread::current();                                       \
    1.20 +    assert (_thread->is_in_stack((address)this), "not on stack?");     \
    1.21 +    _thread->metadata_handles()->push((Metadata*)obj);                 \
    1.22 +  }                                                                    \
    1.23 +}                                                                      \
    1.24 +inline name##Handle::name##Handle(Thread* thread, type* obj) : _value(obj), _thread(thread) { \
    1.25 +  if (obj != NULL) {                                                   \
    1.26 +    assert(((Metadata*)obj)->is_valid(), "obj is valid");              \
    1.27 +    assert(_thread == Thread::current(), "thread must be current");    \
    1.28 +    assert (_thread->is_in_stack((address)this), "not on stack?");     \
    1.29 +    _thread->metadata_handles()->push((Metadata*)obj);                 \
    1.30 +  }                                                                    \
    1.31 +}                                                                      \
    1.32 +inline name##Handle::name##Handle(const name##Handle &h) {             \
    1.33 +  _value = h._value;                                                   \
    1.34 +  if (_value != NULL) {                                                \
    1.35 +    assert(_value->is_valid(), "obj is valid");                        \
    1.36 +    if (h._thread != NULL) {                                           \
    1.37 +      assert(h._thread == Thread::current(), "thread must be current");\
    1.38 +      _thread = h._thread;                                             \
    1.39 +    } else {                                                           \
    1.40 +      _thread = Thread::current();                                     \
    1.41 +    }                                                                  \
    1.42 +    _thread->metadata_handles()->push((Metadata*)_value);              \
    1.43 +  }                                                                    \
    1.44 +}                                                                      \
    1.45 +inline name##Handle& name##Handle::operator=(const name##Handle &s) {  \
    1.46 +  remove();                                                            \
    1.47 +  _value = s._value;                                                   \
    1.48 +  if (_value != NULL) {                                                \
    1.49 +    assert(_value->is_valid(), "obj is valid");                        \
    1.50 +    if (s._thread != NULL) {                                           \
    1.51 +      assert(s._thread == Thread::current(), "thread must be current");\
    1.52 +      _thread = s._thread;                                             \
    1.53 +    } else {                                                           \
    1.54 +      _thread = Thread::current();                                     \
    1.55 +    }                                                                  \
    1.56 +    _thread->metadata_handles()->push((Metadata*)_value);              \
    1.57 +  }                                                                    \
    1.58 +  return *this;                                                        \
    1.59 +}                                                                      \
    1.60 +inline void name##Handle::remove() {                                   \
    1.61 +  if (_value != NULL) {                                                \
    1.62 +    int i = _thread->metadata_handles()->find_from_end((Metadata*)_value); \
    1.63 +    assert(i!=-1, "not in metadata_handles list");                     \
    1.64 +    _thread->metadata_handles()->remove_at(i);                         \
    1.65 +  }                                                                    \
    1.66 +}                                                                      \
    1.67 +inline name##Handle::~name##Handle () { remove(); }                    \
    1.68 +
    1.69 +DEF_METADATA_HANDLE_FN(method, Method)
    1.70 +DEF_METADATA_HANDLE_FN(constantPool, ConstantPool)
    1.71  
    1.72  inline HandleMark::HandleMark() {
    1.73    initialize(Thread::current());

mercurial