We consider shape functionals obtained as minima on Sobolev spaces of classical integrals having smooth and convex densities, under mixed Dirichlet-Neumann boundary conditions. We propose a new approach for the computation of the second order shape derivative of such functionals, yielding a general existence and representation theorem. In particular, we consider the p-torsional rigidity functional for p ≥ 2.Keywords: shape functionals, infimum problems, domain derivative, duality. MSC2010: 49Q10, 49K10, 49M29, 49J45.Our main results, which are intimately related to each other, are:-an existence result for J ′′ (Ω, V ) which is a quadratic form in V and can be represented as follows:here C(u, V ) · n is the normal trace of a suitable vector field (see (3.4)) depending on the solution u to J(Ω) and quadratically on the deformation V , whereas q(u, V ) is a nonlocal term which involves a further vector field B(u, V ) and a quadratic form Q(u, ·) depending on the second derivatives of f and g (see Theorem 3.4); we stress that, as detailed in Remark 3.6 below, formula (1.3) fits the general representation result for second order shape derivatives given in [36, Corollary 2.4];-a regularity result of type W 2,2 loc for the solution to J(Ω) (see Proposition 3.2); -a new necessary optimality condition, which involves the distributional divergence of the above mentioned vector field B(u, V ) (see Proposition 3.3).Both the regularity of the solution and the optimality condition on one hand seem to have an independent interest, and on the other hand are strictly related to the second order shape derivative. Namely, if the W 2,2 loc regularity of u stated in Proposition 3.2 extends up to the boundary, the field C(u, V ) turns out to admit a normal trace on the boundary as soon as the latter is piecewise C 1 ; moreover, in order to arrive at the expression (1.3) for J ′′ (Ω, V ), the optimality condition given in Proposition 3.3 is exploited as a crucial tool.The paper is organized as follows. After providing some notation and preliminary background in Section 2, we state in Section 3 our main results (Proposition 3.2, Proposition 3.3 and Theorem 3.4),