# HG changeset patch # User chrisphi # Date 1372273859 14400 # Node ID ea7bce0f610ade5d1dfc40c2bbfe76b9bd8d8368 # Parent a1cb163cb044df6656c26bdcc3983f674e822e13 Summary: Backport 20130618 sec fixes 7158805 and 8001330 added patches/security/20130618/7158805-nested_subroutine_rewriting-it6.patch added patches/security/20130618/8001330-checking_order_improvement-it6.patch changed ChangeLog changed Makefile.am diff -r a1cb163cb044 -r ea7bce0f610a ChangeLog --- a/ChangeLog Wed Jun 26 13:45:20 2013 -0400 +++ b/ChangeLog Wed Jun 26 15:10:59 2013 -0400 @@ -1,3 +1,26 @@ +2013-06-26 Chris Phillips + * Makefile.am (SECURITY_PATCHES): Drop + patches/security/20130618/7158805-nested_subroutine_rewriting.patch + patches/security/20130618/8001330-checking_order_improvement.patch + patches/openjdk/7036747-elfstringtable.patch + patches/openjdk/7017732-move_static_fields_to_class.patch + patches/openjdk/6990754-use_native_memory_for_symboltable.patch + patches/openjdk/6990754-handle_renames.patch + patches/openjdk/7008809-report_class_in_arraystoreexception.patch + patches/openjdk/7086585-flexible_field_injection.patch + patches/security/20130618/hs_merge-01.patch + patches/security/20130618/hs_merge-02.patch + patches/security/20130618/hs_merge-03.patch + patches/openjdk/7014851-unused_parallel_compaction_code.patch + patches/security/20130618/hs_merge-04.patch + Add: + patches/security/20130618/7158805-nested_subroutine_rewriting-it6.patch + patches/security/20130618/8001330-checking_order_improvement-it6.patch + * patches/security/20130618/7158805-nested_subroutine_rewriting-it6.patch: + Backported fix for 7158805. + * patches/security/20130618/8001330-checking_order_improvement-it6.patch: + Backported fix for hs portion of 8001330. + 2013-06-26 Omair Majid Severin Gehwolf diff -r a1cb163cb044 -r ea7bce0f610a Makefile.am --- a/Makefile.am Wed Jun 26 13:45:20 2013 -0400 +++ b/Makefile.am Wed Jun 26 15:10:59 2013 -0400 @@ -377,19 +377,8 @@ patches/security/20130618/diamond_fix.patch \ patches/security/20130618/handle_npe.patch \ patches/security/20130618/javac_issue.patch \ - patches/security/20130618/7158805-nested_subroutine_rewriting.patch \ - patches/security/20130618/8001330-checking_order_improvement.patch \ - patches/openjdk/7036747-elfstringtable.patch \ - patches/openjdk/7017732-move_static_fields_to_class.patch \ - patches/openjdk/6990754-use_native_memory_for_symboltable.patch \ - patches/openjdk/6990754-handle_renames.patch \ - patches/openjdk/7008809-report_class_in_arraystoreexception.patch \ - patches/openjdk/7086585-flexible_field_injection.patch \ - patches/security/20130618/hs_merge-01.patch \ - patches/security/20130618/hs_merge-02.patch \ - patches/security/20130618/hs_merge-03.patch \ - patches/openjdk/7014851-unused_parallel_compaction_code.patch \ - patches/security/20130618/hs_merge-04.patch \ + patches/security/20130618/7158805-nested_subroutine_rewriting-it6.patch \ + patches/security/20130618/8001330-checking_order_improvement-it6.patch \ patches/security/20130618/8000642-better_transportation_handling.patch \ patches/openjdk/6786028-wcag_bold_tags.patch \ patches/openjdk/6786682-wcag_lang.patch \ diff -r a1cb163cb044 -r ea7bce0f610a patches/security/20130618/7158805-nested_subroutine_rewriting-it6.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/security/20130618/7158805-nested_subroutine_rewriting-it6.patch Wed Jun 26 15:10:59 2013 -0400 @@ -0,0 +1,743 @@ +*** openjdk/hotspot/src/share/vm/memory/allocation.cpp 2011-11-14 17:07:35.000000000 -0500 +--- openjdk/hotspot/src/share/vm/memory/allocation.cpp 2013-06-25 14:55:54.749915166 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 199,205 **** + ChunkPool(size_t size) : _size(size) { _first = NULL; _num_chunks = _num_used = 0; } + + // Allocate a new chunk from the pool (might expand the pool) +! void* allocate(size_t bytes) { + assert(bytes == _size, "bad size"); + void* p = NULL; + { ThreadCritical tc; +--- 199,205 ---- + ChunkPool(size_t size) : _size(size) { _first = NULL; _num_chunks = _num_used = 0; } + + // Allocate a new chunk from the pool (might expand the pool) +! void* allocate(size_t bytes, AllocFailType alloc_failmode) { + assert(bytes == _size, "bad size"); + void* p = NULL; + { ThreadCritical tc; +*************** +*** 207,215 **** + p = get_first(); + if (p == NULL) p = os::malloc(bytes); + } +! if (p == NULL) + vm_exit_out_of_memory(bytes, "ChunkPool::allocate"); +! + return p; + } + +--- 207,215 ---- + p = get_first(); + if (p == NULL) p = os::malloc(bytes); + } +! if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { + vm_exit_out_of_memory(bytes, "ChunkPool::allocate"); +! } + return p; + } + +*************** +*** 300,306 **** + //-------------------------------------------------------------------------------------- + // Chunk implementation + +! void* Chunk::operator new(size_t requested_size, size_t length) { + // requested_size is equal to sizeof(Chunk) but in order for the arena + // allocations to come out aligned as expected the size must be aligned + // to expected arean alignment. +--- 300,306 ---- + //-------------------------------------------------------------------------------------- + // Chunk implementation + +! void* Chunk::operator new(size_t requested_size, AllocFailType alloc_failmode, size_t length) { + // requested_size is equal to sizeof(Chunk) but in order for the arena + // allocations to come out aligned as expected the size must be aligned + // to expected arean alignment. +*************** +*** 308,320 **** + assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment"); + size_t bytes = ARENA_ALIGN(requested_size) + length; + switch (length) { +! case Chunk::size: return ChunkPool::large_pool()->allocate(bytes); +! case Chunk::medium_size: return ChunkPool::medium_pool()->allocate(bytes); +! case Chunk::init_size: return ChunkPool::small_pool()->allocate(bytes); + default: { +! void *p = os::malloc(bytes); +! if (p == NULL) + vm_exit_out_of_memory(bytes, "Chunk::new"); + return p; + } + } +--- 308,321 ---- + assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment"); + size_t bytes = ARENA_ALIGN(requested_size) + length; + switch (length) { +! case Chunk::size: return ChunkPool::large_pool()->allocate(bytes, alloc_failmode); +! case Chunk::medium_size: return ChunkPool::medium_pool()->allocate(bytes, alloc_failmode); +! case Chunk::init_size: return ChunkPool::small_pool()->allocate(bytes, alloc_failmode); + default: { +! void* p = os::malloc(bytes); +! if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) { + vm_exit_out_of_memory(bytes, "Chunk::new"); ++ } + return p; + } + } +*************** +*** 367,380 **** + Arena::Arena(size_t init_size) { + size_t round_size = (sizeof (char *)) - 1; + init_size = (init_size+round_size) & ~round_size; +! _first = _chunk = new (init_size) Chunk(init_size); + _hwm = _chunk->bottom(); // Save the cached hwm, max + _max = _chunk->top(); + set_size_in_bytes(init_size); + } + + Arena::Arena() { +! _first = _chunk = new (Chunk::init_size) Chunk(Chunk::init_size); + _hwm = _chunk->bottom(); // Save the cached hwm, max + _max = _chunk->top(); + set_size_in_bytes(Chunk::init_size); +--- 368,381 ---- + Arena::Arena(size_t init_size) { + size_t round_size = (sizeof (char *)) - 1; + init_size = (init_size+round_size) & ~round_size; +! _first = _chunk = new (AllocFailStrategy::EXIT_OOM, init_size) Chunk(init_size); + _hwm = _chunk->bottom(); // Save the cached hwm, max + _max = _chunk->top(); + set_size_in_bytes(init_size); + } + + Arena::Arena() { +! _first = _chunk = new (AllocFailStrategy::EXIT_OOM, Chunk::init_size) Chunk(Chunk::init_size); + _hwm = _chunk->bottom(); // Save the cached hwm, max + _max = _chunk->top(); + set_size_in_bytes(Chunk::init_size); +*************** +*** 427,441 **** + } + + // Grow a new Chunk +! void* Arena::grow( size_t x ) { + // Get minimal required size. Either real big, or even bigger for giant objs + size_t len = MAX2(x, (size_t) Chunk::size); + + Chunk *k = _chunk; // Get filled-up chunk address +! _chunk = new (len) Chunk(len); + + if (_chunk == NULL) { +! signal_out_of_memory(len * Chunk::aligned_overhead_size(), "Arena::grow"); + } + + if (k) k->set_next(_chunk); // Append new chunk to end of linked list +--- 428,442 ---- + } + + // Grow a new Chunk +! void* Arena::grow(size_t x, AllocFailType alloc_failmode) { + // Get minimal required size. Either real big, or even bigger for giant objs + size_t len = MAX2(x, (size_t) Chunk::size); + + Chunk *k = _chunk; // Get filled-up chunk address +! _chunk = new (alloc_failmode, len) Chunk(len); + + if (_chunk == NULL) { +! return NULL; + } + + if (k) k->set_next(_chunk); // Append new chunk to end of linked list +*************** +*** 451,463 **** + + + // Reallocate storage in Arena. +! void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size) { + assert(new_size >= 0, "bad size"); + if (new_size == 0) return NULL; + #ifdef ASSERT + if (UseMallocOnly) { + // always allocate a new object (otherwise we'll free this one twice) +! char* copy = (char*)Amalloc(new_size); + size_t n = MIN2(old_size, new_size); + if (n > 0) memcpy(copy, old_ptr, n); + Afree(old_ptr,old_size); // Mostly done to keep stats accurate +--- 452,467 ---- + + + // Reallocate storage in Arena. +! void *Arena::Arealloc(void* old_ptr, size_t old_size, size_t new_size, AllocFailType alloc_failmode) { + assert(new_size >= 0, "bad size"); + if (new_size == 0) return NULL; + #ifdef ASSERT + if (UseMallocOnly) { + // always allocate a new object (otherwise we'll free this one twice) +! char* copy = (char*)Amalloc(new_size, alloc_failmode); +! if (copy == NULL) { +! return NULL; +! } + size_t n = MIN2(old_size, new_size); + if (n > 0) memcpy(copy, old_ptr, n); + Afree(old_ptr,old_size); // Mostly done to keep stats accurate +*************** +*** 483,489 **** + } + + // Oops, got to relocate guts +! void *new_ptr = Amalloc(new_size); + memcpy( new_ptr, c_old, old_size ); + Afree(c_old,old_size); // Mostly done to keep stats accurate + return new_ptr; +--- 487,496 ---- + } + + // Oops, got to relocate guts +! void *new_ptr = Amalloc(new_size, alloc_failmode); +! if (new_ptr == NULL) { +! return NULL; +! } + memcpy( new_ptr, c_old, old_size ); + Afree(c_old,old_size); // Mostly done to keep stats accurate + return new_ptr; +*** openjdk/hotspot/src/share/vm/memory/allocation.hpp 2011-11-14 17:07:35.000000000 -0500 +--- openjdk/hotspot/src/share/vm/memory/allocation.hpp 2013-06-25 15:13:06.325141250 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 34,43 **** +--- 34,51 ---- + #include "opto/c2_globals.hpp" + #endif + ++ #include ++ + #define ARENA_ALIGN_M1 (((size_t)(ARENA_AMALLOC_ALIGNMENT)) - 1) + #define ARENA_ALIGN_MASK (~((size_t)ARENA_ALIGN_M1)) + #define ARENA_ALIGN(x) ((((size_t)(x)) + ARENA_ALIGN_M1) & ARENA_ALIGN_MASK) + ++ class AllocFailStrategy { ++ public: ++ enum AllocFailEnum { EXIT_OOM, RETURN_NULL }; ++ }; ++ typedef AllocFailStrategy::AllocFailEnum AllocFailType; ++ + // All classes in the virtual machine must be subclassed + // by one of the following allocation classes: + // +*************** +*** 152,158 **** + Chunk* _next; // Next Chunk in list + const size_t _len; // Size of this Chunk + public: +! void* operator new(size_t size, size_t length); + void operator delete(void* p); + Chunk(size_t length); + +--- 160,166 ---- + Chunk* _next; // Next Chunk in list + const size_t _len; // Size of this Chunk + public: +! void* operator new(size_t size, AllocFailType alloc_failmode, size_t length); + void operator delete(void* p); + Chunk(size_t length); + +*************** +*** 200,206 **** + Chunk *_first; // First chunk + Chunk *_chunk; // current chunk + char *_hwm, *_max; // High water mark and max in current chunk +! void* grow(size_t x); // Get a new Chunk of at least size x + NOT_PRODUCT(size_t _size_in_bytes;) // Size of arena (used for memory usage tracing) + NOT_PRODUCT(static size_t _bytes_allocated;) // total #bytes allocated since start + friend class AllocStats; +--- 208,215 ---- + Chunk *_first; // First chunk + Chunk *_chunk; // current chunk + char *_hwm, *_max; // High water mark and max in current chunk +! // Get a new Chunk of at least size x +! void* grow(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); + NOT_PRODUCT(size_t _size_in_bytes;) // Size of arena (used for memory usage tracing) + NOT_PRODUCT(static size_t _bytes_allocated;) // total #bytes allocated since start + friend class AllocStats; +*************** +*** 209,218 **** + + void signal_out_of_memory(size_t request, const char* whence) const; + +! void check_for_overflow(size_t request, const char* whence) const { + if (UINTPTR_MAX - request < (uintptr_t)_hwm) { + signal_out_of_memory(request, whence); + } + } + + public: +--- 218,232 ---- + + void signal_out_of_memory(size_t request, const char* whence) const; + +! bool check_for_overflow(size_t request, const char* whence, +! AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) const { + if (UINTPTR_MAX - request < (uintptr_t)_hwm) { ++ if (alloc_failmode == AllocFailStrategy::RETURN_NULL) { ++ return false; ++ } + signal_out_of_memory(request, whence); + } ++ return true; + } + + public: +*************** +*** 224,237 **** + char* hwm() const { return _hwm; } + + // Fast allocate in the arena. Common case is: pointer test + increment. +! void* Amalloc(size_t x) { + assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); + x = ARENA_ALIGN(x); + debug_only(if (UseMallocOnly) return malloc(x);) +! check_for_overflow(x, "Arena::Amalloc"); + NOT_PRODUCT(_bytes_allocated += x); + if (_hwm + x > _max) { +! return grow(x); + } else { + char *old = _hwm; + _hwm += x; +--- 238,252 ---- + char* hwm() const { return _hwm; } + + // Fast allocate in the arena. Common case is: pointer test + increment. +! void* Amalloc(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { + assert(is_power_of_2(ARENA_AMALLOC_ALIGNMENT) , "should be a power of 2"); + x = ARENA_ALIGN(x); + debug_only(if (UseMallocOnly) return malloc(x);) +! if (!check_for_overflow(x, "Arena::Amalloc", alloc_failmode)) +! return NULL; + NOT_PRODUCT(_bytes_allocated += x); + if (_hwm + x > _max) { +! return grow(x, alloc_failmode); + } else { + char *old = _hwm; + _hwm += x; +*************** +*** 239,251 **** + } + } + // Further assume size is padded out to words +! void *Amalloc_4(size_t x) { + assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); + debug_only(if (UseMallocOnly) return malloc(x);) +! check_for_overflow(x, "Arena::Amalloc_4"); + NOT_PRODUCT(_bytes_allocated += x); + if (_hwm + x > _max) { +! return grow(x); + } else { + char *old = _hwm; + _hwm += x; +--- 254,267 ---- + } + } + // Further assume size is padded out to words +! void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { + assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); + debug_only(if (UseMallocOnly) return malloc(x);) +! if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode)) +! return NULL; + NOT_PRODUCT(_bytes_allocated += x); + if (_hwm + x > _max) { +! return grow(x, alloc_failmode); + } else { + char *old = _hwm; + _hwm += x; +*************** +*** 255,261 **** + + // Allocate with 'double' alignment. It is 8 bytes on sparc. + // In other cases Amalloc_D() should be the same as Amalloc_4(). +! void* Amalloc_D(size_t x) { + assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); + debug_only(if (UseMallocOnly) return malloc(x);) + #if defined(SPARC) && !defined(_LP64) +--- 271,277 ---- + + // Allocate with 'double' alignment. It is 8 bytes on sparc. + // In other cases Amalloc_D() should be the same as Amalloc_4(). +! void* Amalloc_D(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { + assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" ); + debug_only(if (UseMallocOnly) return malloc(x);) + #if defined(SPARC) && !defined(_LP64) +*************** +*** 263,272 **** + size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; + x += delta; + #endif +! check_for_overflow(x, "Arena::Amalloc_D"); + NOT_PRODUCT(_bytes_allocated += x); + if (_hwm + x > _max) { +! return grow(x); // grow() returns a result aligned >= 8 bytes. + } else { + char *old = _hwm; + _hwm += x; +--- 279,289 ---- + size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm; + x += delta; + #endif +! if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode)) +! return NULL; + NOT_PRODUCT(_bytes_allocated += x); + if (_hwm + x > _max) { +! return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes. + } else { + char *old = _hwm; + _hwm += x; +*************** +*** 286,292 **** + if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr; + } + +! void *Arealloc( void *old_ptr, size_t old_size, size_t new_size ); + + // Move contents of this arena into an empty arena + Arena *move_contents(Arena *empty_arena); +--- 303,310 ---- + if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr; + } + +! void *Arealloc( void *old_ptr, size_t old_size, size_t new_size, +! AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); + + // Move contents of this arena into an empty arena + Arena *move_contents(Arena *empty_arena); +*************** +*** 328,336 **** + + + //%note allocation_1 +! extern char* resource_allocate_bytes(size_t size); +! extern char* resource_allocate_bytes(Thread* thread, size_t size); +! extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size); + extern void resource_free_bytes( char *old, size_t size ); + + //---------------------------------------------------------------------- +--- 346,357 ---- + + + //%note allocation_1 +! extern char* resource_allocate_bytes(size_t size, +! AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); +! extern char* resource_allocate_bytes(Thread* thread, size_t size, +! AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); +! extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size, +! AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM); + extern void resource_free_bytes( char *old, size_t size ); + + //---------------------------------------------------------------------- +*************** +*** 376,381 **** +--- 397,409 ---- + DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);) + return res; + } ++ ++ void* operator new(size_t size, const std::nothrow_t& nothrow_constant) { ++ address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL); ++ DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);) ++ return res; ++ } ++ + void operator delete(void* p); + }; + +*************** +*** 386,391 **** +--- 414,422 ---- + #define NEW_RESOURCE_ARRAY(type, size)\ + (type*) resource_allocate_bytes((size) * sizeof(type)) + ++ #define NEW_RESOURCE_ARRAY_RETURN_NULL(type, size)\ ++ (type*) resource_allocate_bytes((size) * sizeof(type), AllocFailStrategy::RETURN_NULL) ++ + #define NEW_RESOURCE_ARRAY_IN_THREAD(thread, type, size)\ + (type*) resource_allocate_bytes(thread, (size) * sizeof(type)) + +*** openjdk/hotspot/src/share/vm/memory/allocation.inline.hpp 2011-11-14 17:07:35.000000000 -0500 +--- openjdk/hotspot/src/share/vm/memory/allocation.inline.hpp 2013-06-25 14:55:54.751915115 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 34,58 **** + + + // allocate using malloc; will fail if no memory available +! inline char* AllocateHeap(size_t size, const char* name = NULL) { + char* p = (char*) os::malloc(size); + #ifdef ASSERT + if (PrintMallocFree) trace_heap_malloc(size, name, p); + #else + Unused_Variable(name); + #endif +! if (p == NULL) vm_exit_out_of_memory(size, name); + return p; + } + +! inline char* ReallocateHeap(char *old, size_t size, const char* name = NULL) { + char* p = (char*) os::realloc(old,size); + #ifdef ASSERT + if (PrintMallocFree) trace_heap_malloc(size, name, p); + #else + Unused_Variable(name); + #endif +! if (p == NULL) vm_exit_out_of_memory(size, name); + return p; + } + +--- 34,62 ---- + + + // allocate using malloc; will fail if no memory available +! inline char* AllocateHeap(size_t size, const char* name = NULL, +! AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { + char* p = (char*) os::malloc(size); + #ifdef ASSERT + if (PrintMallocFree) trace_heap_malloc(size, name, p); + #else + Unused_Variable(name); + #endif +! if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) +! vm_exit_out_of_memory(size, "AllocateHeap"); + return p; + } + +! inline char* ReallocateHeap(char *old, size_t size, const char* name = NULL, +! AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { + char* p = (char*) os::realloc(old,size); + #ifdef ASSERT + if (PrintMallocFree) trace_heap_malloc(size, name, p); + #else + Unused_Variable(name); + #endif +! if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) +! vm_exit_out_of_memory(size, "ReallocateHeap"); + return p; + } + +*** openjdk/hotspot/src/share/vm/memory/resourceArea.cpp 2011-11-14 17:07:36.000000000 -0500 +--- openjdk/hotspot/src/share/vm/memory/resourceArea.cpp 2013-06-25 14:55:54.787914183 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 42,56 **** + // The following routines are declared in allocation.hpp and used everywhere: + + // Allocation in thread-local resource area +! extern char* resource_allocate_bytes(size_t size) { +! return Thread::current()->resource_area()->allocate_bytes(size); + } +! extern char* resource_allocate_bytes(Thread* thread, size_t size) { +! return thread->resource_area()->allocate_bytes(size); + } + +! extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size){ +! return (char*)Thread::current()->resource_area()->Arealloc(old, old_size, new_size); + } + + extern void resource_free_bytes( char *old, size_t size ) { +--- 42,57 ---- + // The following routines are declared in allocation.hpp and used everywhere: + + // Allocation in thread-local resource area +! extern char* resource_allocate_bytes(size_t size, AllocFailType alloc_failmode) { +! return Thread::current()->resource_area()->allocate_bytes(size, alloc_failmode); + } +! extern char* resource_allocate_bytes(Thread* thread, size_t size, AllocFailType alloc_failmode) { +! return thread->resource_area()->allocate_bytes(size, alloc_failmode); + } + +! extern char* resource_reallocate_bytes( char *old, size_t old_size, size_t new_size, +! AllocFailType alloc_failmode){ +! return (char*)Thread::current()->resource_area()->Arealloc(old, old_size, new_size, alloc_failmode); + } + + extern void resource_free_bytes( char *old, size_t size ) { +*** openjdk/hotspot/src/share/vm/memory/resourceArea.hpp 2011-11-14 17:07:36.000000000 -0500 +--- openjdk/hotspot/src/share/vm/memory/resourceArea.hpp 2013-06-25 14:55:54.789914131 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 64,70 **** + debug_only(_nesting = 0;); + } + +! char* allocate_bytes(size_t size) { + #ifdef ASSERT + if (_nesting < 1 && !_warned++) + fatal("memory leak: allocating without ResourceMark"); +--- 64,70 ---- + debug_only(_nesting = 0;); + } + +! char* allocate_bytes(size_t size, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) { + #ifdef ASSERT + if (_nesting < 1 && !_warned++) + fatal("memory leak: allocating without ResourceMark"); +*************** +*** 74,80 **** + return (*save = (char*)os::malloc(size)); + } + #endif +! return (char*)Amalloc(size); + } + + debug_only(int nesting() const { return _nesting; }); +--- 74,80 ---- + return (*save = (char*)os::malloc(size)); + } + #endif +! return (char*)Amalloc(size, alloc_failmode); + } + + debug_only(int nesting() const { return _nesting; }); +*** openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp 2011-11-14 17:07:36.000000000 -0500 +--- openjdk/hotspot/src/share/vm/oops/generateOopMap.cpp 2013-06-25 14:55:54.790914103 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 643,653 **** + // CellType handling methods + // + + void GenerateOopMap::init_state() { + _state_len = _max_locals + _max_stack + _max_monitors; +! _state = NEW_RESOURCE_ARRAY(CellTypeState, _state_len); + memset(_state, 0, _state_len * sizeof(CellTypeState)); +! _state_vec_buf = NEW_RESOURCE_ARRAY(char, MAX3(_max_locals, _max_stack, _max_monitors) + 1/*for null terminator char */); + } + + void GenerateOopMap::make_context_uninitialized() { +--- 643,662 ---- + // CellType handling methods + // + ++ // Allocate memory and throw LinkageError if failure. ++ #define ALLOC_RESOURCE_ARRAY(var, type, count) \ ++ var = NEW_RESOURCE_ARRAY_RETURN_NULL(type, count); \ ++ if (var == NULL) { \ ++ report_error("Cannot reserve enough memory to analyze this method"); \ ++ return; \ ++ } ++ + void GenerateOopMap::init_state() { + _state_len = _max_locals + _max_stack + _max_monitors; +! ALLOC_RESOURCE_ARRAY(_state, CellTypeState, _state_len); + memset(_state, 0, _state_len * sizeof(CellTypeState)); +! int count = MAX3(_max_locals, _max_stack, _max_monitors) + 1/*for null terminator char */; +! ALLOC_RESOURCE_ARRAY(_state_vec_buf, char, count) + } + + void GenerateOopMap::make_context_uninitialized() { +*************** +*** 905,911 **** + // But cumbersome since we don't know the stack heights yet. (Nor the + // monitor stack heights...) + +! _basic_blocks = NEW_RESOURCE_ARRAY(BasicBlock, _bb_count); + + // Make a pass through the bytecodes. Count the number of monitorenters. + // This can be used an upper bound on the monitor stack depth in programs +--- 914,920 ---- + // But cumbersome since we don't know the stack heights yet. (Nor the + // monitor stack heights...) + +! ALLOC_RESOURCE_ARRAY(_basic_blocks, BasicBlock, _bb_count); + + // Make a pass through the bytecodes. Count the number of monitorenters. + // This can be used an upper bound on the monitor stack depth in programs +*************** +*** 976,983 **** + return; + } + +! CellTypeState *basicBlockState = +! NEW_RESOURCE_ARRAY(CellTypeState, bbNo * _state_len); + memset(basicBlockState, 0, bbNo * _state_len * sizeof(CellTypeState)); + + // Make a pass over the basicblocks and assign their state vectors. +--- 985,992 ---- + return; + } + +! CellTypeState *basicBlockState; +! ALLOC_RESOURCE_ARRAY(basicBlockState, CellTypeState, bbNo * _state_len); + memset(basicBlockState, 0, bbNo * _state_len * sizeof(CellTypeState)); + + // Make a pass over the basicblocks and assign their state vectors. diff -r a1cb163cb044 -r ea7bce0f610a patches/security/20130618/8001330-checking_order_improvement-it6.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/security/20130618/8001330-checking_order_improvement-it6.patch Wed Jun 26 15:10:59 2013 -0400 @@ -0,0 +1,500 @@ +*** openjdk/hotspot/src/share/vm/classfile/javaClasses.cpp 2013-06-26 09:52:56.103661791 -0400 +--- openjdk--/hotspot/src/share/vm/classfile/javaClasses.cpp 2013-06-25 15:28:43.225907956 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 2559,2564 **** +--- 2559,2565 ---- + int java_security_AccessControlContext::_context_offset = 0; + int java_security_AccessControlContext::_privilegedContext_offset = 0; + int java_security_AccessControlContext::_isPrivileged_offset = 0; ++ int java_security_AccessControlContext::_isAuthorized_offset = -1; + + void java_security_AccessControlContext::compute_offsets() { + assert(_isPrivileged_offset == 0, "offsets should be initialized only once"); +*************** +*** 2579,2587 **** +--- 2580,2599 ---- + fatal("Invalid layout of java.security.AccessControlContext"); + } + _isPrivileged_offset = fd.offset(); ++ ++ // The offset may not be present for bootstrapping with older JDK. ++ if (ik->find_local_field(vmSymbols::isAuthorized_name(), vmSymbols::bool_signature(), &fd)) { ++ _isAuthorized_offset = fd.offset(); ++ } + } + + ++ bool java_security_AccessControlContext::is_authorized(Handle context) { ++ assert(context.not_null() && context->klass() == SystemDictionary::AccessControlContext_klass(), "Invalid type"); ++ assert(_isAuthorized_offset != -1, "should be set"); ++ return context->bool_field(_isAuthorized_offset) != 0; ++ } ++ + oop java_security_AccessControlContext::create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS) { + assert(_isPrivileged_offset != 0, "offsets should have been initialized"); + // Ensure klass is initialized +*************** +*** 2592,2597 **** +--- 2604,2611 ---- + result->obj_field_put(_context_offset, context()); + result->obj_field_put(_privilegedContext_offset, privileged_context()); + result->bool_field_put(_isPrivileged_offset, isPrivileged); ++ // whitelist AccessControlContexts created by the JVM. ++ result->bool_field_put(_isAuthorized_offset, true); + return result; + } + +*************** +*** 2656,2661 **** +--- 2670,2684 ---- + } + + ++ bool java_lang_System::has_security_manager() { ++ instanceKlass* ik = instanceKlass::cast(SystemDictionary::System_klass()); ++ address addr = ik->static_field_addr(static_security_offset); ++ if (UseCompressedOops) { ++ return oopDesc::load_decode_heap_oop((narrowOop *)addr) != NULL; ++ } else { ++ return oopDesc::load_decode_heap_oop((oop*)addr) != NULL; ++ } ++ } + + int java_lang_String::value_offset; + int java_lang_String::offset_offset; +*************** +*** 2712,2717 **** +--- 2735,2741 ---- + int java_lang_System::static_in_offset; + int java_lang_System::static_out_offset; + int java_lang_System::static_err_offset; ++ int java_lang_System::static_security_offset; + int java_lang_StackTraceElement::declaringClass_offset; + int java_lang_StackTraceElement::methodName_offset; + int java_lang_StackTraceElement::fileName_offset; +*************** +*** 2866,2871 **** +--- 2890,2896 ---- + java_lang_System::static_in_offset = java_lang_System::hc_static_in_offset * x; + java_lang_System::static_out_offset = java_lang_System::hc_static_out_offset * x; + java_lang_System::static_err_offset = java_lang_System::hc_static_err_offset * x; ++ java_lang_System::static_security_offset = java_lang_System::hc_static_security_offset * x; + + // java_lang_StackTraceElement + java_lang_StackTraceElement::declaringClass_offset = java_lang_StackTraceElement::hc_declaringClass_offset * x + header; +*************** +*** 3067,3072 **** +--- 3092,3098 ---- + CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, in, "Ljava/io/InputStream;"); + CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, out, "Ljava/io/PrintStream;"); + CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, err, "Ljava/io/PrintStream;"); ++ CHECK_STATIC_OFFSET("java/lang/System", java_lang_System, security, "Ljava/lang/SecurityManager;"); + + // java.lang.StackTraceElement + +*** openjdk/hotspot/src/share/vm/classfile/javaClasses.hpp 2013-06-26 09:52:56.106661711 -0400 +--- openjdk--/hotspot/src/share/vm/classfile/javaClasses.hpp 2013-06-25 15:28:43.226907930 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 1146,1156 **** +--- 1146,1159 ---- + static int _context_offset; + static int _privilegedContext_offset; + static int _isPrivileged_offset; ++ static int _isAuthorized_offset; + + static void compute_offsets(); + public: + static oop create(objArrayHandle context, bool isPrivileged, Handle privileged_context, TRAPS); + ++ static bool is_authorized(Handle context); ++ + // Debugging/initialization + friend class JavaClasses; + }; +*************** +*** 1186,1198 **** + enum { + hc_static_in_offset = 0, + hc_static_out_offset = 1, +! hc_static_err_offset = 2 + }; + + static int offset_of_static_fields; + static int static_in_offset; + static int static_out_offset; + static int static_err_offset; + + static void compute_offsets(); + +--- 1189,1203 ---- + enum { + hc_static_in_offset = 0, + hc_static_out_offset = 1, +! hc_static_err_offset = 2, +! hc_static_security_offset = 3 + }; + + static int offset_of_static_fields; + static int static_in_offset; + static int static_out_offset; + static int static_err_offset; ++ static int static_security_offset; + + static void compute_offsets(); + +*************** +*** 1201,1206 **** +--- 1206,1213 ---- + static int out_offset_in_bytes(); + static int err_offset_in_bytes(); + ++ static bool has_security_manager(); ++ + // Debugging + friend class JavaClasses; + }; +*** openjdk/hotspot/src/share/vm/classfile/vmSymbols.hpp 2011-11-14 17:07:34.000000000 -0500 +--- openjdk--/hotspot/src/share/vm/classfile/vmSymbols.hpp 2013-06-25 15:28:43.227907903 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 93,98 **** +--- 93,99 ---- + template(java_lang_CharSequence, "java/lang/CharSequence") \ + template(java_security_AccessControlContext, "java/security/AccessControlContext") \ + template(java_security_ProtectionDomain, "java/security/ProtectionDomain") \ ++ template(impliesCreateAccessControlContext_name, "impliesCreateAccessControlContext") \ + template(java_io_OutputStream, "java/io/OutputStream") \ + template(java_io_Reader, "java/io/Reader") \ + template(java_io_BufferedReader, "java/io/BufferedReader") \ +*************** +*** 315,320 **** +--- 316,322 ---- + template(contextClassLoader_name, "contextClassLoader") \ + template(inheritedAccessControlContext_name, "inheritedAccessControlContext") \ + template(isPrivileged_name, "isPrivileged") \ ++ template(isAuthorized_name, "isAuthorized") \ + template(wait_name, "wait") \ + template(checkPackageAccess_name, "checkPackageAccess") \ + template(stackSize_name, "stackSize") \ +*** openjdk/hotspot/src/share/vm/memory/universe.cpp 2011-11-14 17:07:36.000000000 -0500 +--- openjdk--/hotspot/src/share/vm/memory/universe.cpp 2013-06-25 15:28:43.267906879 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 143,148 **** +--- 143,149 ---- + oop Universe::_the_min_jint_string = NULL; + LatestMethodOopCache* Universe::_finalizer_register_cache = NULL; + LatestMethodOopCache* Universe::_loader_addClass_cache = NULL; ++ LatestMethodOopCache* Universe::_pd_implies_cache = NULL; + ActiveMethodOopsCache* Universe::_reflect_invoke_cache = NULL; + oop Universe::_out_of_memory_error_java_heap = NULL; + oop Universe::_out_of_memory_error_perm_gen = NULL; +*************** +*** 265,270 **** +--- 266,272 ---- + f->do_oop((oop*)&_the_min_jint_string); + _finalizer_register_cache->oops_do(f); + _loader_addClass_cache->oops_do(f); ++ _pd_implies_cache->oops_do(f); + _reflect_invoke_cache->oops_do(f); + f->do_oop((oop*)&_out_of_memory_error_java_heap); + f->do_oop((oop*)&_out_of_memory_error_perm_gen); +*************** +*** 787,792 **** +--- 789,795 ---- + // CompactingPermGenGen::initialize_oops() tries to populate them. + Universe::_finalizer_register_cache = new LatestMethodOopCache(); + Universe::_loader_addClass_cache = new LatestMethodOopCache(); ++ Universe::_pd_implies_cache = new LatestMethodOopCache(); + Universe::_reflect_invoke_cache = new ActiveMethodOopsCache(); + + if (UseSharedSpaces) { +*************** +*** 1137,1142 **** +--- 1140,1162 ---- + Universe::_loader_addClass_cache->init( + SystemDictionary::ClassLoader_klass(), m, CHECK_false); + ++ // Setup method for checking protection domain ++ instanceKlass::cast(SystemDictionary::ProtectionDomain_klass())->link_class(CHECK_false); ++ m = instanceKlass::cast(SystemDictionary::ProtectionDomain_klass())-> ++ find_method(vmSymbols::impliesCreateAccessControlContext_name(), ++ vmSymbols::void_boolean_signature()); ++ // Allow NULL which should only happen with bootstrapping. ++ if (m != NULL) { ++ if (m->is_static()) { ++ // NoSuchMethodException doesn't actually work because it tries to run the ++ // function before java_lang_Class is linked. Print error and exit. ++ tty->print_cr("ProtectionDomain.impliesCreateAccessControlContext() has the wrong linkage"); ++ return false; // initialization failed ++ } ++ Universe::_pd_implies_cache->init( ++ SystemDictionary::ProtectionDomain_klass(), m, CHECK_false);; ++ } ++ + // The folowing is initializing converter functions for serialization in + // JVM.cpp. If we clean up the StrictMath code above we may want to find + // a better solution for this as well. +*************** +*** 1570,1575 **** +--- 1590,1596 ---- + + + methodOop LatestMethodOopCache::get_methodOop() { ++ if (klass() == NULL) return NULL; + instanceKlass* ik = instanceKlass::cast(klass()); + methodOop m = ik->method_with_idnum(method_idnum()); + assert(m != NULL, "sanity check"); +*** openjdk/hotspot/src/share/vm/memory/universe.hpp 2011-11-14 17:07:36.000000000 -0500 +--- openjdk--/hotspot/src/share/vm/memory/universe.hpp 2013-06-25 15:28:43.269906816 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 179,184 **** +--- 179,185 ---- + static oop _the_min_jint_string; // A cache of "-2147483648" as a Java string + static LatestMethodOopCache* _finalizer_register_cache; // static method for registering finalizable objects + static LatestMethodOopCache* _loader_addClass_cache; // method for registering loaded classes in class loader vector ++ static LatestMethodOopCache* _pd_implies_cache; // method for checking protection domain attributes + static ActiveMethodOopsCache* _reflect_invoke_cache; // method for security checks + static oop _out_of_memory_error_java_heap; // preallocated error object (no backtrace) + static oop _out_of_memory_error_perm_gen; // preallocated error object (no backtrace) +*************** +*** 322,327 **** +--- 323,329 ---- + static oop the_min_jint_string() { return _the_min_jint_string; } + static methodOop finalizer_register_method() { return _finalizer_register_cache->get_methodOop(); } + static methodOop loader_addClass_method() { return _loader_addClass_cache->get_methodOop(); } ++ static methodOop protection_domain_implies_method() { return _pd_implies_cache->get_methodOop(); } + static ActiveMethodOopsCache* reflect_invoke_cache() { return _reflect_invoke_cache; } + static oop null_ptr_exception_instance() { return _null_ptr_exception_instance; } + static oop arithmetic_exception_instance() { return _arithmetic_exception_instance; } +*** openjdk/hotspot/src/share/vm/prims/jvm.cpp 2011-11-14 17:07:37.000000000 -0500 +--- openjdk--/hotspot/src/share/vm/prims/jvm.cpp 2013-06-25 15:28:43.324905405 -0400 +*************** +*** 1,5 **** + /* +! * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +--- 1,5 ---- + /* +! * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it +*************** +*** 1101,1106 **** +--- 1101,1156 ---- + } + JVM_END + ++ static bool is_authorized(Handle context, instanceKlassHandle klass, TRAPS) { ++ // If there is a security manager and protection domain, check the access ++ // in the protection domain, otherwise it is authorized. ++ if (java_lang_System::has_security_manager()) { ++ ++ // For bootstrapping, if pd implies method isn't in the JDK, allow ++ // this context to revert to older behavior. ++ // In this case the isAuthorized field in AccessControlContext is also not ++ // present. ++ if (Universe::protection_domain_implies_method() == NULL) { ++ return true; ++ } ++ ++ // Whitelist certain access control contexts ++ if (java_security_AccessControlContext::is_authorized(context)) { ++ return true; ++ } ++ ++ oop prot = klass->protection_domain(); ++ if (prot != NULL) { ++ // Call pd.implies(new SecurityPermission("createAccessControlContext")) ++ // in the new wrapper. ++ methodHandle m(THREAD, Universe::protection_domain_implies_method()); ++ Handle h_prot(THREAD, prot); ++ JavaValue result(T_BOOLEAN); ++ JavaCallArguments args(h_prot); ++ JavaCalls::call(&result, m, &args, CHECK_false); ++ return (result.get_jboolean() != 0); ++ } ++ } ++ return true; ++ } ++ ++ // Create an AccessControlContext with a protection domain with null codesource ++ // and null permissions - which gives no permissions. ++ oop create_dummy_access_control_context(TRAPS) { ++ instanceKlassHandle pd_klass (THREAD, SystemDictionary::ProtectionDomain_klass()); ++ // new ProtectionDomain(null,null); ++ oop null_protection_domain = pd_klass->allocate_instance(CHECK_NULL); ++ Handle null_pd(THREAD, null_protection_domain); ++ ++ // new ProtectionDomain[] {pd}; ++ objArrayOop context = oopFactory::new_objArray(pd_klass(), 1, CHECK_NULL); ++ context->obj_at_put(0, null_pd()); ++ ++ // new AccessControlContext(new ProtectionDomain[] {pd}) ++ objArrayHandle h_context(THREAD, context); ++ oop result = java_security_AccessControlContext::create(h_context, false, Handle(), CHECK_NULL); ++ return result; ++ } + + JVM_ENTRY(jobject, JVM_DoPrivileged(JNIEnv *env, jclass cls, jobject action, jobject context, jboolean wrapException)) + JVMWrapper("JVM_DoPrivileged"); +*************** +*** 1109,1116 **** + THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action"); + } + +! // Stack allocated list of privileged stack elements +! PrivilegedElement pi; + + // Check that action object understands "Object run()" + Handle object (THREAD, JNIHandles::resolve(action)); +--- 1159,1187 ---- + THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), "Null action"); + } + +! // Compute the frame initiating the do privileged operation and setup the privileged stack +! vframeStream vfst(thread); +! vfst.security_get_caller_frame(1); +! +! if (vfst.at_end()) { +! THROW_MSG_0(vmSymbols::java_lang_InternalError(), "no caller?"); +! } +! +! methodOop method = vfst.method(); +! instanceKlassHandle klass (THREAD, method->method_holder()); +! +! // Check that action object understands "Object run()" +! Handle h_context; +! if (context != NULL) { +! h_context = Handle(THREAD, JNIHandles::resolve(context)); +! bool authorized = is_authorized(h_context, klass, CHECK_NULL); +! if (!authorized) { +! // Create an unprivileged access control object and call it's run function +! // instead. +! oop noprivs = create_dummy_access_control_context(CHECK_NULL); +! h_context = Handle(THREAD, noprivs); +! } +! } + + // Check that action object understands "Object run()" + Handle object (THREAD, JNIHandles::resolve(action)); +*************** +*** 1124,1135 **** + THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method"); + } + +! // Compute the frame initiating the do privileged operation and setup the privileged stack +! vframeStream vfst(thread); +! vfst.security_get_caller_frame(1); +! + if (!vfst.at_end()) { +! pi.initialize(&vfst, JNIHandles::resolve(context), thread->privileged_stack_top(), CHECK_NULL); + thread->set_privileged_stack_top(&pi); + } + +--- 1195,1204 ---- + THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method"); + } + +! // Stack allocated list of privileged stack elements +! PrivilegedElement pi; + if (!vfst.at_end()) { +! pi.initialize(&vfst, h_context(), thread->privileged_stack_top(), CHECK_NULL); + thread->set_privileged_stack_top(&pi); + } + +*** openjdk/hotspot/src/share/vm/oops/instanceKlass.hpp 2011-11-14 17:07:36.000000000 -0500 +--- openjdk--/hotspot/src/share/vm/oops/instanceKlass.hpp 2013-06-25 15:40:20.707898471 -0400 +*************** +*** 675,680 **** +--- 675,682 ---- + + intptr_t* end_of_itable() const { return start_of_itable() + itable_length(); } + ++ address static_field_addr(int offset); ++ + int offset_of_static_fields() const { + return (intptr_t)start_of_static_fields() - (intptr_t)as_klassOop(); + } +*** openjdk/hotspot/src/share/vm/oops/instanceKlass.cpp 2011-11-14 17:07:36.000000000 -0500 +--- openjdk--/hotspot/src/share/vm/oops/instanceKlass.cpp 2013-06-26 09:20:09.412156641 -0400 +*************** +*** 1992,1997 **** +--- 1992,2002 ---- + } + } + ++ address instanceKlass::static_field_addr(int offset) { ++ return (address)(offset + instanceKlass::offset_of_static_fields() + (intptr_t)java_mirror()); ++ } ++ ++ + const char* instanceKlass::signature_name() const { + const char* src = (const char*) (name()->as_C_string()); + const int src_length = (int)strlen(src);